@@ -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 !str_contains('*+?', $last)) |
|
| 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 !str_contains('*+?', $last)) |
|
| 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'])) |
@@ -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 | } |
@@ -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 | } |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | " class='picto_err'", |
| 64 | 64 | _T('plugin_info_erreur_xml') |
| 65 | 65 | ) |
| 66 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>'; |
|
| 66 | + . "<div class='erreur'>".join('<br >', $info['erreur']).'</div>'; |
|
| 67 | 67 | $checkable = false; |
| 68 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 68 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])) { |
|
| 69 | 69 | $class_li .= ' error'; |
| 70 | 70 | $erreur = http_img_pack( |
| 71 | 71 | 'plugin-err-32.png', |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | " class='picto_err'", |
| 74 | 74 | _T('plugin_impossible_activer', ['plugin' => $nom]) |
| 75 | 75 | ) |
| 76 | - . "<div class='erreur'>" . implode( |
|
| 76 | + . "<div class='erreur'>".implode( |
|
| 77 | 77 | '<br />', |
| 78 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file] |
|
| 79 | - ) . '</div>'; |
|
| 78 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file] |
|
| 79 | + ).'</div>'; |
|
| 80 | 80 | } else { |
| 81 | 81 | $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ''; |
| 82 | 82 | if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) { |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | // numerotons les occurrences d'un meme prefix |
| 94 | 94 | $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
| 95 | 95 | |
| 96 | - $class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : ''); |
|
| 96 | + $class_li .= ($actif ? ' actif' : '').($expose ? ' on' : ''); |
|
| 97 | 97 | |
| 98 | 98 | return "<li id='$prefix$id' class='$class_li'>" |
| 99 | 99 | . ((!$checkable and !$checked) |
| 100 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 100 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 101 | 101 | . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
| 102 | 102 | . $cfg |
| 103 | 103 | . $erreur |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | // si paquet.xml fournit un squelette, le prendre |
| 117 | 117 | if (isset($infos['config']) and $infos['config']) { |
| 118 | 118 | return recuperer_fond( |
| 119 | - "$dir$nom/" . $infos['config'], |
|
| 119 | + "$dir$nom/".$infos['config'], |
|
| 120 | 120 | [ |
| 121 | - 'script' => 'configurer_' . $prefix, |
|
| 121 | + 'script' => 'configurer_'.$prefix, |
|
| 122 | 122 | 'nom' => $nom |
| 123 | 123 | ] |
| 124 | 124 | ); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | return recuperer_fond( |
| 138 | 138 | 'prive/squelettes/inclure/cfg', |
| 139 | 139 | [ |
| 140 | - 'script' => 'configurer_' . $prefix, |
|
| 140 | + 'script' => 'configurer_'.$prefix, |
|
| 141 | 141 | 'nom' => $nom |
| 142 | 142 | ] |
| 143 | 143 | ); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | . "<input type='checkbox' name='s$name' id='label_$id_input'" |
| 154 | 154 | . ($actif ? " checked='checked'" : '') |
| 155 | 155 | . " class='checkbox' value='O' />" |
| 156 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>' |
|
| 156 | + . "\n<label for='label_$id_input'>"._T('activer_plugin').'</label>' |
|
| 157 | 157 | . '</div>'; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | . "<h3><a href='$url' rel='info'>" |
| 209 | 209 | . $nom |
| 210 | 210 | . '</a></h3>' |
| 211 | - . " <span class='version'>" . $info['version'] . '</span>' |
|
| 211 | + . " <span class='version'>".$info['version'].'</span>' |
|
| 212 | 212 | . " <span class='etat'> - " |
| 213 | 213 | . plugin_etat_en_clair($info['etat']) |
| 214 | 214 | . '</span>' |
| 215 | - . "<div class='short'>" . $slogan . '</div>' |
|
| 215 | + . "<div class='short'>".$slogan.'</div>' |
|
| 216 | 216 | . $i |
| 217 | 217 | . '</div>'; |
| 218 | 218 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $text2 = _T('info_desinstaller_plugin'); |
| 228 | 228 | $file = basename($plug_file); |
| 229 | 229 | |
| 230 | - return "<div class='actions'>[" . |
|
| 230 | + return "<div class='actions'>[". |
|
| 231 | 231 | "<a href='$action' |
| 232 | 232 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 233 | 233 | . $text |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $etat = 'developpement'; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - return _T('plugin_etat_' . $etat); |
|
| 252 | + return _T('plugin_etat_'.$etat); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | function plugin_propre($texte, $module = '', $propre = 'propre') { |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | $module = substr($module, strlen(_DIR_RACINE)); |
| 259 | 259 | } |
| 260 | 260 | if (preg_match('|^\w+_[\w_]+$|', $texte)) { |
| 261 | - $texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]); |
|
| 261 | + $texte = _T(($module ? "$module:" : '').$texte, [], ['force' => false]); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | return $propre($texte); |
@@ -291,9 +291,9 @@ discard block |
||
| 291 | 291 | isset($info['documentation']) |
| 292 | 292 | and $lien = $info['documentation'] |
| 293 | 293 | ) { |
| 294 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 294 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>"._T('en_savoir_plus').'</a></em></p>'; |
|
| 295 | 295 | } |
| 296 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 296 | + $s .= "<dd class='desc'>".$description."</dd>\n"; |
|
| 297 | 297 | |
| 298 | 298 | if (isset($info['auteur'])) { |
| 299 | 299 | if (is_array($info['auteur'])) { |
@@ -303,19 +303,19 @@ discard block |
||
| 303 | 303 | $a = trim($info['auteur']); |
| 304 | 304 | } |
| 305 | 305 | if ($a) { |
| 306 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre( |
|
| 306 | + $s .= "<dt class='auteurs'>"._T('public:par_auteur')."</dt><dd class='auteurs'>".PtoBR(propre( |
|
| 307 | 307 | $a, |
| 308 | 308 | $dir |
| 309 | - )) . "</dd>\n"; |
|
| 309 | + ))."</dd>\n"; |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | if (isset($info['credit'])) { |
| 314 | 314 | if ($a = formater_credits($info['credit'], ', ')) { |
| 315 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre( |
|
| 315 | + $s .= "<dt class='credits'>"._T('plugin_info_credit')."</dt><dd class='credits'>".PtoBR(propre( |
|
| 316 | 316 | $a, |
| 317 | 317 | $dir |
| 318 | - )) . "</dd>\n"; |
|
| 318 | + ))."</dd>\n"; |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
@@ -327,10 +327,10 @@ discard block |
||
| 327 | 327 | $a = trim($info['licence']); |
| 328 | 328 | } |
| 329 | 329 | if ($a) { |
| 330 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre( |
|
| 330 | + $s .= "<dt class='licence'>"._T('intitule_licence')."</dt><dd class='licence'>".PtoBR(propre( |
|
| 331 | 331 | $a, |
| 332 | 332 | $dir |
| 333 | - )) . "</dd>\n"; |
|
| 333 | + ))."</dd>\n"; |
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
@@ -341,25 +341,24 @@ discard block |
||
| 341 | 341 | // |
| 342 | 342 | $infotech = []; |
| 343 | 343 | |
| 344 | - $version = '<dt>' . _T('version') . '</dt><dd>' . $info['version']; |
|
| 344 | + $version = '<dt>'._T('version').'</dt><dd>'.$info['version']; |
|
| 345 | 345 | // Version VCS |
| 346 | - if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 347 | - $version .= ' ' . $vcs; |
|
| 346 | + if ($vcs = version_vcs_courante($dir_plugins.$plug_file)) { |
|
| 347 | + $version .= ' '.$vcs; |
|
| 348 | 348 | } |
| 349 | 349 | $version .= '</dd>'; |
| 350 | 350 | $infotech[] = $version; |
| 351 | - $infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>'; |
|
| 351 | + $infotech[] = '<dt>'._T('repertoire_plugins').'</dt><dd>'.joli_repertoire("$dir_plugins$plug_file").'</dd>'; |
|
| 352 | 352 | // source zip le cas echeant |
| 353 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 353 | + $infotech[] = (lire_fichier($dir_plugins.$plug_file.'/install.log', $log) |
|
| 354 | 354 | and preg_match(',^source:(.*)$,m', $log, $r)) |
| 355 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>' |
|
| 355 | + ? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1]).'</dd>' |
|
| 356 | 356 | : ''; |
| 357 | 357 | |
| 358 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 359 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join( |
|
| 358 | + $infotech[] = !$info['necessite'] ? '' : ('<dt>'._T('plugin_info_necessite').'</dt><dd>'.join( |
|
| 360 | 359 | ' ', |
| 361 | 360 | array_map('array_shift', $info['necessite']) |
| 362 | - ) . '</dd>'); |
|
| 361 | + ).'</dd>'); |
|
| 363 | 362 | |
| 364 | 363 | $s .= "<dl class='tech'>" |
| 365 | 364 | . join('', $infotech) |
@@ -380,8 +379,8 @@ discard block |
||
| 380 | 379 | $texte .= |
| 381 | 380 | (!is_array($_credit)) |
| 382 | 381 | ? PtoBR(propre($_credit)) |
| 383 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 384 | - $_credit['nom'] . |
|
| 382 | + : ($_credit['url'] ? '<a href="'.$_credit['url'].'">' : ''). |
|
| 383 | + $_credit['nom']. |
|
| 385 | 384 | ($_credit['url'] ? '</a>' : ''); |
| 386 | 385 | } |
| 387 | 386 | |
@@ -17,212 +17,212 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/charsets'); |
| 23 | 23 | include_spip('inc/texte'); |
| 24 | 24 | include_spip('inc/plugin'); // pour plugin_est_installe |
| 25 | 25 | |
| 26 | 26 | function plugins_afficher_plugin_dist( |
| 27 | - $url_page, |
|
| 28 | - $plug_file, |
|
| 29 | - $checked, |
|
| 30 | - $actif, |
|
| 31 | - $expose = false, |
|
| 32 | - $class_li = 'item', |
|
| 33 | - $dir_plugins = _DIR_PLUGINS |
|
| 27 | + $url_page, |
|
| 28 | + $plug_file, |
|
| 29 | + $checked, |
|
| 30 | + $actif, |
|
| 31 | + $expose = false, |
|
| 32 | + $class_li = 'item', |
|
| 33 | + $dir_plugins = _DIR_PLUGINS |
|
| 34 | 34 | ) { |
| 35 | 35 | |
| 36 | - static $id_input = 0; |
|
| 37 | - static $versions = []; |
|
| 38 | - |
|
| 39 | - $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 40 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 41 | - $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 42 | - $prefix = $info['prefix']; |
|
| 43 | - $cfg = ''; |
|
| 44 | - $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 45 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 46 | - $erreur = ''; |
|
| 47 | - |
|
| 48 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 49 | - $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 50 | - $erreur = http_img_pack( |
|
| 51 | - 'plugin-dis-32.png', |
|
| 52 | - _T('plugin_info_non_compatible_spip'), |
|
| 53 | - " class='picto_err'", |
|
| 54 | - _T('plugin_info_non_compatible_spip') |
|
| 55 | - ); |
|
| 56 | - $class_li .= ' disabled'; |
|
| 57 | - $checkable = false; |
|
| 58 | - } elseif (isset($info['erreur'])) { |
|
| 59 | - $class_li .= ' error'; |
|
| 60 | - $erreur = http_img_pack( |
|
| 61 | - 'plugin-err-32.png', |
|
| 62 | - _T('plugin_info_erreur_xml'), |
|
| 63 | - " class='picto_err'", |
|
| 64 | - _T('plugin_info_erreur_xml') |
|
| 65 | - ) |
|
| 66 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>'; |
|
| 67 | - $checkable = false; |
|
| 68 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 69 | - $class_li .= ' error'; |
|
| 70 | - $erreur = http_img_pack( |
|
| 71 | - 'plugin-err-32.png', |
|
| 72 | - _T('plugin_impossible_activer', ['plugin' => $nom]), |
|
| 73 | - " class='picto_err'", |
|
| 74 | - _T('plugin_impossible_activer', ['plugin' => $nom]) |
|
| 75 | - ) |
|
| 76 | - . "<div class='erreur'>" . implode( |
|
| 77 | - '<br />', |
|
| 78 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file] |
|
| 79 | - ) . '</div>'; |
|
| 80 | - } else { |
|
| 81 | - $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ''; |
|
| 82 | - if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) { |
|
| 83 | - //$info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 84 | - $erreur = http_img_pack( |
|
| 85 | - 'plugin-dis-32.png', |
|
| 86 | - _T('plugin_info_non_compatible_spip'), |
|
| 87 | - " class='picto_err picto_compat_forcee'", |
|
| 88 | - _L('Version incompatible : compatibilité forcée') |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // numerotons les occurrences d'un meme prefix |
|
| 94 | - $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 95 | - |
|
| 96 | - $class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : ''); |
|
| 97 | - |
|
| 98 | - return "<li id='$prefix$id' class='$class_li'>" |
|
| 99 | - . ((!$checkable and !$checked) |
|
| 100 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 101 | - . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 102 | - . $cfg |
|
| 103 | - . $erreur |
|
| 104 | - . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 105 | - ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 106 | - . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 107 | - . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 108 | - . '</div>' |
|
| 109 | - . '</li>'; |
|
| 36 | + static $id_input = 0; |
|
| 37 | + static $versions = []; |
|
| 38 | + |
|
| 39 | + $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 40 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 41 | + $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 42 | + $prefix = $info['prefix']; |
|
| 43 | + $cfg = ''; |
|
| 44 | + $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 45 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 46 | + $erreur = ''; |
|
| 47 | + |
|
| 48 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 49 | + $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 50 | + $erreur = http_img_pack( |
|
| 51 | + 'plugin-dis-32.png', |
|
| 52 | + _T('plugin_info_non_compatible_spip'), |
|
| 53 | + " class='picto_err'", |
|
| 54 | + _T('plugin_info_non_compatible_spip') |
|
| 55 | + ); |
|
| 56 | + $class_li .= ' disabled'; |
|
| 57 | + $checkable = false; |
|
| 58 | + } elseif (isset($info['erreur'])) { |
|
| 59 | + $class_li .= ' error'; |
|
| 60 | + $erreur = http_img_pack( |
|
| 61 | + 'plugin-err-32.png', |
|
| 62 | + _T('plugin_info_erreur_xml'), |
|
| 63 | + " class='picto_err'", |
|
| 64 | + _T('plugin_info_erreur_xml') |
|
| 65 | + ) |
|
| 66 | + . "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>'; |
|
| 67 | + $checkable = false; |
|
| 68 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 69 | + $class_li .= ' error'; |
|
| 70 | + $erreur = http_img_pack( |
|
| 71 | + 'plugin-err-32.png', |
|
| 72 | + _T('plugin_impossible_activer', ['plugin' => $nom]), |
|
| 73 | + " class='picto_err'", |
|
| 74 | + _T('plugin_impossible_activer', ['plugin' => $nom]) |
|
| 75 | + ) |
|
| 76 | + . "<div class='erreur'>" . implode( |
|
| 77 | + '<br />', |
|
| 78 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file] |
|
| 79 | + ) . '</div>'; |
|
| 80 | + } else { |
|
| 81 | + $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ''; |
|
| 82 | + if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) { |
|
| 83 | + //$info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 84 | + $erreur = http_img_pack( |
|
| 85 | + 'plugin-dis-32.png', |
|
| 86 | + _T('plugin_info_non_compatible_spip'), |
|
| 87 | + " class='picto_err picto_compat_forcee'", |
|
| 88 | + _L('Version incompatible : compatibilité forcée') |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // numerotons les occurrences d'un meme prefix |
|
| 94 | + $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 95 | + |
|
| 96 | + $class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : ''); |
|
| 97 | + |
|
| 98 | + return "<li id='$prefix$id' class='$class_li'>" |
|
| 99 | + . ((!$checkable and !$checked) |
|
| 100 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 101 | + . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 102 | + . $cfg |
|
| 103 | + . $erreur |
|
| 104 | + . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 105 | + ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 106 | + . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 107 | + . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 108 | + . '</div>' |
|
| 109 | + . '</li>'; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | function plugin_bouton_config($nom, $infos, $dir) { |
| 113 | - // la verification se base sur le filesystem |
|
| 114 | - // il faut donc n'utiliser que des minuscules, par convention |
|
| 115 | - $prefix = strtolower($infos['prefix']); |
|
| 116 | - // si paquet.xml fournit un squelette, le prendre |
|
| 117 | - if (isset($infos['config']) and $infos['config']) { |
|
| 118 | - return recuperer_fond( |
|
| 119 | - "$dir$nom/" . $infos['config'], |
|
| 120 | - [ |
|
| 121 | - 'script' => 'configurer_' . $prefix, |
|
| 122 | - 'nom' => $nom |
|
| 123 | - ] |
|
| 124 | - ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // sinon prendre le squelette std sur le nom std |
|
| 128 | - return recuperer_fond( |
|
| 129 | - 'prive/squelettes/inclure/cfg', |
|
| 130 | - [ |
|
| 131 | - 'script' => 'configurer_' . $prefix, |
|
| 132 | - 'nom' => $nom |
|
| 133 | - ] |
|
| 134 | - ); |
|
| 113 | + // la verification se base sur le filesystem |
|
| 114 | + // il faut donc n'utiliser que des minuscules, par convention |
|
| 115 | + $prefix = strtolower($infos['prefix']); |
|
| 116 | + // si paquet.xml fournit un squelette, le prendre |
|
| 117 | + if (isset($infos['config']) and $infos['config']) { |
|
| 118 | + return recuperer_fond( |
|
| 119 | + "$dir$nom/" . $infos['config'], |
|
| 120 | + [ |
|
| 121 | + 'script' => 'configurer_' . $prefix, |
|
| 122 | + 'nom' => $nom |
|
| 123 | + ] |
|
| 124 | + ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // sinon prendre le squelette std sur le nom std |
|
| 128 | + return recuperer_fond( |
|
| 129 | + 'prive/squelettes/inclure/cfg', |
|
| 130 | + [ |
|
| 131 | + 'script' => 'configurer_' . $prefix, |
|
| 132 | + 'nom' => $nom |
|
| 133 | + ] |
|
| 134 | + ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // checkbox pour activer ou desactiver |
| 138 | 138 | // si ce n'est pas une extension |
| 139 | 139 | |
| 140 | 140 | function plugin_checkbox($id_input, $file, $actif) { |
| 141 | - $name = substr(md5($file), 0, 16); |
|
| 142 | - |
|
| 143 | - return "<div class='check'>\n" |
|
| 144 | - . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 145 | - . ($actif ? " checked='checked'" : '') |
|
| 146 | - . " class='checkbox' value='O' />" |
|
| 147 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>' |
|
| 148 | - . '</div>'; |
|
| 141 | + $name = substr(md5($file), 0, 16); |
|
| 142 | + |
|
| 143 | + return "<div class='check'>\n" |
|
| 144 | + . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 145 | + . ($actif ? " checked='checked'" : '') |
|
| 146 | + . " class='checkbox' value='O' />" |
|
| 147 | + . "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>' |
|
| 148 | + . '</div>'; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function plugin_nom($info, $dir_plugins, $plug_file) { |
| 152 | - $prefix = $info['prefix']; |
|
| 153 | - $dir = "$dir_plugins$plug_file"; |
|
| 154 | - // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 155 | - if ($info['dtd'] == 'paquet') { |
|
| 156 | - $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix"); |
|
| 157 | - if (!$nom) { |
|
| 158 | - $nom = typo($info['nom']); |
|
| 159 | - } |
|
| 160 | - } else { |
|
| 161 | - $nom = typo(attribut_html($info['nom'])); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return trim($nom); |
|
| 152 | + $prefix = $info['prefix']; |
|
| 153 | + $dir = "$dir_plugins$plug_file"; |
|
| 154 | + // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 155 | + if ($info['dtd'] == 'paquet') { |
|
| 156 | + $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix"); |
|
| 157 | + if (!$nom) { |
|
| 158 | + $nom = typo($info['nom']); |
|
| 159 | + } |
|
| 160 | + } else { |
|
| 161 | + $nom = typo(attribut_html($info['nom'])); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return trim($nom); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Cartouche Resume |
| 168 | 168 | function plugin_resume($info, $dir_plugins, $plug_file, $url_page) { |
| 169 | - $prefix = $info['prefix']; |
|
| 170 | - $dir = "$dir_plugins$plug_file"; |
|
| 171 | - $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 172 | - // une seule ligne dans le slogan : couper si besoin |
|
| 173 | - if (($p = strpos($slogan, '<br />')) !== false) { |
|
| 174 | - $slogan = substr($slogan, 0, $p); |
|
| 175 | - } |
|
| 176 | - // couper par securite |
|
| 177 | - $slogan = couper($slogan, 80); |
|
| 178 | - |
|
| 179 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 180 | - |
|
| 181 | - $url = parametre_url($url_page, 'plugin', substr($dir, strlen(_DIR_RACINE))); |
|
| 182 | - |
|
| 183 | - $icon_class = 'icon'; |
|
| 184 | - $img = ''; |
|
| 185 | - if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 186 | - $img = http_img_pack("$dir/$i", '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]); |
|
| 187 | - if (!extraire_attribut($img, 'src')) { |
|
| 188 | - $img = ''; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - if (!$img) { |
|
| 192 | - $img = http_img_pack('plugin-xx.svg', '', " width='32' height='32'"); |
|
| 193 | - $icon_class .= ' no-logo'; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>"; |
|
| 197 | - |
|
| 198 | - return "<div class='resume'>" |
|
| 199 | - . "<h3><a href='$url' rel='info'>" |
|
| 200 | - . $nom |
|
| 201 | - . '</a></h3>' |
|
| 202 | - . " <span class='version'>" . $info['version'] . '</span>' |
|
| 203 | - . " <span class='etat'> - " |
|
| 204 | - . plugin_etat_en_clair($info['etat']) |
|
| 205 | - . '</span>' |
|
| 206 | - . "<div class='short'>" . $slogan . '</div>' |
|
| 207 | - . $i |
|
| 208 | - . '</div>'; |
|
| 169 | + $prefix = $info['prefix']; |
|
| 170 | + $dir = "$dir_plugins$plug_file"; |
|
| 171 | + $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 172 | + // une seule ligne dans le slogan : couper si besoin |
|
| 173 | + if (($p = strpos($slogan, '<br />')) !== false) { |
|
| 174 | + $slogan = substr($slogan, 0, $p); |
|
| 175 | + } |
|
| 176 | + // couper par securite |
|
| 177 | + $slogan = couper($slogan, 80); |
|
| 178 | + |
|
| 179 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 180 | + |
|
| 181 | + $url = parametre_url($url_page, 'plugin', substr($dir, strlen(_DIR_RACINE))); |
|
| 182 | + |
|
| 183 | + $icon_class = 'icon'; |
|
| 184 | + $img = ''; |
|
| 185 | + if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 186 | + $img = http_img_pack("$dir/$i", '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]); |
|
| 187 | + if (!extraire_attribut($img, 'src')) { |
|
| 188 | + $img = ''; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + if (!$img) { |
|
| 192 | + $img = http_img_pack('plugin-xx.svg', '', " width='32' height='32'"); |
|
| 193 | + $icon_class .= ' no-logo'; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>"; |
|
| 197 | + |
|
| 198 | + return "<div class='resume'>" |
|
| 199 | + . "<h3><a href='$url' rel='info'>" |
|
| 200 | + . $nom |
|
| 201 | + . '</a></h3>' |
|
| 202 | + . " <span class='version'>" . $info['version'] . '</span>' |
|
| 203 | + . " <span class='etat'> - " |
|
| 204 | + . plugin_etat_en_clair($info['etat']) |
|
| 205 | + . '</span>' |
|
| 206 | + . "<div class='short'>" . $slogan . '</div>' |
|
| 207 | + . $i |
|
| 208 | + . '</div>'; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 212 | - if (!$dir_plugins) { |
|
| 213 | - $dir_plugins = _DIR_PLUGINS; |
|
| 214 | - } |
|
| 212 | + if (!$dir_plugins) { |
|
| 213 | + $dir_plugins = _DIR_PLUGINS; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 217 | - $text = _T('bouton_desinstaller'); |
|
| 218 | - $text2 = _T('info_desinstaller_plugin'); |
|
| 219 | - $file = basename($plug_file); |
|
| 216 | + $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 217 | + $text = _T('bouton_desinstaller'); |
|
| 218 | + $text2 = _T('info_desinstaller_plugin'); |
|
| 219 | + $file = basename($plug_file); |
|
| 220 | 220 | |
| 221 | - return "<div class='actions'>[" . |
|
| 222 | - "<a href='$action' |
|
| 221 | + return "<div class='actions'>[" . |
|
| 222 | + "<a href='$action' |
|
| 223 | 223 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 224 | - . $text |
|
| 225 | - . '</a>]</div>'; |
|
| 224 | + . $text |
|
| 225 | + . '</a>]</div>'; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -236,145 +236,145 @@ discard block |
||
| 236 | 236 | * Traduction de l'état dans la langue en cours |
| 237 | 237 | **/ |
| 238 | 238 | function plugin_etat_en_clair($etat) { |
| 239 | - if (!in_array($etat, ['stable', 'test', 'experimental'])) { |
|
| 240 | - $etat = 'developpement'; |
|
| 241 | - } |
|
| 239 | + if (!in_array($etat, ['stable', 'test', 'experimental'])) { |
|
| 240 | + $etat = 'developpement'; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - return _T('plugin_etat_' . $etat); |
|
| 243 | + return _T('plugin_etat_' . $etat); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | function plugin_propre($texte, $module = '', $propre = 'propre') { |
| 247 | - // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 248 | - if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 249 | - $module = substr($module, strlen(_DIR_RACINE)); |
|
| 250 | - } |
|
| 251 | - if (preg_match('|^\w+_[\w_]+$|', $texte)) { |
|
| 252 | - $texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - return $propre($texte); |
|
| 247 | + // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 248 | + if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 249 | + $module = substr($module, strlen(_DIR_RACINE)); |
|
| 250 | + } |
|
| 251 | + if (preg_match('|^\w+_[\w_]+$|', $texte)) { |
|
| 252 | + $texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + return $propre($texte); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | function plugin_typo($texte, $module = '') { |
| 259 | - return plugin_propre($texte, $module, 'typo'); |
|
| 259 | + return plugin_propre($texte, $module, 'typo'); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
| 263 | 263 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) { |
| 264 | - $log = null; |
|
| 265 | - if (!$dir_plugins) { |
|
| 266 | - $dir_plugins = _DIR_PLUGINS; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $prefix = $info['prefix']; |
|
| 270 | - $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 271 | - |
|
| 272 | - $s = ''; |
|
| 273 | - // TODO: le traiter_multi ici n'est pas beau |
|
| 274 | - // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 275 | - // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 276 | - $description = ''; |
|
| 277 | - if (isset($info['description'])) { |
|
| 278 | - $description = plugin_propre($info['description'], $dir); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - if ( |
|
| 282 | - isset($info['documentation']) |
|
| 283 | - and $lien = $info['documentation'] |
|
| 284 | - ) { |
|
| 285 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 286 | - } |
|
| 287 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 288 | - |
|
| 289 | - if (isset($info['auteur'])) { |
|
| 290 | - if (is_array($info['auteur'])) { |
|
| 291 | - $a = formater_credits($info['auteur'], ', '); |
|
| 292 | - } // pour compat mais ne doit plus arriver |
|
| 293 | - else { |
|
| 294 | - $a = trim($info['auteur']); |
|
| 295 | - } |
|
| 296 | - if ($a) { |
|
| 297 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre( |
|
| 298 | - $a, |
|
| 299 | - $dir |
|
| 300 | - )) . "</dd>\n"; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if (isset($info['credit'])) { |
|
| 305 | - if ($a = formater_credits($info['credit'], ', ')) { |
|
| 306 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre( |
|
| 307 | - $a, |
|
| 308 | - $dir |
|
| 309 | - )) . "</dd>\n"; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - if (isset($info['licence'])) { |
|
| 314 | - if (is_array($info['licence'])) { |
|
| 315 | - $a = formater_credits($info['licence'], ', '); |
|
| 316 | - } // pour compat mais ne doit plus arriver |
|
| 317 | - else { |
|
| 318 | - $a = trim($info['licence']); |
|
| 319 | - } |
|
| 320 | - if ($a) { |
|
| 321 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre( |
|
| 322 | - $a, |
|
| 323 | - $dir |
|
| 324 | - )) . "</dd>\n"; |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - $s = "<dl class='description'>$s</dl>"; |
|
| 329 | - |
|
| 330 | - // |
|
| 331 | - // Ajouter les infos techniques |
|
| 332 | - // |
|
| 333 | - $infotech = []; |
|
| 334 | - |
|
| 335 | - $version = '<dt>' . _T('version') . '</dt><dd>' . $info['version']; |
|
| 336 | - // Version VCS |
|
| 337 | - if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 338 | - $version .= ' ' . $vcs; |
|
| 339 | - } |
|
| 340 | - $version .= '</dd>'; |
|
| 341 | - $infotech[] = $version; |
|
| 342 | - $infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>'; |
|
| 343 | - // source zip le cas echeant |
|
| 344 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 345 | - and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 346 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>' |
|
| 347 | - : ''; |
|
| 348 | - |
|
| 349 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 350 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join( |
|
| 351 | - ' ', |
|
| 352 | - array_map('array_shift', $info['necessite']) |
|
| 353 | - ) . '</dd>'); |
|
| 354 | - |
|
| 355 | - $s .= "<dl class='tech'>" |
|
| 356 | - . join('', $infotech) |
|
| 357 | - . '</dl>'; |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - return $s; |
|
| 264 | + $log = null; |
|
| 265 | + if (!$dir_plugins) { |
|
| 266 | + $dir_plugins = _DIR_PLUGINS; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $prefix = $info['prefix']; |
|
| 270 | + $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 271 | + |
|
| 272 | + $s = ''; |
|
| 273 | + // TODO: le traiter_multi ici n'est pas beau |
|
| 274 | + // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 275 | + // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 276 | + $description = ''; |
|
| 277 | + if (isset($info['description'])) { |
|
| 278 | + $description = plugin_propre($info['description'], $dir); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + if ( |
|
| 282 | + isset($info['documentation']) |
|
| 283 | + and $lien = $info['documentation'] |
|
| 284 | + ) { |
|
| 285 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 286 | + } |
|
| 287 | + $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 288 | + |
|
| 289 | + if (isset($info['auteur'])) { |
|
| 290 | + if (is_array($info['auteur'])) { |
|
| 291 | + $a = formater_credits($info['auteur'], ', '); |
|
| 292 | + } // pour compat mais ne doit plus arriver |
|
| 293 | + else { |
|
| 294 | + $a = trim($info['auteur']); |
|
| 295 | + } |
|
| 296 | + if ($a) { |
|
| 297 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre( |
|
| 298 | + $a, |
|
| 299 | + $dir |
|
| 300 | + )) . "</dd>\n"; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if (isset($info['credit'])) { |
|
| 305 | + if ($a = formater_credits($info['credit'], ', ')) { |
|
| 306 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre( |
|
| 307 | + $a, |
|
| 308 | + $dir |
|
| 309 | + )) . "</dd>\n"; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + if (isset($info['licence'])) { |
|
| 314 | + if (is_array($info['licence'])) { |
|
| 315 | + $a = formater_credits($info['licence'], ', '); |
|
| 316 | + } // pour compat mais ne doit plus arriver |
|
| 317 | + else { |
|
| 318 | + $a = trim($info['licence']); |
|
| 319 | + } |
|
| 320 | + if ($a) { |
|
| 321 | + $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre( |
|
| 322 | + $a, |
|
| 323 | + $dir |
|
| 324 | + )) . "</dd>\n"; |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + $s = "<dl class='description'>$s</dl>"; |
|
| 329 | + |
|
| 330 | + // |
|
| 331 | + // Ajouter les infos techniques |
|
| 332 | + // |
|
| 333 | + $infotech = []; |
|
| 334 | + |
|
| 335 | + $version = '<dt>' . _T('version') . '</dt><dd>' . $info['version']; |
|
| 336 | + // Version VCS |
|
| 337 | + if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 338 | + $version .= ' ' . $vcs; |
|
| 339 | + } |
|
| 340 | + $version .= '</dd>'; |
|
| 341 | + $infotech[] = $version; |
|
| 342 | + $infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>'; |
|
| 343 | + // source zip le cas echeant |
|
| 344 | + $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 345 | + and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 346 | + ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>' |
|
| 347 | + : ''; |
|
| 348 | + |
|
| 349 | + $infotech[] = !$info['necessite'] ? '' : |
|
| 350 | + ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join( |
|
| 351 | + ' ', |
|
| 352 | + array_map('array_shift', $info['necessite']) |
|
| 353 | + ) . '</dd>'); |
|
| 354 | + |
|
| 355 | + $s .= "<dl class='tech'>" |
|
| 356 | + . join('', $infotech) |
|
| 357 | + . '</dl>'; |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + return $s; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | function formater_credits($infos, $sep = ', ') { |
| 364 | - $texte = ''; |
|
| 365 | - |
|
| 366 | - foreach ($infos as $_credit) { |
|
| 367 | - if ($texte) { |
|
| 368 | - $texte .= $sep; |
|
| 369 | - } |
|
| 370 | - // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 371 | - $texte .= |
|
| 372 | - (!is_array($_credit)) |
|
| 373 | - ? PtoBR(propre($_credit)) |
|
| 374 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 375 | - $_credit['nom'] . |
|
| 376 | - ($_credit['url'] ? '</a>' : ''); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - return $texte; |
|
| 364 | + $texte = ''; |
|
| 365 | + |
|
| 366 | + foreach ($infos as $_credit) { |
|
| 367 | + if ($texte) { |
|
| 368 | + $texte .= $sep; |
|
| 369 | + } |
|
| 370 | + // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 371 | + $texte .= |
|
| 372 | + (!is_array($_credit)) |
|
| 373 | + ? PtoBR(propre($_credit)) |
|
| 374 | + : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 375 | + $_credit['nom'] . |
|
| 376 | + ($_credit['url'] ? '</a>' : ''); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + return $texte; |
|
| 380 | 380 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Presentation |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/presentation_mini'); |
@@ -31,141 +31,141 @@ discard block |
||
| 31 | 31 | include_spip('inc/filtres_alertes'); |
| 32 | 32 | |
| 33 | 33 | function debut_cadre($style, $icone = '', $fonction = '', $titre = '', $id = '', $class = '', $padding = true) { |
| 34 | - $fond = null; |
|
| 35 | - $style_mapping = [ |
|
| 36 | - 'r' => 'simple', |
|
| 37 | - 'e' => 'raccourcis', |
|
| 38 | - 'couleur' => 'basic highlight', |
|
| 39 | - 'couleur-foncee' => 'basic highlight', |
|
| 40 | - 'trait-couleur' => 'important', |
|
| 41 | - 'alerte' => 'notice', |
|
| 42 | - 'info' => 'info', |
|
| 43 | - 'sous_rub' => 'simple sous-rub' |
|
| 44 | - ]; |
|
| 45 | - $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
|
| 46 | - $c = $style_mapping[$style] ?? 'simple'; |
|
| 47 | - $class = $c . ($class ? " $class" : ''); |
|
| 48 | - if (!$padding) { |
|
| 49 | - $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - //($id?"id='$id' ":"") |
|
| 53 | - if (strlen($icone) > 1) { |
|
| 54 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 55 | - [$fond, $fonction] = $icone_renommer($icone, $fonction); |
|
| 56 | - } |
|
| 57 | - $size = 24; |
|
| 58 | - if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) { |
|
| 59 | - $size = $match[1]; |
|
| 60 | - } |
|
| 61 | - if ($fonction) { |
|
| 62 | - // 2 images pour composer l'icone : le fond (article) en background, |
|
| 63 | - // la fonction (new) en image |
|
| 64 | - $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 65 | - http_style_background($fond, 'no-repeat center center', $size)); |
|
| 66 | - } else { |
|
| 67 | - $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
|
| 68 | - } |
|
| 69 | - $titre = $icone . $titre; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return boite_ouvrir($titre, $class, $style_titre_mapping[$style] ?? '', $id); |
|
| 34 | + $fond = null; |
|
| 35 | + $style_mapping = [ |
|
| 36 | + 'r' => 'simple', |
|
| 37 | + 'e' => 'raccourcis', |
|
| 38 | + 'couleur' => 'basic highlight', |
|
| 39 | + 'couleur-foncee' => 'basic highlight', |
|
| 40 | + 'trait-couleur' => 'important', |
|
| 41 | + 'alerte' => 'notice', |
|
| 42 | + 'info' => 'info', |
|
| 43 | + 'sous_rub' => 'simple sous-rub' |
|
| 44 | + ]; |
|
| 45 | + $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
|
| 46 | + $c = $style_mapping[$style] ?? 'simple'; |
|
| 47 | + $class = $c . ($class ? " $class" : ''); |
|
| 48 | + if (!$padding) { |
|
| 49 | + $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + //($id?"id='$id' ":"") |
|
| 53 | + if (strlen($icone) > 1) { |
|
| 54 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 55 | + [$fond, $fonction] = $icone_renommer($icone, $fonction); |
|
| 56 | + } |
|
| 57 | + $size = 24; |
|
| 58 | + if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) { |
|
| 59 | + $size = $match[1]; |
|
| 60 | + } |
|
| 61 | + if ($fonction) { |
|
| 62 | + // 2 images pour composer l'icone : le fond (article) en background, |
|
| 63 | + // la fonction (new) en image |
|
| 64 | + $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 65 | + http_style_background($fond, 'no-repeat center center', $size)); |
|
| 66 | + } else { |
|
| 67 | + $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
|
| 68 | + } |
|
| 69 | + $titre = $icone . $titre; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return boite_ouvrir($titre, $class, $style_titre_mapping[$style] ?? '', $id); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | function fin_cadre() { |
| 76 | - return boite_fermer(); |
|
| 76 | + return boite_fermer(); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | function debut_cadre_relief( |
| 81 | - $icone = '', |
|
| 82 | - $dummy = '', |
|
| 83 | - $fonction = '', |
|
| 84 | - $titre = '', |
|
| 85 | - $id = '', |
|
| 86 | - $class = '' |
|
| 81 | + $icone = '', |
|
| 82 | + $dummy = '', |
|
| 83 | + $fonction = '', |
|
| 84 | + $titre = '', |
|
| 85 | + $id = '', |
|
| 86 | + $class = '' |
|
| 87 | 87 | ) { |
| 88 | - return debut_cadre('r', $icone, $fonction, $titre, $id, $class); |
|
| 88 | + return debut_cadre('r', $icone, $fonction, $titre, $id, $class); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function fin_cadre_relief() { |
| 92 | - return fin_cadre(); |
|
| 92 | + return fin_cadre(); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | function debut_cadre_enfonce( |
| 96 | - $icone = '', |
|
| 97 | - $dummy = '', |
|
| 98 | - $fonction = '', |
|
| 99 | - $titre = '', |
|
| 100 | - $id = '', |
|
| 101 | - $class = '' |
|
| 96 | + $icone = '', |
|
| 97 | + $dummy = '', |
|
| 98 | + $fonction = '', |
|
| 99 | + $titre = '', |
|
| 100 | + $id = '', |
|
| 101 | + $class = '' |
|
| 102 | 102 | ) { |
| 103 | - return debut_cadre('e', $icone, $fonction, $titre, $id, $class); |
|
| 103 | + return debut_cadre('e', $icone, $fonction, $titre, $id, $class); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function fin_cadre_enfonce() { |
| 107 | - return fin_cadre(); |
|
| 107 | + return fin_cadre(); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | function debut_cadre_sous_rub( |
| 111 | - $icone = '', |
|
| 112 | - $dummy = '', |
|
| 113 | - $fonction = '', |
|
| 114 | - $titre = '', |
|
| 115 | - $id = '', |
|
| 116 | - $class = '' |
|
| 111 | + $icone = '', |
|
| 112 | + $dummy = '', |
|
| 113 | + $fonction = '', |
|
| 114 | + $titre = '', |
|
| 115 | + $id = '', |
|
| 116 | + $class = '' |
|
| 117 | 117 | ) { |
| 118 | - return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); |
|
| 118 | + return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | function fin_cadre_sous_rub() { |
| 122 | - return fin_cadre(); |
|
| 122 | + return fin_cadre(); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | function debut_cadre_couleur( |
| 126 | - $icone = '', |
|
| 127 | - $dummy = '', |
|
| 128 | - $fonction = '', |
|
| 129 | - $titre = '', |
|
| 130 | - $id = '', |
|
| 131 | - $class = '' |
|
| 126 | + $icone = '', |
|
| 127 | + $dummy = '', |
|
| 128 | + $fonction = '', |
|
| 129 | + $titre = '', |
|
| 130 | + $id = '', |
|
| 131 | + $class = '' |
|
| 132 | 132 | ) { |
| 133 | - return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); |
|
| 133 | + return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | function fin_cadre_couleur() { |
| 137 | - return fin_cadre(); |
|
| 137 | + return fin_cadre(); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | function debut_cadre_trait_couleur( |
| 141 | - $icone = '', |
|
| 142 | - $dummy = '', |
|
| 143 | - $fonction = '', |
|
| 144 | - $titre = '', |
|
| 145 | - $id = '', |
|
| 146 | - $class = '' |
|
| 141 | + $icone = '', |
|
| 142 | + $dummy = '', |
|
| 143 | + $fonction = '', |
|
| 144 | + $titre = '', |
|
| 145 | + $id = '', |
|
| 146 | + $class = '' |
|
| 147 | 147 | ) { |
| 148 | - return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); |
|
| 148 | + return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function fin_cadre_trait_couleur() { |
| 152 | - return fin_cadre(); |
|
| 152 | + return fin_cadre(); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | function debut_boite_alerte() { |
| 156 | - return debut_cadre('alerte', '', '', '', '', ''); |
|
| 156 | + return debut_cadre('alerte', '', '', '', '', ''); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | function fin_boite_alerte() { |
| 160 | - return fin_cadre(); |
|
| 160 | + return fin_cadre(); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function debut_boite_info() { |
| 164 | - return debut_cadre('info', '', '', '', '', ''); |
|
| 164 | + return debut_cadre('info', '', '', '', '', ''); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | function fin_boite_info() { |
| 168 | - return fin_cadre(); |
|
| 168 | + return fin_cadre(); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -176,17 +176,17 @@ discard block |
||
| 176 | 176 | * @return string Code PHP. |
| 177 | 177 | **/ |
| 178 | 178 | function gros_titre( |
| 179 | - $titre, |
|
| 180 | - $ze_logo = '' |
|
| 179 | + $titre, |
|
| 180 | + $ze_logo = '' |
|
| 181 | 181 | ) { |
| 182 | - return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 182 | + return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // La boite des raccourcis |
| 186 | 186 | // Se place a droite si l'ecran est en mode panoramique. |
| 187 | 187 | function bloc_des_raccourcis($bloc) { |
| 188 | - return creer_colonne_droite() |
|
| 189 | - . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 188 | + return creer_colonne_droite() |
|
| 189 | + . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // |
@@ -196,18 +196,18 @@ discard block |
||
| 196 | 196 | // Fonctions onglets |
| 197 | 197 | // @param string $sous_classe prend la valeur second pour definir les onglet de deuxieme niveau |
| 198 | 198 | function debut_onglet($classe = 'barre_onglet') { |
| 199 | - return "<div class = '$classe clearfix'><ul>\n"; |
|
| 199 | + return "<div class = '$classe clearfix'><ul>\n"; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function fin_onglet() { |
| 203 | - return "</ul></div>\n"; |
|
| 203 | + return "</ul></div>\n"; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | function onglet($texte, $lien, $onglet_ref, $onglet, $icone = '') { |
| 207 | - return '<li>' |
|
| 208 | - . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
|
| 209 | - . lien_ou_expose($lien, $texte, $onglet == $onglet_ref) |
|
| 210 | - . '</li>'; |
|
| 207 | + return '<li>' |
|
| 208 | + . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
|
| 209 | + . lien_ou_expose($lien, $texte, $onglet == $onglet_ref) |
|
| 210 | + . '</li>'; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -239,14 +239,14 @@ discard block |
||
| 239 | 239 | * Code HTML du lien |
| 240 | 240 | **/ |
| 241 | 241 | function icone_verticale($texte, $lien, $fond, $fonction = '', $align = '', $javascript = '') { |
| 242 | - // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 243 | - // (il faudrait fusionner avec le cas $javascript) |
|
| 244 | - if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 245 | - [$x, $lien, $atts, $texte] = $r; |
|
| 246 | - $javascript .= $atts; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript); |
|
| 242 | + // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 243 | + // (il faudrait fusionner avec le cas $javascript) |
|
| 244 | + if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 245 | + [$x, $lien, $atts, $texte] = $r; |
|
| 246 | + $javascript .= $atts; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -271,15 +271,15 @@ discard block |
||
| 271 | 271 | * Code HTML du lien |
| 272 | 272 | **/ |
| 273 | 273 | function icone_horizontale($texte, $lien, $fond, $fonction = '', $dummy = '', $javascript = '') { |
| 274 | - $retour = ''; |
|
| 275 | - // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 276 | - // (il faudrait fusionner avec le cas $javascript) |
|
| 277 | - if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 278 | - [$x, $lien, $atts, $texte] = $r; |
|
| 279 | - $javascript .= $atts; |
|
| 280 | - } |
|
| 274 | + $retour = ''; |
|
| 275 | + // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 276 | + // (il faudrait fusionner avec le cas $javascript) |
|
| 277 | + if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 278 | + [$x, $lien, $atts, $texte] = $r; |
|
| 279 | + $javascript .= $atts; |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript); |
|
| 282 | + $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript); |
|
| 283 | 283 | |
| 284 | - return $retour; |
|
| 284 | + return $retour; |
|
| 285 | 285 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | ]; |
| 45 | 45 | $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
| 46 | 46 | $c = $style_mapping[$style] ?? 'simple'; |
| 47 | - $class = $c . ($class ? " $class" : ''); |
|
| 47 | + $class = $c.($class ? " $class" : ''); |
|
| 48 | 48 | if (!$padding) { |
| 49 | - $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 49 | + $class .= ($class ? ' ' : '').'no-padding'; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | //($id?"id='$id' ":"") |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | if ($fonction) { |
| 62 | 62 | // 2 images pour composer l'icone : le fond (article) en background, |
| 63 | 63 | // la fonction (new) en image |
| 64 | - $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 64 | + $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n". |
|
| 65 | 65 | http_style_background($fond, 'no-repeat center center', $size)); |
| 66 | 66 | } else { |
| 67 | 67 | $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
| 68 | 68 | } |
| 69 | - $titre = $icone . $titre; |
|
| 69 | + $titre = $icone.$titre; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | return boite_ouvrir($titre, $class, $style_titre_mapping[$style] ?? '', $id); |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | $titre, |
| 180 | 180 | $ze_logo = '' |
| 181 | 181 | ) { |
| 182 | - return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 182 | + return "<h1 class = 'grostitre'>".$ze_logo.' '.typo($titre)."</h1>\n"; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // La boite des raccourcis |
| 186 | 186 | // Se place a droite si l'ecran est en mode panoramique. |
| 187 | 187 | function bloc_des_raccourcis($bloc) { |
| 188 | 188 | return creer_colonne_droite() |
| 189 | - . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 189 | + . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis').$bloc.boite_fermer(); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -26,70 +26,70 @@ discard block |
||
| 26 | 26 | * @return string Code HTML du cadre dépliable |
| 27 | 27 | **/ |
| 28 | 28 | function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') { |
| 29 | - $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | - |
|
| 31 | - return |
|
| 32 | - debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | - . debut_block_depliable($deplie, $ids) |
|
| 34 | - . "<div class='cadre_padding'>\n" |
|
| 35 | - . $contenu |
|
| 36 | - . "</div>\n" |
|
| 37 | - . fin_block() |
|
| 38 | - . fin_cadre(); |
|
| 29 | + $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | + |
|
| 31 | + return |
|
| 32 | + debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | + . debut_block_depliable($deplie, $ids) |
|
| 34 | + . "<div class='cadre_padding'>\n" |
|
| 35 | + . $contenu |
|
| 36 | + . "</div>\n" |
|
| 37 | + . fin_block() |
|
| 38 | + . fin_cadre(); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) { |
| 42 | - return "\n" |
|
| 43 | - . bouton_block_depliable($invite, $visible, $nom) |
|
| 44 | - . debut_block_depliable($visible, $nom) |
|
| 45 | - . $masque |
|
| 46 | - . fin_block(); |
|
| 42 | + return "\n" |
|
| 43 | + . bouton_block_depliable($invite, $visible, $nom) |
|
| 44 | + . debut_block_depliable($visible, $nom) |
|
| 45 | + . $masque |
|
| 46 | + . fin_block(); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | function debut_block_depliable($deplie, $id = '') { |
| 50 | - $class = ' blocdeplie'; |
|
| 51 | - // si on n'accepte pas js, ne pas fermer |
|
| 52 | - if (!$deplie) { |
|
| 53 | - $class = ' blocreplie'; |
|
| 54 | - } |
|
| 50 | + $class = ' blocdeplie'; |
|
| 51 | + // si on n'accepte pas js, ne pas fermer |
|
| 52 | + if (!$deplie) { |
|
| 53 | + $class = ' blocreplie'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 56 | + return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function fin_block() { |
| 60 | - return "<div class='nettoyeur'></div>\n</div>"; |
|
| 60 | + return "<div class='nettoyeur'></div>\n</div>"; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // $texte : texte du bouton |
| 64 | 64 | // $deplie : true (deplie) ou false (plie) ou -1 (inactif) ou 'incertain' pour que le bouton s'auto init au chargement de la page |
| 65 | 65 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 66 | 66 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 67 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 68 | - |
|
| 69 | - $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 70 | - if (strlen($ids)) { |
|
| 71 | - $cible = explode(',', $ids); |
|
| 72 | - $cible = '#' . implode(',#', $cible); |
|
| 73 | - } else { |
|
| 74 | - $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 78 | - |
|
| 79 | - return "<$b " |
|
| 80 | - . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 81 | - . "class='titrem$class'" |
|
| 82 | - . (($deplie === -1) |
|
| 83 | - ? '' |
|
| 84 | - : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 85 | - ) |
|
| 86 | - . '>' |
|
| 87 | - // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 88 | - . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 89 | - . "$texte</$b>" |
|
| 90 | - . http_script(($deplie === 'incertain') |
|
| 91 | - ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 92 | - : ''); |
|
| 67 | + $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 68 | + |
|
| 69 | + $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 70 | + if (strlen($ids)) { |
|
| 71 | + $cible = explode(',', $ids); |
|
| 72 | + $cible = '#' . implode(',#', $cible); |
|
| 73 | + } else { |
|
| 74 | + $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 78 | + |
|
| 79 | + return "<$b " |
|
| 80 | + . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 81 | + . "class='titrem$class'" |
|
| 82 | + . (($deplie === -1) |
|
| 83 | + ? '' |
|
| 84 | + : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 85 | + ) |
|
| 86 | + . '>' |
|
| 87 | + // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 88 | + . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 89 | + . "$texte</$b>" |
|
| 90 | + . http_script(($deplie === 'incertain') |
|
| 91 | + ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 92 | + : ''); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // |
@@ -97,66 +97,66 @@ discard block |
||
| 97 | 97 | // |
| 98 | 98 | function verif_butineur() { |
| 99 | 99 | |
| 100 | - preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 101 | - $GLOBALS['browser_name'] = $match[1]; |
|
| 102 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 103 | - $GLOBALS['browser_description'] = $match[3]; |
|
| 104 | - $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 105 | - $GLOBALS['browser_barre'] = ''; |
|
| 106 | - |
|
| 107 | - if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 108 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 109 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 110 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 111 | - } else { |
|
| 112 | - if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 113 | - preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 114 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 115 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 116 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 117 | - } else { |
|
| 118 | - if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 119 | - preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 120 | - $GLOBALS['browser_name'] = 'MSIE'; |
|
| 121 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 122 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 123 | - } else { |
|
| 124 | - if ( |
|
| 125 | - preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 126 | - preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 127 | - ) { |
|
| 128 | - $GLOBALS['browser_name'] = 'Safari'; |
|
| 129 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 130 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 131 | - } else { |
|
| 132 | - if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 133 | - // Numero de version pour Mozilla "authentique" |
|
| 134 | - if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 135 | - $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 136 | - } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 137 | - else { |
|
| 138 | - if ( |
|
| 139 | - strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 140 | - $GLOBALS['browser_description'], |
|
| 141 | - 'KHTML' |
|
| 142 | - ) |
|
| 143 | - ) { |
|
| 144 | - $GLOBALS['browser_rev'] = 1.4; |
|
| 145 | - } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 146 | - else { |
|
| 147 | - $GLOBALS['browser_rev'] = 1.0; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (!$GLOBALS['browser_name']) { |
|
| 158 | - $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 159 | - } |
|
| 100 | + preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 101 | + $GLOBALS['browser_name'] = $match[1]; |
|
| 102 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 103 | + $GLOBALS['browser_description'] = $match[3]; |
|
| 104 | + $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 105 | + $GLOBALS['browser_barre'] = ''; |
|
| 106 | + |
|
| 107 | + if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 108 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 109 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 110 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 111 | + } else { |
|
| 112 | + if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 113 | + preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 114 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 115 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 116 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 117 | + } else { |
|
| 118 | + if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 119 | + preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 120 | + $GLOBALS['browser_name'] = 'MSIE'; |
|
| 121 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 122 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 123 | + } else { |
|
| 124 | + if ( |
|
| 125 | + preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 126 | + preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 127 | + ) { |
|
| 128 | + $GLOBALS['browser_name'] = 'Safari'; |
|
| 129 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 130 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 131 | + } else { |
|
| 132 | + if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 133 | + // Numero de version pour Mozilla "authentique" |
|
| 134 | + if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 135 | + $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 136 | + } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 137 | + else { |
|
| 138 | + if ( |
|
| 139 | + strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 140 | + $GLOBALS['browser_description'], |
|
| 141 | + 'KHTML' |
|
| 142 | + ) |
|
| 143 | + ) { |
|
| 144 | + $GLOBALS['browser_rev'] = 1.4; |
|
| 145 | + } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 146 | + else { |
|
| 147 | + $GLOBALS['browser_rev'] = 1.0; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (!$GLOBALS['browser_name']) { |
|
| 158 | + $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | verif_butineur(); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $class = ' blocreplie'; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 56 | + return '<div '.($id ? "id='$id' " : '')."class='bloc_depliable$class'>"; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function fin_block() { |
@@ -64,12 +64,12 @@ discard block |
||
| 64 | 64 | // $deplie : true (deplie) ou false (plie) ou -1 (inactif) ou 'incertain' pour que le bouton s'auto init au chargement de la page |
| 65 | 65 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 66 | 66 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 67 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 67 | + $bouton_id = 'b'.substr(md5($texte.microtime()), 0, 8); |
|
| 68 | 68 | |
| 69 | 69 | $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
| 70 | 70 | if (strlen($ids)) { |
| 71 | 71 | $cible = explode(',', $ids); |
| 72 | - $cible = '#' . implode(',#', $cible); |
|
| 72 | + $cible = '#'.implode(',#', $cible); |
|
| 73 | 73 | } else { |
| 74 | 74 | $cible = "#$bouton_id + div.bloc_depliable"; |
| 75 | 75 | } |
@@ -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 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return |
| 76 | 76 | **/ |
| 77 | 77 | function inc_genie_dist($taches = []) { |
| 78 | - include_spip('inc/queue'); |
|
| 79 | - |
|
| 80 | - if (_request('exec') == 'job_queue') { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $force_jobs = []; |
|
| 85 | - // l'ancienne facon de lancer une tache cron immediatement |
|
| 86 | - // etait de la passer en parametre a ing_genie_dist |
|
| 87 | - // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 88 | - foreach ($taches as $function => $period) { |
|
| 89 | - $force_jobs[] = queue_add_job( |
|
| 90 | - $function, |
|
| 91 | - _T('tache_cron_asap', ['function' => $function]), |
|
| 92 | - [time() - abs($period)], |
|
| 93 | - 'genie/' |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // et on passe la main a la gestion de la queue ! |
|
| 98 | - // en forcant eventuellement les jobs ajoute a l'instant |
|
| 99 | - return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 78 | + include_spip('inc/queue'); |
|
| 79 | + |
|
| 80 | + if (_request('exec') == 'job_queue') { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $force_jobs = []; |
|
| 85 | + // l'ancienne facon de lancer une tache cron immediatement |
|
| 86 | + // etait de la passer en parametre a ing_genie_dist |
|
| 87 | + // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 88 | + foreach ($taches as $function => $period) { |
|
| 89 | + $force_jobs[] = queue_add_job( |
|
| 90 | + $function, |
|
| 91 | + _T('tache_cron_asap', ['function' => $function]), |
|
| 92 | + [time() - abs($period)], |
|
| 93 | + 'genie/' |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // et on passe la main a la gestion de la queue ! |
|
| 98 | + // en forcant eventuellement les jobs ajoute a l'instant |
|
| 99 | + return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // |
@@ -109,33 +109,33 @@ discard block |
||
| 109 | 109 | // |
| 110 | 110 | function taches_generales($taches_generales = []) { |
| 111 | 111 | |
| 112 | - // verifier que toutes les taches cron sont planifiees |
|
| 113 | - // c'est une tache cron ! |
|
| 114 | - $taches_generales['queue_watch'] = 3600 * 24; |
|
| 112 | + // verifier que toutes les taches cron sont planifiees |
|
| 113 | + // c'est une tache cron ! |
|
| 114 | + $taches_generales['queue_watch'] = 3600 * 24; |
|
| 115 | 115 | |
| 116 | - // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 117 | - // est fait au coup par coup a present |
|
| 118 | - // $taches_generales['rubriques'] = 3600; |
|
| 116 | + // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 117 | + // est fait au coup par coup a present |
|
| 118 | + // $taches_generales['rubriques'] = 3600; |
|
| 119 | 119 | |
| 120 | - // Optimisation de la base |
|
| 121 | - $taches_generales['optimiser'] = 3600 * 48; |
|
| 120 | + // Optimisation de la base |
|
| 121 | + $taches_generales['optimiser'] = 3600 * 48; |
|
| 122 | 122 | |
| 123 | - // nouveautes |
|
| 124 | - if ( |
|
| 125 | - isset($GLOBALS['meta']['adresse_neuf']) and $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | - and $GLOBALS['meta']['jours_neuf'] |
|
| 127 | - and ($GLOBALS['meta']['quoi_de_neuf'] == 'oui') |
|
| 128 | - ) { |
|
| 129 | - $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | - } |
|
| 123 | + // nouveautes |
|
| 124 | + if ( |
|
| 125 | + isset($GLOBALS['meta']['adresse_neuf']) and $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | + and $GLOBALS['meta']['jours_neuf'] |
|
| 127 | + and ($GLOBALS['meta']['quoi_de_neuf'] == 'oui') |
|
| 128 | + ) { |
|
| 129 | + $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // maintenance (ajax, verifications diverses) |
|
| 133 | - $taches_generales['maintenance'] = 3600 * 2; |
|
| 132 | + // maintenance (ajax, verifications diverses) |
|
| 133 | + $taches_generales['maintenance'] = 3600 * 2; |
|
| 134 | 134 | |
| 135 | - // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | - $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 135 | + // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | + $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 137 | 137 | |
| 138 | - return pipeline('taches_generales_cron', $taches_generales); |
|
| 138 | + return pipeline('taches_generales_cron', $taches_generales); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,22 +151,22 @@ discard block |
||
| 151 | 151 | * @return int |
| 152 | 152 | */ |
| 153 | 153 | function genie_queue_watch_dist() { |
| 154 | - static $deja_la = false; |
|
| 155 | - if ($deja_la) { |
|
| 156 | - return; |
|
| 157 | - } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | - $deja_la = true; |
|
| 159 | - $taches = taches_generales(); |
|
| 160 | - $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | - $programmees = array_column($programmees, 'fonction'); |
|
| 162 | - foreach ($taches as $tache => $periode) { |
|
| 163 | - if (!in_array($tache, $programmees)) { |
|
| 164 | - queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - $deja_la = false; |
|
| 168 | - |
|
| 169 | - return 1; |
|
| 154 | + static $deja_la = false; |
|
| 155 | + if ($deja_la) { |
|
| 156 | + return; |
|
| 157 | + } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | + $deja_la = true; |
|
| 159 | + $taches = taches_generales(); |
|
| 160 | + $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | + $programmees = array_column($programmees, 'fonction'); |
|
| 162 | + foreach ($taches as $tache => $periode) { |
|
| 163 | + if (!in_array($tache, $programmees)) { |
|
| 164 | + queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + $deja_la = false; |
|
| 168 | + |
|
| 169 | + return 1; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -187,32 +187,32 @@ discard block |
||
| 187 | 187 | * @return void |
| 188 | 188 | */ |
| 189 | 189 | function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) { |
| 190 | - static $done = []; |
|
| 191 | - if (isset($done[$function])) { |
|
| 192 | - return; |
|
| 193 | - } |
|
| 194 | - $done[$function] = true; |
|
| 195 | - if (is_null($time)) { |
|
| 196 | - $time = time(); |
|
| 197 | - if ($last) { |
|
| 198 | - $time = max($last + $period, $time); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - if (!$last) { |
|
| 202 | - $last = $time - $period; |
|
| 203 | - } |
|
| 204 | - spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | - include_spip('inc/queue'); |
|
| 206 | - // on replanifie un job cron |
|
| 207 | - // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | - // independament de l'argument |
|
| 209 | - queue_add_job( |
|
| 210 | - $function, |
|
| 211 | - _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | - [$last], |
|
| 213 | - 'genie/', |
|
| 214 | - 'function_only', |
|
| 215 | - $time, |
|
| 216 | - $priority |
|
| 217 | - ); |
|
| 190 | + static $done = []; |
|
| 191 | + if (isset($done[$function])) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 194 | + $done[$function] = true; |
|
| 195 | + if (is_null($time)) { |
|
| 196 | + $time = time(); |
|
| 197 | + if ($last) { |
|
| 198 | + $time = max($last + $period, $time); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + if (!$last) { |
|
| 202 | + $last = $time - $period; |
|
| 203 | + } |
|
| 204 | + spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | + include_spip('inc/queue'); |
|
| 206 | + // on replanifie un job cron |
|
| 207 | + // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | + // independament de l'argument |
|
| 209 | + queue_add_job( |
|
| 210 | + $function, |
|
| 211 | + _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | + [$last], |
|
| 213 | + 'genie/', |
|
| 214 | + 'function_only', |
|
| 215 | + $time, |
|
| 216 | + $priority |
|
| 217 | + ); |
|
| 218 | 218 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | . $pere |
| 62 | 62 | . '</b>' |
| 63 | 63 | . (!$bons_peres ? '' |
| 64 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 64 | + : ('<p style="font-size: 80%"> '._T('zxml_mais_de').' <b>'.$bons_peres.'</b></p>'))); |
|
| 65 | 65 | } elseif ($this->dtc->regles[$pere][0] == '/') { |
| 66 | 66 | $frat = substr($depth, 2); |
| 67 | 67 | if (!isset($this->fratrie[$frat])) { |
@@ -98,15 +98,15 @@ discard block |
||
| 98 | 98 | if (!isset($a[$name])) { |
| 99 | 99 | $bons = join(', ', array_keys($a)); |
| 100 | 100 | if ($bons) { |
| 101 | - $bons = " title=' " . |
|
| 102 | - _T('zxml_connus_attributs') . |
|
| 103 | - ' : ' . |
|
| 104 | - $bons . |
|
| 101 | + $bons = " title=' ". |
|
| 102 | + _T('zxml_connus_attributs'). |
|
| 103 | + ' : '. |
|
| 104 | + $bons. |
|
| 105 | 105 | "'"; |
| 106 | 106 | } |
| 107 | 107 | $bons .= " style='font-weight: bold'"; |
| 108 | 108 | coordonnees_erreur($this, " <b>$name</b> " |
| 109 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 109 | + . _T('zxml_inconnu_attribut').' '._T('zxml_de') |
|
| 110 | 110 | . " <a$bons>$bal</a> (" |
| 111 | 111 | . _T('zxml_survoler') |
| 112 | 112 | . ')'); |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | if (!preg_match('/^\w+$/', $type)) { |
| 116 | 116 | $this->valider_motif($phraseur, $name, $val, $bal, $type); |
| 117 | 117 | } else { |
| 118 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 118 | + if (method_exists($this, $f = 'validerAttribut_'.$type)) { |
|
| 119 | 119 | $this->$f($phraseur, $name, $val, $bal); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -164,13 +164,13 @@ discard block |
||
| 164 | 164 | . " <b>$bal</b> " |
| 165 | 165 | . _T('zxml_non_conforme') |
| 166 | 166 | . '</p><p>' |
| 167 | - . '<b>' . $motif . '</b>'); |
|
| 167 | + . '<b>'.$motif.'</b>'); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | public function valider_idref($nom, $ligne, $col) { |
| 172 | 172 | if (!isset($this->ids[$nom])) { |
| 173 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 173 | + $this->err[] = [" <p><b>$nom</b> "._T('zxml_inconnu_id'), $ligne, $col]; |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | // controler que les balises devant etre vides le sont |
| 218 | 218 | if ($vide) { |
| 219 | 219 | if ($n <> ($k + $c)) { |
| 220 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 220 | + coordonnees_erreur($this, " <p><b>$name</b> "._T('zxml_nonvide_balise')); |
|
| 221 | 221 | } |
| 222 | 222 | // pour les regles PCDATA ou iteration de disjonction, tout est fait |
| 223 | 223 | } elseif ($regle and ($regle != '*')) { |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $d = $this->ouvrant[$d]; |
| 253 | 253 | preg_match('/^\s*(\S+)/', $d, $m); |
| 254 | 254 | if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
| 255 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 255 | + coordonnees_erreur($this, ' <p><b>'.$m[1].'</b> ' |
|
| 256 | 256 | . _T('zxml_nonvide_balise')); // message a affiner |
| 257 | 257 | } |
| 258 | 258 | } |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | public function phraserTout($phraseur, $data) { |
| 297 | 297 | xml_parsestring($this, $data); |
| 298 | 298 | |
| 299 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 299 | + if (!$this->dtc or preg_match(',^'._MESSAGE_DOCTYPE.',', $data)) { |
|
| 300 | 300 | $this->err[] = ['DOCTYPE ?', 0, 0]; |
| 301 | 301 | } else { |
| 302 | 302 | $this->valider_passe2(); |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -23,322 +23,322 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | class ValidateurXML |
| 25 | 25 | { |
| 26 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 27 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 28 | - if ($p = strpos($name, ':')) { |
|
| 29 | - $name = substr($name, $p + 1); |
|
| 30 | - $p = isset($this->dtc->elements[$name]); |
|
| 31 | - } |
|
| 32 | - if (!$p) { |
|
| 33 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 34 | - . _T('zxml_inconnu_balise')); |
|
| 35 | - |
|
| 36 | - return; |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - // controler les filles illegitimes, ca suffit |
|
| 40 | - $depth = $this->depth; |
|
| 41 | - $ouvrant = $this->ouvrant; |
|
| 42 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 43 | - if (isset($ouvrant[$depth])) { |
|
| 44 | - if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 45 | - $pere = $r[1]; |
|
| 46 | - #spip_log("pere $pere"); |
|
| 47 | - if (isset($this->dtc->elements[$pere])) { |
|
| 48 | - $fils = $this->dtc->elements[$pere]; |
|
| 49 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 50 | - if (!($p = @in_array($name, $fils))) { |
|
| 51 | - if ($p = strpos($name, ':')) { |
|
| 52 | - $p = substr($name, $p + 1); |
|
| 53 | - $p = @in_array($p, $fils); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - if (!$p) { |
|
| 57 | - $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 58 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 59 | - . _T('zxml_non_fils') |
|
| 60 | - . ' <b>' |
|
| 61 | - . $pere |
|
| 62 | - . '</b>' |
|
| 63 | - . (!$bons_peres ? '' |
|
| 64 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 66 | - $frat = substr($depth, 2); |
|
| 67 | - if (!isset($this->fratrie[$frat])) { |
|
| 68 | - $this->fratrie[$frat] = ''; |
|
| 69 | - } |
|
| 70 | - $this->fratrie[$frat] .= "$name "; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 76 | - if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 77 | - $this->fratrie[$depth] = ''; |
|
| 78 | - } |
|
| 79 | - if (isset($this->dtc->attributs[$name])) { |
|
| 80 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 81 | - if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 82 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 83 | - . ' : ' |
|
| 84 | - . _T('zxml_obligatoire_attribut') |
|
| 85 | - . " <b>$name</b>"); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 92 | - // Si la balise est inconnue, eviter d'insister |
|
| 93 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $a = $this->dtc->attributs[$bal]; |
|
| 98 | - if (!isset($a[$name])) { |
|
| 99 | - $bons = join(', ', array_keys($a)); |
|
| 100 | - if ($bons) { |
|
| 101 | - $bons = " title=' " . |
|
| 102 | - _T('zxml_connus_attributs') . |
|
| 103 | - ' : ' . |
|
| 104 | - $bons . |
|
| 105 | - "'"; |
|
| 106 | - } |
|
| 107 | - $bons .= " style='font-weight: bold'"; |
|
| 108 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 109 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 110 | - . " <a$bons>$bal</a> (" |
|
| 111 | - . _T('zxml_survoler') |
|
| 112 | - . ')'); |
|
| 113 | - } else { |
|
| 114 | - $type = $a[$name][0]; |
|
| 115 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 116 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 117 | - } else { |
|
| 118 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 119 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 127 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 131 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 135 | - if (isset($this->ids[$val])) { |
|
| 136 | - [$l, $c] = $this->ids[$val]; |
|
| 137 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 138 | - . _T('zxml_valeur_attribut') |
|
| 139 | - . " <b>$name</b> " |
|
| 140 | - . _T('zxml_de') |
|
| 141 | - . " <b>$bal</b> " |
|
| 142 | - . _T('zxml_vu') |
|
| 143 | - . " (L$l,C$c)"); |
|
| 144 | - } else { |
|
| 145 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 146 | - $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 151 | - $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 155 | - $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 159 | - if (!preg_match($motif, $val)) { |
|
| 160 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 161 | - . _T('zxml_valeur_attribut') |
|
| 162 | - . " <b>$name</b> " |
|
| 163 | - . _T('zxml_de') |
|
| 164 | - . " <b>$bal</b> " |
|
| 165 | - . _T('zxml_non_conforme') |
|
| 166 | - . '</p><p>' |
|
| 167 | - . '<b>' . $motif . '</b>'); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function valider_idref($nom, $ligne, $col) { |
|
| 172 | - if (!isset($this->ids[$nom])) { |
|
| 173 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function valider_passe2() { |
|
| 178 | - if (!$this->err) { |
|
| 179 | - foreach ($this->idrefs as $idref) { |
|
| 180 | - [$nom, $ligne, $col] = $idref; |
|
| 181 | - $this->valider_idref($nom, $ligne, $col); |
|
| 182 | - } |
|
| 183 | - foreach ($this->idrefss as $idref) { |
|
| 184 | - [$noms, $ligne, $col] = $idref; |
|
| 185 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 186 | - $this->valider_idref($nom, $ligne, $col); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 193 | - if ($this->dtc->elements) { |
|
| 194 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if ($f = $this->process['debut']) { |
|
| 198 | - $f($this, $name, $attrs); |
|
| 199 | - } |
|
| 200 | - $depth = $this->depth; |
|
| 201 | - $this->debuts[$depth] = strlen($this->res); |
|
| 202 | - foreach ($attrs as $k => $v) { |
|
| 203 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - public function finElement($phraseur, $name) { |
|
| 208 | - $depth = $this->depth; |
|
| 209 | - $contenu = $this->contenu; |
|
| 210 | - |
|
| 211 | - $n = strlen($this->res); |
|
| 212 | - $c = strlen(trim($contenu[$depth])); |
|
| 213 | - $k = $this->debuts[$depth]; |
|
| 214 | - |
|
| 215 | - $regle = $this->dtc->regles[$name] ?? false; |
|
| 216 | - $vide = ($regle == 'EMPTY'); |
|
| 217 | - // controler que les balises devant etre vides le sont |
|
| 218 | - if ($vide) { |
|
| 219 | - if ($n <> ($k + $c)) { |
|
| 220 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 221 | - } |
|
| 222 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 223 | - } elseif ($regle and ($regle != '*')) { |
|
| 224 | - if ($regle == '+') { |
|
| 225 | - // iteration de disjonction non vide: 1 balise au - |
|
| 226 | - if ($n == $k) { |
|
| 227 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 228 | - . _T('zxml_vide_balise')); |
|
| 229 | - } |
|
| 230 | - } else { |
|
| 231 | - $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 232 | - if (is_null($f) or !preg_match($regle, $f)) { |
|
| 233 | - coordonnees_erreur( |
|
| 234 | - $this, |
|
| 235 | - " <p>\n<b>$name</b> " |
|
| 236 | - . _T('zxml_succession_fils_incorrecte') |
|
| 237 | - . ' : <b>' |
|
| 238 | - . $f |
|
| 239 | - . '</b>' |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - if ($f = $this->process['fin']) { |
|
| 245 | - $f($this, $name, $vide); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - public function textElement($phraseur, $data) { |
|
| 250 | - if (trim($data)) { |
|
| 251 | - $d = $this->depth; |
|
| 252 | - $d = $this->ouvrant[$d]; |
|
| 253 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 254 | - if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 255 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 256 | - . _T('zxml_nonvide_balise')); // message a affiner |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - if ($f = $this->process['text']) { |
|
| 260 | - $f($this, $data); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - public function piElement($phraseur, $target, $data) { |
|
| 265 | - if ($f = $this->process['pi']) { |
|
| 266 | - $f($this, $target, $data); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Denonciation des entitees XML inconnues |
|
| 271 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 272 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 273 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 274 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 275 | - // le source de la page laisse legitimement supposer. |
|
| 276 | - |
|
| 277 | - public function defaultElement($phraseur, $data) { |
|
| 278 | - if ( |
|
| 279 | - !preg_match('/^<!--/', $data) |
|
| 280 | - and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 281 | - ) { |
|
| 282 | - foreach ($r as $m) { |
|
| 283 | - [$t, $e] = $m; |
|
| 284 | - if (!isset($this->dtc->entites[$e])) { |
|
| 285 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 286 | - . _T('zxml_inconnu_entite') |
|
| 287 | - . ' '); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 292 | - $f($this, $data); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - public function phraserTout($phraseur, $data) { |
|
| 297 | - xml_parsestring($this, $data); |
|
| 298 | - |
|
| 299 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 300 | - $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 301 | - } else { |
|
| 302 | - $this->valider_passe2(); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Constructeur |
|
| 308 | - * |
|
| 309 | - * @param array $process ? |
|
| 310 | - **/ |
|
| 311 | - public function __construct($process = []) { |
|
| 312 | - if (is_array($process)) { |
|
| 313 | - $this->process = $process; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - public $ids = []; |
|
| 318 | - public $idrefs = []; |
|
| 319 | - public $idrefss = []; |
|
| 320 | - public $debuts = []; |
|
| 321 | - public $fratrie = []; |
|
| 322 | - |
|
| 323 | - public $dtc = null; |
|
| 324 | - public $sax = null; |
|
| 325 | - public $depth = ''; |
|
| 326 | - public $entete = ''; |
|
| 327 | - public $page = ''; |
|
| 328 | - public $res = ''; |
|
| 329 | - public array $err = []; |
|
| 330 | - public array $contenu = []; |
|
| 331 | - public array $versions = []; |
|
| 332 | - |
|
| 333 | - public array $ouvrant = []; |
|
| 334 | - public array $reperes = []; |
|
| 335 | - public array $process = [ |
|
| 336 | - 'debut' => 'xml_debutElement', |
|
| 337 | - 'fin' => 'xml_finElement', |
|
| 338 | - 'text' => 'xml_textElement', |
|
| 339 | - 'pi' => 'xml_piElement', |
|
| 340 | - 'default' => 'xml_defaultElement' |
|
| 341 | - ]; |
|
| 26 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 27 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 28 | + if ($p = strpos($name, ':')) { |
|
| 29 | + $name = substr($name, $p + 1); |
|
| 30 | + $p = isset($this->dtc->elements[$name]); |
|
| 31 | + } |
|
| 32 | + if (!$p) { |
|
| 33 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 34 | + . _T('zxml_inconnu_balise')); |
|
| 35 | + |
|
| 36 | + return; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + // controler les filles illegitimes, ca suffit |
|
| 40 | + $depth = $this->depth; |
|
| 41 | + $ouvrant = $this->ouvrant; |
|
| 42 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 43 | + if (isset($ouvrant[$depth])) { |
|
| 44 | + if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 45 | + $pere = $r[1]; |
|
| 46 | + #spip_log("pere $pere"); |
|
| 47 | + if (isset($this->dtc->elements[$pere])) { |
|
| 48 | + $fils = $this->dtc->elements[$pere]; |
|
| 49 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 50 | + if (!($p = @in_array($name, $fils))) { |
|
| 51 | + if ($p = strpos($name, ':')) { |
|
| 52 | + $p = substr($name, $p + 1); |
|
| 53 | + $p = @in_array($p, $fils); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + if (!$p) { |
|
| 57 | + $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 58 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 59 | + . _T('zxml_non_fils') |
|
| 60 | + . ' <b>' |
|
| 61 | + . $pere |
|
| 62 | + . '</b>' |
|
| 63 | + . (!$bons_peres ? '' |
|
| 64 | + : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 66 | + $frat = substr($depth, 2); |
|
| 67 | + if (!isset($this->fratrie[$frat])) { |
|
| 68 | + $this->fratrie[$frat] = ''; |
|
| 69 | + } |
|
| 70 | + $this->fratrie[$frat] .= "$name "; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 76 | + if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 77 | + $this->fratrie[$depth] = ''; |
|
| 78 | + } |
|
| 79 | + if (isset($this->dtc->attributs[$name])) { |
|
| 80 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 81 | + if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 82 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 83 | + . ' : ' |
|
| 84 | + . _T('zxml_obligatoire_attribut') |
|
| 85 | + . " <b>$name</b>"); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 92 | + // Si la balise est inconnue, eviter d'insister |
|
| 93 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $a = $this->dtc->attributs[$bal]; |
|
| 98 | + if (!isset($a[$name])) { |
|
| 99 | + $bons = join(', ', array_keys($a)); |
|
| 100 | + if ($bons) { |
|
| 101 | + $bons = " title=' " . |
|
| 102 | + _T('zxml_connus_attributs') . |
|
| 103 | + ' : ' . |
|
| 104 | + $bons . |
|
| 105 | + "'"; |
|
| 106 | + } |
|
| 107 | + $bons .= " style='font-weight: bold'"; |
|
| 108 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 109 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 110 | + . " <a$bons>$bal</a> (" |
|
| 111 | + . _T('zxml_survoler') |
|
| 112 | + . ')'); |
|
| 113 | + } else { |
|
| 114 | + $type = $a[$name][0]; |
|
| 115 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 116 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 117 | + } else { |
|
| 118 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 119 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 127 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 131 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 135 | + if (isset($this->ids[$val])) { |
|
| 136 | + [$l, $c] = $this->ids[$val]; |
|
| 137 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 138 | + . _T('zxml_valeur_attribut') |
|
| 139 | + . " <b>$name</b> " |
|
| 140 | + . _T('zxml_de') |
|
| 141 | + . " <b>$bal</b> " |
|
| 142 | + . _T('zxml_vu') |
|
| 143 | + . " (L$l,C$c)"); |
|
| 144 | + } else { |
|
| 145 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 146 | + $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 151 | + $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 155 | + $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 159 | + if (!preg_match($motif, $val)) { |
|
| 160 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 161 | + . _T('zxml_valeur_attribut') |
|
| 162 | + . " <b>$name</b> " |
|
| 163 | + . _T('zxml_de') |
|
| 164 | + . " <b>$bal</b> " |
|
| 165 | + . _T('zxml_non_conforme') |
|
| 166 | + . '</p><p>' |
|
| 167 | + . '<b>' . $motif . '</b>'); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function valider_idref($nom, $ligne, $col) { |
|
| 172 | + if (!isset($this->ids[$nom])) { |
|
| 173 | + $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function valider_passe2() { |
|
| 178 | + if (!$this->err) { |
|
| 179 | + foreach ($this->idrefs as $idref) { |
|
| 180 | + [$nom, $ligne, $col] = $idref; |
|
| 181 | + $this->valider_idref($nom, $ligne, $col); |
|
| 182 | + } |
|
| 183 | + foreach ($this->idrefss as $idref) { |
|
| 184 | + [$noms, $ligne, $col] = $idref; |
|
| 185 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 186 | + $this->valider_idref($nom, $ligne, $col); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 193 | + if ($this->dtc->elements) { |
|
| 194 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if ($f = $this->process['debut']) { |
|
| 198 | + $f($this, $name, $attrs); |
|
| 199 | + } |
|
| 200 | + $depth = $this->depth; |
|
| 201 | + $this->debuts[$depth] = strlen($this->res); |
|
| 202 | + foreach ($attrs as $k => $v) { |
|
| 203 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + public function finElement($phraseur, $name) { |
|
| 208 | + $depth = $this->depth; |
|
| 209 | + $contenu = $this->contenu; |
|
| 210 | + |
|
| 211 | + $n = strlen($this->res); |
|
| 212 | + $c = strlen(trim($contenu[$depth])); |
|
| 213 | + $k = $this->debuts[$depth]; |
|
| 214 | + |
|
| 215 | + $regle = $this->dtc->regles[$name] ?? false; |
|
| 216 | + $vide = ($regle == 'EMPTY'); |
|
| 217 | + // controler que les balises devant etre vides le sont |
|
| 218 | + if ($vide) { |
|
| 219 | + if ($n <> ($k + $c)) { |
|
| 220 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 221 | + } |
|
| 222 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 223 | + } elseif ($regle and ($regle != '*')) { |
|
| 224 | + if ($regle == '+') { |
|
| 225 | + // iteration de disjonction non vide: 1 balise au - |
|
| 226 | + if ($n == $k) { |
|
| 227 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 228 | + . _T('zxml_vide_balise')); |
|
| 229 | + } |
|
| 230 | + } else { |
|
| 231 | + $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 232 | + if (is_null($f) or !preg_match($regle, $f)) { |
|
| 233 | + coordonnees_erreur( |
|
| 234 | + $this, |
|
| 235 | + " <p>\n<b>$name</b> " |
|
| 236 | + . _T('zxml_succession_fils_incorrecte') |
|
| 237 | + . ' : <b>' |
|
| 238 | + . $f |
|
| 239 | + . '</b>' |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + if ($f = $this->process['fin']) { |
|
| 245 | + $f($this, $name, $vide); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + public function textElement($phraseur, $data) { |
|
| 250 | + if (trim($data)) { |
|
| 251 | + $d = $this->depth; |
|
| 252 | + $d = $this->ouvrant[$d]; |
|
| 253 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 254 | + if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 255 | + coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 256 | + . _T('zxml_nonvide_balise')); // message a affiner |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + if ($f = $this->process['text']) { |
|
| 260 | + $f($this, $data); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + public function piElement($phraseur, $target, $data) { |
|
| 265 | + if ($f = $this->process['pi']) { |
|
| 266 | + $f($this, $target, $data); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Denonciation des entitees XML inconnues |
|
| 271 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 272 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 273 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 274 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 275 | + // le source de la page laisse legitimement supposer. |
|
| 276 | + |
|
| 277 | + public function defaultElement($phraseur, $data) { |
|
| 278 | + if ( |
|
| 279 | + !preg_match('/^<!--/', $data) |
|
| 280 | + and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 281 | + ) { |
|
| 282 | + foreach ($r as $m) { |
|
| 283 | + [$t, $e] = $m; |
|
| 284 | + if (!isset($this->dtc->entites[$e])) { |
|
| 285 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 286 | + . _T('zxml_inconnu_entite') |
|
| 287 | + . ' '); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 292 | + $f($this, $data); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + public function phraserTout($phraseur, $data) { |
|
| 297 | + xml_parsestring($this, $data); |
|
| 298 | + |
|
| 299 | + if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 300 | + $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 301 | + } else { |
|
| 302 | + $this->valider_passe2(); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Constructeur |
|
| 308 | + * |
|
| 309 | + * @param array $process ? |
|
| 310 | + **/ |
|
| 311 | + public function __construct($process = []) { |
|
| 312 | + if (is_array($process)) { |
|
| 313 | + $this->process = $process; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + public $ids = []; |
|
| 318 | + public $idrefs = []; |
|
| 319 | + public $idrefss = []; |
|
| 320 | + public $debuts = []; |
|
| 321 | + public $fratrie = []; |
|
| 322 | + |
|
| 323 | + public $dtc = null; |
|
| 324 | + public $sax = null; |
|
| 325 | + public $depth = ''; |
|
| 326 | + public $entete = ''; |
|
| 327 | + public $page = ''; |
|
| 328 | + public $res = ''; |
|
| 329 | + public array $err = []; |
|
| 330 | + public array $contenu = []; |
|
| 331 | + public array $versions = []; |
|
| 332 | + |
|
| 333 | + public array $ouvrant = []; |
|
| 334 | + public array $reperes = []; |
|
| 335 | + public array $process = [ |
|
| 336 | + 'debut' => 'xml_debutElement', |
|
| 337 | + 'fin' => 'xml_finElement', |
|
| 338 | + 'text' => 'xml_textElement', |
|
| 339 | + 'pi' => 'xml_piElement', |
|
| 340 | + 'default' => 'xml_defaultElement' |
|
| 341 | + ]; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | * |
| 349 | 349 | **/ |
| 350 | 350 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 351 | - $f = new ValidateurXML($process); |
|
| 352 | - $sax = charger_fonction('sax', 'xml'); |
|
| 351 | + $f = new ValidateurXML($process); |
|
| 352 | + $sax = charger_fonction('sax', 'xml'); |
|
| 353 | 353 | |
| 354 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 354 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 355 | 355 | } |