@@ -21,74 +21,74 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | // http://doc.spip.org/@interprete_argument_balise |
| 23 | 23 | function interprete_argument_balise($n,$p) { |
| 24 | - if (($p->param) && (!$p->param[0][0]) && (count($p->param[0])>$n)) |
|
| 25 | - return calculer_liste($p->param[0][$n], |
|
| 26 | - $p->descr, |
|
| 27 | - $p->boucles, |
|
| 28 | - $p->id_boucle); |
|
| 29 | - else |
|
| 30 | - return NULL; |
|
| 24 | + if (($p->param) && (!$p->param[0][0]) && (count($p->param[0])>$n)) |
|
| 25 | + return calculer_liste($p->param[0][$n], |
|
| 26 | + $p->descr, |
|
| 27 | + $p->boucles, |
|
| 28 | + $p->id_boucle); |
|
| 29 | + else |
|
| 30 | + return NULL; |
|
| 31 | 31 | } |
| 32 | 32 | // |
| 33 | 33 | // Definition des balises |
| 34 | 34 | // |
| 35 | 35 | // http://doc.spip.org/@balise_NOM_SITE_SPIP_dist |
| 36 | 36 | function balise_NOM_SITE_SPIP_dist($p) { |
| 37 | - $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 38 | - #$p->interdire_scripts = true; |
|
| 39 | - return $p; |
|
| 37 | + $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 38 | + #$p->interdire_scripts = true; |
|
| 39 | + return $p; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // http://doc.spip.org/@balise_EMAIL_WEBMASTER_dist |
| 43 | 43 | function balise_EMAIL_WEBMASTER_dist($p) { |
| 44 | - $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 45 | - #$p->interdire_scripts = true; |
|
| 46 | - return $p; |
|
| 44 | + $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 45 | + #$p->interdire_scripts = true; |
|
| 46 | + return $p; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | // http://doc.spip.org/@balise_DESCRIPTIF_SITE_SPIP_dist |
| 50 | 50 | function balise_DESCRIPTIF_SITE_SPIP_dist($p) { |
| 51 | - $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 52 | - #$p->interdire_scripts = true; |
|
| 53 | - return $p; |
|
| 51 | + $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 52 | + #$p->interdire_scripts = true; |
|
| 53 | + return $p; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // http://doc.spip.org/@balise_CHARSET_dist |
| 57 | 57 | function balise_CHARSET_dist($p) { |
| 58 | - $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 59 | - #$p->interdire_scripts = true; |
|
| 60 | - return $p; |
|
| 58 | + $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 59 | + #$p->interdire_scripts = true; |
|
| 60 | + return $p; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // http://doc.spip.org/@balise_LANG_LEFT_dist |
| 64 | 64 | function balise_LANG_LEFT_dist($p) { |
| 65 | - $_lang = champ_sql('lang', $p); |
|
| 66 | - $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 67 | - $p->interdire_scripts = false; |
|
| 68 | - return $p; |
|
| 65 | + $_lang = champ_sql('lang', $p); |
|
| 66 | + $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 67 | + $p->interdire_scripts = false; |
|
| 68 | + return $p; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // http://doc.spip.org/@balise_LANG_RIGHT_dist |
| 72 | 72 | function balise_LANG_RIGHT_dist($p) { |
| 73 | - $_lang = champ_sql('lang', $p); |
|
| 74 | - $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 75 | - $p->interdire_scripts = false; |
|
| 76 | - return $p; |
|
| 73 | + $_lang = champ_sql('lang', $p); |
|
| 74 | + $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 75 | + $p->interdire_scripts = false; |
|
| 76 | + return $p; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // http://doc.spip.org/@balise_LANG_DIR_dist |
| 80 | 80 | function balise_LANG_DIR_dist($p) { |
| 81 | - $_lang = champ_sql('lang', $p); |
|
| 82 | - $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 83 | - $p->interdire_scripts = false; |
|
| 84 | - return $p; |
|
| 81 | + $_lang = champ_sql('lang', $p); |
|
| 82 | + $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 83 | + $p->interdire_scripts = false; |
|
| 84 | + return $p; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // http://doc.spip.org/@balise_PUCE_dist |
| 88 | 88 | function balise_PUCE_dist($p) { |
| 89 | - $p->code = "definir_puce()"; |
|
| 90 | - $p->interdire_scripts = false; |
|
| 91 | - return $p; |
|
| 89 | + $p->code = "definir_puce()"; |
|
| 90 | + $p->interdire_scripts = false; |
|
| 91 | + return $p; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // #DATE |
@@ -97,67 +97,67 @@ discard block |
||
| 97 | 97 | // http://www.spip.net/fr_article1971.html |
| 98 | 98 | // http://doc.spip.org/@balise_DATE_dist |
| 99 | 99 | function balise_DATE_dist ($p) { |
| 100 | - $d = champ_sql('date', $p); |
|
| 100 | + $d = champ_sql('date', $p); |
|
| 101 | 101 | # if ($d === "@\$Pile[0]['date']") |
| 102 | 102 | # $d = "isset(\$Pile[0]['date']) ? $d : time()"; |
| 103 | - $p->code = $d; |
|
| 104 | - return $p; |
|
| 103 | + $p->code = $d; |
|
| 104 | + return $p; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // #DATE_REDAC |
| 108 | 108 | // http://www.spip.net/fr_article1971.html |
| 109 | 109 | // http://doc.spip.org/@balise_DATE_REDAC_dist |
| 110 | 110 | function balise_DATE_REDAC_dist ($p) { |
| 111 | - $d = champ_sql('date_redac', $p); |
|
| 111 | + $d = champ_sql('date_redac', $p); |
|
| 112 | 112 | # if ($d === "@\$Pile[0]['date_redac']") |
| 113 | 113 | # $d = "isset(\$Pile[0]['date_redac']) ? $d : time()"; |
| 114 | - $p->code = $d; |
|
| 115 | - $p->interdire_scripts = false; |
|
| 116 | - return $p; |
|
| 114 | + $p->code = $d; |
|
| 115 | + $p->interdire_scripts = false; |
|
| 116 | + return $p; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // #DATE_MODIF |
| 120 | 120 | // http://www.spip.net/fr_article1971.html |
| 121 | 121 | // http://doc.spip.org/@balise_DATE_MODIF_dist |
| 122 | 122 | function balise_DATE_MODIF_dist ($p) { |
| 123 | - $p->code = champ_sql('date_modif', $p); |
|
| 124 | - $p->interdire_scripts = false; |
|
| 125 | - return $p; |
|
| 123 | + $p->code = champ_sql('date_modif', $p); |
|
| 124 | + $p->interdire_scripts = false; |
|
| 125 | + return $p; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // #DATE_NOUVEAUTES |
| 129 | 129 | // http://www.spip.net/fr_article1971.html |
| 130 | 130 | // http://doc.spip.org/@balise_DATE_NOUVEAUTES_dist |
| 131 | 131 | function balise_DATE_NOUVEAUTES_dist($p) { |
| 132 | - $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 132 | + $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 133 | 133 | AND isset(\$GLOBALS['meta']['dernier_envoi_neuf'])) ? |
| 134 | 134 | \$GLOBALS['meta']['dernier_envoi_neuf'] : |
| 135 | 135 | \"'0000-00-00'\")"; |
| 136 | - $p->interdire_scripts = false; |
|
| 137 | - return $p; |
|
| 136 | + $p->interdire_scripts = false; |
|
| 137 | + return $p; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // http://doc.spip.org/@balise_DOSSIER_SQUELETTE_dist |
| 141 | 141 | function balise_DOSSIER_SQUELETTE_dist($p) { |
| 142 | - $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 143 | - $p->code = "_DIR_RACINE . '$code'" . |
|
| 144 | - $p->interdire_scripts = false; |
|
| 145 | - return $p; |
|
| 142 | + $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 143 | + $p->code = "_DIR_RACINE . '$code'" . |
|
| 144 | + $p->interdire_scripts = false; |
|
| 145 | + return $p; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // http://doc.spip.org/@balise_SQUELETTE_dist |
| 149 | 149 | function balise_SQUELETTE_dist($p) { |
| 150 | - $code = addslashes($p->descr['sourcefile']); |
|
| 151 | - $p->code = "'$code'" . |
|
| 152 | - $p->interdire_scripts = false; |
|
| 153 | - return $p; |
|
| 150 | + $code = addslashes($p->descr['sourcefile']); |
|
| 151 | + $p->code = "'$code'" . |
|
| 152 | + $p->interdire_scripts = false; |
|
| 153 | + return $p; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // http://doc.spip.org/@balise_SPIP_VERSION_dist |
| 157 | 157 | function balise_SPIP_VERSION_dist($p) { |
| 158 | - $p->code = "spip_version()"; |
|
| 159 | - $p->interdire_scripts = false; |
|
| 160 | - return $p; |
|
| 158 | + $p->code = "spip_version()"; |
|
| 159 | + $p->interdire_scripts = false; |
|
| 160 | + return $p; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -182,105 +182,105 @@ discard block |
||
| 182 | 182 | * Pile complétée par le code à générer |
| 183 | 183 | **/ |
| 184 | 184 | function balise_NOM_SITE_dist($p) { |
| 185 | - if (!$p->etoile) { |
|
| 186 | - $p->code = "supprimer_numero(calculer_url(" . |
|
| 187 | - champ_sql('url_site',$p) ."," . |
|
| 188 | - champ_sql('nom_site',$p) . |
|
| 189 | - ", 'titre', \$connect, false))"; |
|
| 190 | - } else |
|
| 191 | - $p->code = champ_sql('nom_site',$p); |
|
| 185 | + if (!$p->etoile) { |
|
| 186 | + $p->code = "supprimer_numero(calculer_url(" . |
|
| 187 | + champ_sql('url_site',$p) ."," . |
|
| 188 | + champ_sql('nom_site',$p) . |
|
| 189 | + ", 'titre', \$connect, false))"; |
|
| 190 | + } else |
|
| 191 | + $p->code = champ_sql('nom_site',$p); |
|
| 192 | 192 | |
| 193 | - $p->interdire_scripts = true; |
|
| 194 | - return $p; |
|
| 193 | + $p->interdire_scripts = true; |
|
| 194 | + return $p; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // http://doc.spip.org/@balise_NOTES_dist |
| 198 | 198 | function balise_NOTES_dist($p) { |
| 199 | - // Recuperer les notes |
|
| 200 | - $p->code = 'calculer_notes()'; |
|
| 201 | - #$p->interdire_scripts = true; |
|
| 202 | - return $p; |
|
| 199 | + // Recuperer les notes |
|
| 200 | + $p->code = 'calculer_notes()'; |
|
| 201 | + #$p->interdire_scripts = true; |
|
| 202 | + return $p; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // http://doc.spip.org/@balise_RECHERCHE_dist |
| 206 | 206 | function balise_RECHERCHE_dist($p) { |
| 207 | - $p->code = 'entites_html(_request("recherche"))'; |
|
| 208 | - $p->interdire_scripts = false; |
|
| 209 | - return $p; |
|
| 207 | + $p->code = 'entites_html(_request("recherche"))'; |
|
| 208 | + $p->interdire_scripts = false; |
|
| 209 | + return $p; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // http://doc.spip.org/@balise_COMPTEUR_BOUCLE_dist |
| 213 | 213 | function balise_COMPTEUR_BOUCLE_dist($p) { |
| 214 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 215 | - if ($b === '') { |
|
| 216 | - $msg = array('zbug_champ_hors_boucle', |
|
| 217 | - array('champ' => '#COMPTEUR_BOUCLE') |
|
| 218 | - ); |
|
| 219 | - erreur_squelette($msg, $p); |
|
| 220 | - } else { |
|
| 221 | - $p->code = "\$Numrows['$b']['compteur_boucle']"; |
|
| 222 | - $p->boucles[$b]->cptrows = true; |
|
| 223 | - $p->interdire_scripts = false; |
|
| 224 | - return $p; |
|
| 225 | - } |
|
| 214 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 215 | + if ($b === '') { |
|
| 216 | + $msg = array('zbug_champ_hors_boucle', |
|
| 217 | + array('champ' => '#COMPTEUR_BOUCLE') |
|
| 218 | + ); |
|
| 219 | + erreur_squelette($msg, $p); |
|
| 220 | + } else { |
|
| 221 | + $p->code = "\$Numrows['$b']['compteur_boucle']"; |
|
| 222 | + $p->boucles[$b]->cptrows = true; |
|
| 223 | + $p->interdire_scripts = false; |
|
| 224 | + return $p; |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // http://doc.spip.org/@balise_TOTAL_BOUCLE_dist |
| 229 | 229 | function balise_TOTAL_BOUCLE_dist($p) { |
| 230 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 231 | - if ($b === '' || !isset($p->boucles[$b])) { |
|
| 232 | - $msg = array('zbug_champ_hors_boucle', |
|
| 233 | - array('champ' => "#$b" . 'TOTAL_BOUCLE') |
|
| 234 | - ); |
|
| 235 | - erreur_squelette($msg, $p); |
|
| 236 | - } else { |
|
| 237 | - $p->code = "\$Numrows['$b']['total']"; |
|
| 238 | - $p->boucles[$b]->numrows = true; |
|
| 239 | - $p->interdire_scripts = false; |
|
| 240 | - } |
|
| 241 | - return $p; |
|
| 230 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 231 | + if ($b === '' || !isset($p->boucles[$b])) { |
|
| 232 | + $msg = array('zbug_champ_hors_boucle', |
|
| 233 | + array('champ' => "#$b" . 'TOTAL_BOUCLE') |
|
| 234 | + ); |
|
| 235 | + erreur_squelette($msg, $p); |
|
| 236 | + } else { |
|
| 237 | + $p->code = "\$Numrows['$b']['total']"; |
|
| 238 | + $p->boucles[$b]->numrows = true; |
|
| 239 | + $p->interdire_scripts = false; |
|
| 240 | + } |
|
| 241 | + return $p; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // Si on est hors d'une boucle {recherche}, ne pas "prendre" cette balise |
| 245 | 245 | // http://doc.spip.org/@balise_POINTS_dist |
| 246 | 246 | function balise_POINTS_dist($p) { |
| 247 | - return rindex_pile($p, 'points', 'recherche'); |
|
| 247 | + return rindex_pile($p, 'points', 'recherche'); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | // http://doc.spip.org/@balise_POPULARITE_ABSOLUE_dist |
| 251 | 251 | function balise_POPULARITE_ABSOLUE_dist($p) { |
| 252 | - $p->code = 'ceil(' . |
|
| 253 | - champ_sql('popularite', $p) . |
|
| 254 | - ')'; |
|
| 255 | - $p->interdire_scripts = false; |
|
| 256 | - return $p; |
|
| 252 | + $p->code = 'ceil(' . |
|
| 253 | + champ_sql('popularite', $p) . |
|
| 254 | + ')'; |
|
| 255 | + $p->interdire_scripts = false; |
|
| 256 | + return $p; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // http://doc.spip.org/@balise_POPULARITE_SITE_dist |
| 260 | 260 | function balise_POPULARITE_SITE_dist($p) { |
| 261 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 262 | - $p->interdire_scripts = false; |
|
| 263 | - return $p; |
|
| 261 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 262 | + $p->interdire_scripts = false; |
|
| 263 | + return $p; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // http://doc.spip.org/@balise_POPULARITE_MAX_dist |
| 267 | 267 | function balise_POPULARITE_MAX_dist($p) { |
| 268 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 269 | - $p->interdire_scripts = false; |
|
| 270 | - return $p; |
|
| 268 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 269 | + $p->interdire_scripts = false; |
|
| 270 | + return $p; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // http://doc.spip.org/@balise_EXPOSE_dist |
| 274 | 274 | function balise_EXPOSE_dist($p) { |
| 275 | - $on = "'on'"; |
|
| 276 | - $off= "''"; |
|
| 277 | - if (($v = interprete_argument_balise(1,$p))!==NULL){ |
|
| 278 | - $on = $v; |
|
| 279 | - if (($v = interprete_argument_balise(2,$p))!==NULL) |
|
| 280 | - $off = $v; |
|
| 275 | + $on = "'on'"; |
|
| 276 | + $off= "''"; |
|
| 277 | + if (($v = interprete_argument_balise(1,$p))!==NULL){ |
|
| 278 | + $on = $v; |
|
| 279 | + if (($v = interprete_argument_balise(2,$p))!==NULL) |
|
| 280 | + $off = $v; |
|
| 281 | 281 | |
| 282 | - } |
|
| 283 | - return calculer_balise_expose($p, $on, $off); |
|
| 282 | + } |
|
| 283 | + return calculer_balise_expose($p, $on, $off); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // #VALEUR renvoie le champ valeur |
@@ -288,44 +288,44 @@ discard block |
||
| 288 | 288 | // #VALEUR{a/b} renvoie #VALEUR|table_valeur{a/b} |
| 289 | 289 | // http://doc.spip.org/@balise_VALEUR_dist |
| 290 | 290 | function balise_VALEUR_dist($p) { |
| 291 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 292 | - $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b);; |
|
| 293 | - if (($v = interprete_argument_balise(1,$p))!==NULL){ |
|
| 294 | - $p->code = 'table_valeur('.$p->code.', '.$v.')'; |
|
| 295 | - } |
|
| 296 | - $p->interdire_scripts = true; |
|
| 297 | - return $p; |
|
| 291 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 292 | + $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b);; |
|
| 293 | + if (($v = interprete_argument_balise(1,$p))!==NULL){ |
|
| 294 | + $p->code = 'table_valeur('.$p->code.', '.$v.')'; |
|
| 295 | + } |
|
| 296 | + $p->interdire_scripts = true; |
|
| 297 | + return $p; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | // http://doc.spip.org/@calculer_balise_expose |
| 301 | 301 | function calculer_balise_expose($p, $on, $off) |
| 302 | 302 | { |
| 303 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 304 | - $key = $p->boucles[$b]->primary; |
|
| 305 | - $type = $p->boucles[$p->id_boucle]->primary; |
|
| 306 | - $desc = $p->boucles[$b]->show; |
|
| 307 | - $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 303 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 304 | + $key = $p->boucles[$b]->primary; |
|
| 305 | + $type = $p->boucles[$p->id_boucle]->primary; |
|
| 306 | + $desc = $p->boucles[$b]->show; |
|
| 307 | + $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 308 | 308 | |
| 309 | - if (!$key) { |
|
| 310 | - $msg = array('zbug_champ_hors_boucle', array('champ' => '#EXPOSER')); |
|
| 311 | - erreur_squelette($msg, $p); |
|
| 312 | - } |
|
| 309 | + if (!$key) { |
|
| 310 | + $msg = array('zbug_champ_hors_boucle', array('champ' => '#EXPOSER')); |
|
| 311 | + erreur_squelette($msg, $p); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 315 | - $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 314 | + // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 315 | + $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 316 | 316 | |
| 317 | - if (isset($desc['field']['id_parent'])) { |
|
| 318 | - $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 319 | - } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 320 | - $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 321 | - } elseif (isset($desc['field']['id_groupe'])) { |
|
| 322 | - $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 323 | - } else $parent = "''"; |
|
| 317 | + if (isset($desc['field']['id_parent'])) { |
|
| 318 | + $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 319 | + } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 320 | + $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 321 | + } elseif (isset($desc['field']['id_groupe'])) { |
|
| 322 | + $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 323 | + } else $parent = "''"; |
|
| 324 | 324 | |
| 325 | - $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 325 | + $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 326 | 326 | |
| 327 | - $p->interdire_scripts = false; |
|
| 328 | - return $p; |
|
| 327 | + $p->interdire_scripts = false; |
|
| 328 | + return $p; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -336,15 +336,15 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | // http://doc.spip.org/@balise_DEBUT_SURLIGNE_dist |
| 338 | 338 | function balise_DEBUT_SURLIGNE_dist($p) { |
| 339 | - include_spip('inc/surligne'); |
|
| 340 | - $p->code = "'<!-- " . MARQUEUR_SURLIGNE . " -->'"; |
|
| 341 | - return $p; |
|
| 339 | + include_spip('inc/surligne'); |
|
| 340 | + $p->code = "'<!-- " . MARQUEUR_SURLIGNE . " -->'"; |
|
| 341 | + return $p; |
|
| 342 | 342 | } |
| 343 | 343 | // http://doc.spip.org/@balise_FIN_SURLIGNE_dist |
| 344 | 344 | function balise_FIN_SURLIGNE_dist($p) { |
| 345 | - include_spip('inc/surligne'); |
|
| 346 | - $p->code = "'<!-- " . MARQUEUR_FSURLIGNE . "-->'"; |
|
| 347 | - return $p; |
|
| 345 | + include_spip('inc/surligne'); |
|
| 346 | + $p->code = "'<!-- " . MARQUEUR_FSURLIGNE . "-->'"; |
|
| 347 | + return $p; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -354,42 +354,42 @@ discard block |
||
| 354 | 354 | // http://doc.spip.org/@balise_INTRODUCTION_dist |
| 355 | 355 | function balise_INTRODUCTION_dist($p) { |
| 356 | 356 | |
| 357 | - $type = $p->type_requete; |
|
| 357 | + $type = $p->type_requete; |
|
| 358 | 358 | |
| 359 | - $_texte = champ_sql('texte', $p); |
|
| 360 | - $_descriptif = ($type == 'articles' OR $type == 'rubriques') ? champ_sql('descriptif', $p) : "''"; |
|
| 359 | + $_texte = champ_sql('texte', $p); |
|
| 360 | + $_descriptif = ($type == 'articles' OR $type == 'rubriques') ? champ_sql('descriptif', $p) : "''"; |
|
| 361 | 361 | |
| 362 | - if ($type == 'articles') { |
|
| 363 | - $_chapo = champ_sql('chapo', $p); |
|
| 364 | - $_texte = "(strlen($_descriptif)) |
|
| 362 | + if ($type == 'articles') { |
|
| 363 | + $_chapo = champ_sql('chapo', $p); |
|
| 364 | + $_texte = "(strlen($_descriptif)) |
|
| 365 | 365 | ? '' |
| 366 | 366 | : $_chapo . \"\\n\\n\" . $_texte"; |
| 367 | - } |
|
| 368 | - |
|
| 369 | - // longueur en parametre, ou valeur par defaut |
|
| 370 | - if (($v = interprete_argument_balise(1,$p))!==NULL) { |
|
| 371 | - $longueur = 'intval('.$v.')'; |
|
| 372 | - } else { |
|
| 373 | - switch ($type) { |
|
| 374 | - case 'articles': |
|
| 375 | - $longueur = '500'; |
|
| 376 | - break; |
|
| 377 | - case 'breves': |
|
| 378 | - $longueur = '300'; |
|
| 379 | - break; |
|
| 380 | - case 'rubriques': |
|
| 381 | - default: |
|
| 382 | - $longueur = '600'; |
|
| 383 | - break; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $f = chercher_filtre('introduction'); |
|
| 388 | - $p->code = "$f($_descriptif, $_texte, $longueur, \$connect)"; |
|
| 389 | - |
|
| 390 | - #$p->interdire_scripts = true; |
|
| 391 | - $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 392 | - return $p; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + // longueur en parametre, ou valeur par defaut |
|
| 370 | + if (($v = interprete_argument_balise(1,$p))!==NULL) { |
|
| 371 | + $longueur = 'intval('.$v.')'; |
|
| 372 | + } else { |
|
| 373 | + switch ($type) { |
|
| 374 | + case 'articles': |
|
| 375 | + $longueur = '500'; |
|
| 376 | + break; |
|
| 377 | + case 'breves': |
|
| 378 | + $longueur = '300'; |
|
| 379 | + break; |
|
| 380 | + case 'rubriques': |
|
| 381 | + default: |
|
| 382 | + $longueur = '600'; |
|
| 383 | + break; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $f = chercher_filtre('introduction'); |
|
| 388 | + $p->code = "$f($_descriptif, $_texte, $longueur, \$connect)"; |
|
| 389 | + |
|
| 390 | + #$p->interdire_scripts = true; |
|
| 391 | + $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 392 | + return $p; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -399,13 +399,13 @@ discard block |
||
| 399 | 399 | // #LANG* n'affiche rien si aucune langue n'est trouvee dans le sql/le contexte |
| 400 | 400 | // http://doc.spip.org/@balise_LANG_dist |
| 401 | 401 | function balise_LANG_dist ($p) { |
| 402 | - $_lang = champ_sql('lang', $p); |
|
| 403 | - if (!$p->etoile) |
|
| 404 | - $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 405 | - else |
|
| 406 | - $p->code = "spip_htmlentities($_lang)"; |
|
| 407 | - $p->interdire_scripts = false; |
|
| 408 | - return $p; |
|
| 402 | + $_lang = champ_sql('lang', $p); |
|
| 403 | + if (!$p->etoile) |
|
| 404 | + $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 405 | + else |
|
| 406 | + $p->code = "spip_htmlentities($_lang)"; |
|
| 407 | + $p->interdire_scripts = false; |
|
| 408 | + return $p; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // #LESAUTEURS |
@@ -414,44 +414,44 @@ discard block |
||
| 414 | 414 | // http://www.spip.net/fr_article911.html |
| 415 | 415 | // http://doc.spip.org/@balise_LESAUTEURS_dist |
| 416 | 416 | function balise_LESAUTEURS_dist ($p) { |
| 417 | - // Cherche le champ 'lesauteurs' dans la pile |
|
| 418 | - $_lesauteurs = champ_sql('lesauteurs', $p, false); |
|
| 419 | - |
|
| 420 | - // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 421 | - // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 422 | - // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 423 | - // (cf extension sites/) |
|
| 424 | - if ($_lesauteurs |
|
| 425 | - AND $_lesauteurs != '@$Pile[0][\'lesauteurs\']') { |
|
| 426 | - $p->code = "safehtml($_lesauteurs)"; |
|
| 427 | - // $p->interdire_scripts = true; |
|
| 428 | - } else { |
|
| 429 | - if(!$p->id_boucle){ |
|
| 430 | - $connect = ''; |
|
| 431 | - $objet = 'article'; |
|
| 432 | - $id_table_objet = 'id_article'; |
|
| 433 | - } |
|
| 434 | - else{ |
|
| 435 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 436 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 437 | - $type_boucle = $p->boucles[$b]->type_requete; |
|
| 438 | - $objet = objet_type($type_boucle); |
|
| 439 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 440 | - } |
|
| 441 | - $c = memoriser_contexte_compil($p); |
|
| 442 | - |
|
| 443 | - $p->code = sprintf(CODE_RECUPERER_FOND, "'modeles/lesauteurs'", |
|
| 444 | - "array('objet'=>'".$objet. |
|
| 445 | - "','id_objet' => ".champ_sql($id_table_objet, $p) . |
|
| 446 | - ",'$id_table_objet' => ".champ_sql($id_table_objet, $p) . |
|
| 447 | - ($objet=='article'?"":",'id_article' => ".champ_sql('id_article', $p)). |
|
| 448 | - ")", |
|
| 449 | - "'trim'=>true, 'compil'=>array($c)", |
|
| 450 | - _q($connect)); |
|
| 451 | - $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return $p; |
|
| 417 | + // Cherche le champ 'lesauteurs' dans la pile |
|
| 418 | + $_lesauteurs = champ_sql('lesauteurs', $p, false); |
|
| 419 | + |
|
| 420 | + // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 421 | + // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 422 | + // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 423 | + // (cf extension sites/) |
|
| 424 | + if ($_lesauteurs |
|
| 425 | + AND $_lesauteurs != '@$Pile[0][\'lesauteurs\']') { |
|
| 426 | + $p->code = "safehtml($_lesauteurs)"; |
|
| 427 | + // $p->interdire_scripts = true; |
|
| 428 | + } else { |
|
| 429 | + if(!$p->id_boucle){ |
|
| 430 | + $connect = ''; |
|
| 431 | + $objet = 'article'; |
|
| 432 | + $id_table_objet = 'id_article'; |
|
| 433 | + } |
|
| 434 | + else{ |
|
| 435 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 436 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 437 | + $type_boucle = $p->boucles[$b]->type_requete; |
|
| 438 | + $objet = objet_type($type_boucle); |
|
| 439 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 440 | + } |
|
| 441 | + $c = memoriser_contexte_compil($p); |
|
| 442 | + |
|
| 443 | + $p->code = sprintf(CODE_RECUPERER_FOND, "'modeles/lesauteurs'", |
|
| 444 | + "array('objet'=>'".$objet. |
|
| 445 | + "','id_objet' => ".champ_sql($id_table_objet, $p) . |
|
| 446 | + ",'$id_table_objet' => ".champ_sql($id_table_objet, $p) . |
|
| 447 | + ($objet=='article'?"":",'id_article' => ".champ_sql('id_article', $p)). |
|
| 448 | + ")", |
|
| 449 | + "'trim'=>true, 'compil'=>array($c)", |
|
| 450 | + _q($connect)); |
|
| 451 | + $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return $p; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | |
@@ -472,62 +472,62 @@ discard block |
||
| 472 | 472 | * @return object |
| 473 | 473 | */ |
| 474 | 474 | function balise_RANG_dist($p) { |
| 475 | - $b = index_boucle($p); |
|
| 476 | - if ($b === '') { |
|
| 477 | - $msg = array( |
|
| 478 | - 'zbug_champ_hors_boucle', |
|
| 479 | - array('champ' => '#RANG') |
|
| 480 | - ); |
|
| 481 | - erreur_squelette($msg, $p); |
|
| 482 | - } else { |
|
| 483 | - // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 484 | - // dans la boucle immediatement englobante uniquement |
|
| 485 | - // sinon on compose le champ calcule |
|
| 486 | - $_rang = champ_sql('rang', $p, '', false); |
|
| 487 | - |
|
| 488 | - // si pas trouve de champ sql rang : |
|
| 489 | - if (!$_rang) { |
|
| 490 | - $boucle = &$p->boucles[$b]; |
|
| 491 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 492 | - $desc = $trouver_table($boucle->id_table); |
|
| 493 | - $_titre = ''; # où extraire le numero ? |
|
| 475 | + $b = index_boucle($p); |
|
| 476 | + if ($b === '') { |
|
| 477 | + $msg = array( |
|
| 478 | + 'zbug_champ_hors_boucle', |
|
| 479 | + array('champ' => '#RANG') |
|
| 480 | + ); |
|
| 481 | + erreur_squelette($msg, $p); |
|
| 482 | + } else { |
|
| 483 | + // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 484 | + // dans la boucle immediatement englobante uniquement |
|
| 485 | + // sinon on compose le champ calcule |
|
| 486 | + $_rang = champ_sql('rang', $p, '', false); |
|
| 487 | + |
|
| 488 | + // si pas trouve de champ sql rang : |
|
| 489 | + if (!$_rang) { |
|
| 490 | + $boucle = &$p->boucles[$b]; |
|
| 491 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 492 | + $desc = $trouver_table($boucle->id_table); |
|
| 493 | + $_titre = ''; # où extraire le numero ? |
|
| 494 | 494 | |
| 495 | - if (isset($desc['titre'])) { |
|
| 496 | - $t = $desc['titre']; |
|
| 497 | - if ( |
|
| 498 | - // Soit on trouve avec la déclaration de la lang AVANT |
|
| 499 | - preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 500 | - // Soit on prend depuis le début |
|
| 501 | - or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 502 | - ) { |
|
| 503 | - $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 504 | - $m = trim($m); |
|
| 505 | - if ($m != "''") { |
|
| 506 | - if (!preg_match(",\W,", $m)) { |
|
| 507 | - $m = $boucle->id_table . ".$m"; |
|
| 508 | - } |
|
| 495 | + if (isset($desc['titre'])) { |
|
| 496 | + $t = $desc['titre']; |
|
| 497 | + if ( |
|
| 498 | + // Soit on trouve avec la déclaration de la lang AVANT |
|
| 499 | + preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 500 | + // Soit on prend depuis le début |
|
| 501 | + or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 502 | + ) { |
|
| 503 | + $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 504 | + $m = trim($m); |
|
| 505 | + if ($m != "''") { |
|
| 506 | + if (!preg_match(",\W,", $m)) { |
|
| 507 | + $m = $boucle->id_table . ".$m"; |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | - $m .= " AS titre_rang"; |
|
| 510 | + $m .= " AS titre_rang"; |
|
| 511 | 511 | |
| 512 | - $boucle->select[] = $m; |
|
| 513 | - $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - } |
|
| 512 | + $boucle->select[] = $m; |
|
| 513 | + $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | 517 | |
| 518 | - // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 519 | - if (!$_titre) { |
|
| 520 | - $_titre = champ_sql('titre', $p); |
|
| 521 | - } |
|
| 518 | + // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 519 | + if (!$_titre) { |
|
| 520 | + $_titre = champ_sql('titre', $p); |
|
| 521 | + } |
|
| 522 | 522 | |
| 523 | - $_rang = "recuperer_numero($_titre)"; |
|
| 524 | - } |
|
| 523 | + $_rang = "recuperer_numero($_titre)"; |
|
| 524 | + } |
|
| 525 | 525 | |
| 526 | - $p->code = $_rang; |
|
| 527 | - $p->interdire_scripts = false; |
|
| 528 | - } |
|
| 526 | + $p->code = $_rang; |
|
| 527 | + $p->interdire_scripts = false; |
|
| 528 | + } |
|
| 529 | 529 | |
| 530 | - return $p; |
|
| 530 | + return $p; |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | |
@@ -535,11 +535,11 @@ discard block |
||
| 535 | 535 | // http://www.spip.net/fr_article1846.html |
| 536 | 536 | // http://doc.spip.org/@balise_POPULARITE_dist |
| 537 | 537 | function balise_POPULARITE_dist ($p) { |
| 538 | - $_popularite = champ_sql('popularite', $p); |
|
| 539 | - $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 538 | + $_popularite = champ_sql('popularite', $p); |
|
| 539 | + $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 540 | 540 | / max(1 , 0 + \$GLOBALS['meta']['popularite_max']))))"; |
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - return $p; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + return $p; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | // #PAGINATION |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | // l'absence peut etre due a une faute de frappe dans le contexte inclus. |
| 549 | 549 | |
| 550 | 550 | define('CODE_PAGINATION', |
| 551 | - '%s($Numrows["%s"]["grand_total"], |
|
| 551 | + '%s($Numrows["%s"]["grand_total"], |
|
| 552 | 552 | %s, |
| 553 | 553 | isset($Pile[0][%4$s])?$Pile[0][%4$s]:intval(_request(%4$s)), |
| 554 | 554 | %5$s, %6$s, %7$s, %8$s, array(%9$s))'); |
@@ -556,59 +556,59 @@ discard block |
||
| 556 | 556 | // http://www.spip.net/fr_article3367.html |
| 557 | 557 | // http://doc.spip.org/@balise_PAGINATION_dist |
| 558 | 558 | function balise_PAGINATION_dist($p, $liste='true') { |
| 559 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 560 | - |
|
| 561 | - // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 562 | - if ($b === '') { |
|
| 563 | - $msg = array('zbug_champ_hors_boucle', |
|
| 564 | - array('champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION') |
|
| 565 | - ); |
|
| 566 | - erreur_squelette($msg, $p); |
|
| 567 | - return $p; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 571 | - // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 572 | - if (!$p->boucles[$b]->mode_partie) { |
|
| 573 | - if (!$p->boucles[$b]->table_optionnelle) { |
|
| 574 | - $msg = array('zbug_pagination_sans_critere', |
|
| 575 | - array('champ' => '#PAGINATION') |
|
| 576 | - ); |
|
| 577 | - erreur_squelette($msg, $p); |
|
| 578 | - } |
|
| 579 | - return $p; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - // a priori true |
|
| 583 | - // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 584 | - // si true, les arguments simples (sans truc=chose) vont degager |
|
| 585 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 586 | - if (count($_contexte)){ |
|
| 587 | - list($key,$val) = each($_contexte); |
|
| 588 | - if (is_numeric($key)){ |
|
| 589 | - array_shift($_contexte); |
|
| 590 | - $__modele = interprete_argument_balise(1,$p); |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - if (count($_contexte)){ |
|
| 595 | - $code_contexte = implode(',',$_contexte); |
|
| 596 | - } |
|
| 597 | - else |
|
| 598 | - $code_contexte = ''; |
|
| 599 | - |
|
| 600 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 601 | - $pas = $p->boucles[$b]->total_parties; |
|
| 602 | - $f_pagination = chercher_filtre('pagination'); |
|
| 603 | - $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 604 | - $modif = ($type[0]!=="'") ? "'debut'.$type" |
|
| 605 | - : ("'debut" .substr($type,1)); |
|
| 606 | - |
|
| 607 | - $p->code = sprintf(CODE_PAGINATION, $f_pagination, $b, $type, $modif, $pas, $liste, ((isset($__modele) and $__modele) ? $__modele : "''"), _q($connect), $code_contexte); |
|
| 608 | - |
|
| 609 | - $p->boucles[$b]->numrows = true; |
|
| 610 | - $p->interdire_scripts = false; |
|
| 611 | - return $p; |
|
| 559 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 560 | + |
|
| 561 | + // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 562 | + if ($b === '') { |
|
| 563 | + $msg = array('zbug_champ_hors_boucle', |
|
| 564 | + array('champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION') |
|
| 565 | + ); |
|
| 566 | + erreur_squelette($msg, $p); |
|
| 567 | + return $p; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 571 | + // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 572 | + if (!$p->boucles[$b]->mode_partie) { |
|
| 573 | + if (!$p->boucles[$b]->table_optionnelle) { |
|
| 574 | + $msg = array('zbug_pagination_sans_critere', |
|
| 575 | + array('champ' => '#PAGINATION') |
|
| 576 | + ); |
|
| 577 | + erreur_squelette($msg, $p); |
|
| 578 | + } |
|
| 579 | + return $p; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + // a priori true |
|
| 583 | + // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 584 | + // si true, les arguments simples (sans truc=chose) vont degager |
|
| 585 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 586 | + if (count($_contexte)){ |
|
| 587 | + list($key,$val) = each($_contexte); |
|
| 588 | + if (is_numeric($key)){ |
|
| 589 | + array_shift($_contexte); |
|
| 590 | + $__modele = interprete_argument_balise(1,$p); |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + if (count($_contexte)){ |
|
| 595 | + $code_contexte = implode(',',$_contexte); |
|
| 596 | + } |
|
| 597 | + else |
|
| 598 | + $code_contexte = ''; |
|
| 599 | + |
|
| 600 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 601 | + $pas = $p->boucles[$b]->total_parties; |
|
| 602 | + $f_pagination = chercher_filtre('pagination'); |
|
| 603 | + $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 604 | + $modif = ($type[0]!=="'") ? "'debut'.$type" |
|
| 605 | + : ("'debut" .substr($type,1)); |
|
| 606 | + |
|
| 607 | + $p->code = sprintf(CODE_PAGINATION, $f_pagination, $b, $type, $modif, $pas, $liste, ((isset($__modele) and $__modele) ? $__modele : "''"), _q($connect), $code_contexte); |
|
| 608 | + |
|
| 609 | + $p->boucles[$b]->numrows = true; |
|
| 610 | + $p->interdire_scripts = false; |
|
| 611 | + return $p; |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | |
@@ -616,28 +616,28 @@ discard block |
||
| 616 | 616 | // qu'on mettra les liens en-dessous de la liste paginee) |
| 617 | 617 | // http://doc.spip.org/@balise_ANCRE_PAGINATION_dist |
| 618 | 618 | function balise_ANCRE_PAGINATION_dist($p) { |
| 619 | - if ($f = charger_fonction('PAGINATION', 'balise', true)) |
|
| 620 | - return $f($p, $liste='false'); |
|
| 621 | - else return NULL; // ou une erreur ? |
|
| 619 | + if ($f = charger_fonction('PAGINATION', 'balise', true)) |
|
| 620 | + return $f($p, $liste='false'); |
|
| 621 | + else return NULL; // ou une erreur ? |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | // equivalent a #TOTAL_BOUCLE sauf pour les boucles paginees, ou elle |
| 625 | 625 | // indique le nombre total d'articles repondant aux criteres hors pagination |
| 626 | 626 | // http://doc.spip.org/@balise_GRAND_TOTAL_dist |
| 627 | 627 | function balise_GRAND_TOTAL_dist($p) { |
| 628 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 629 | - if ($b === '' || !isset($p->boucles[$b])) { |
|
| 630 | - $msg = array('zbug_champ_hors_boucle', |
|
| 631 | - array('champ' => "#$b" . 'TOTAL_BOUCLE') |
|
| 632 | - ); |
|
| 633 | - erreur_squelette($msg, $p); |
|
| 634 | - } else { |
|
| 635 | - $p->code = "(isset(\$Numrows['$b']['grand_total']) |
|
| 628 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 629 | + if ($b === '' || !isset($p->boucles[$b])) { |
|
| 630 | + $msg = array('zbug_champ_hors_boucle', |
|
| 631 | + array('champ' => "#$b" . 'TOTAL_BOUCLE') |
|
| 632 | + ); |
|
| 633 | + erreur_squelette($msg, $p); |
|
| 634 | + } else { |
|
| 635 | + $p->code = "(isset(\$Numrows['$b']['grand_total']) |
|
| 636 | 636 | ? \$Numrows['$b']['grand_total'] : \$Numrows['$b']['total'])"; |
| 637 | - $p->boucles[$b]->numrows = true; |
|
| 638 | - $p->interdire_scripts = false; |
|
| 639 | - } |
|
| 640 | - return $p; |
|
| 637 | + $p->boucles[$b]->numrows = true; |
|
| 638 | + $p->interdire_scripts = false; |
|
| 639 | + } |
|
| 640 | + return $p; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // Reference a l'URL de la page courante |
@@ -647,9 +647,9 @@ discard block |
||
| 647 | 647 | // http://www.spip.net/@self |
| 648 | 648 | // http://doc.spip.org/@balise_SELF_dist |
| 649 | 649 | function balise_SELF_dist($p) { |
| 650 | - $p->code = 'self()'; |
|
| 651 | - $p->interdire_scripts = false; |
|
| 652 | - return $p; |
|
| 650 | + $p->code = 'self()'; |
|
| 651 | + $p->interdire_scripts = false; |
|
| 652 | + return $p; |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | // |
@@ -657,26 +657,26 @@ discard block |
||
| 657 | 657 | // |
| 658 | 658 | // http://doc.spip.org/@balise_CHEMIN_dist |
| 659 | 659 | function balise_CHEMIN_dist($p) { |
| 660 | - $arg = interprete_argument_balise(1,$p); |
|
| 661 | - if (!$arg) { |
|
| 662 | - $msg = array('zbug_balise_sans_argument', array('balise' => ' CHEMIN')); |
|
| 663 | - erreur_squelette($msg, $p); |
|
| 664 | - } else |
|
| 665 | - $p->code = 'find_in_path(' . $arg .')'; |
|
| 660 | + $arg = interprete_argument_balise(1,$p); |
|
| 661 | + if (!$arg) { |
|
| 662 | + $msg = array('zbug_balise_sans_argument', array('balise' => ' CHEMIN')); |
|
| 663 | + erreur_squelette($msg, $p); |
|
| 664 | + } else |
|
| 665 | + $p->code = 'find_in_path(' . $arg .')'; |
|
| 666 | 666 | |
| 667 | - #$p->interdire_scripts = true; |
|
| 668 | - return $p; |
|
| 667 | + #$p->interdire_scripts = true; |
|
| 668 | + return $p; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | function balise_CHEMIN_IMAGE_dist($p) { |
| 672 | - $arg = interprete_argument_balise(1,$p); |
|
| 673 | - if (!$arg) { |
|
| 674 | - $msg = array('zbug_balise_sans_argument', array('balise' => ' CHEMIN_IMAGE')); |
|
| 675 | - erreur_squelette($msg, $p); |
|
| 676 | - } else $p->code = 'chemin_image(' . $arg .')'; |
|
| 672 | + $arg = interprete_argument_balise(1,$p); |
|
| 673 | + if (!$arg) { |
|
| 674 | + $msg = array('zbug_balise_sans_argument', array('balise' => ' CHEMIN_IMAGE')); |
|
| 675 | + erreur_squelette($msg, $p); |
|
| 676 | + } else $p->code = 'chemin_image(' . $arg .')'; |
|
| 677 | 677 | |
| 678 | - #$p->interdire_scripts = true; |
|
| 679 | - return $p; |
|
| 678 | + #$p->interdire_scripts = true; |
|
| 679 | + return $p; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | |
@@ -718,35 +718,35 @@ discard block |
||
| 718 | 718 | **/ |
| 719 | 719 | function balise_ENV_dist($p, $src = NULL) { |
| 720 | 720 | |
| 721 | - // cle du tableau desiree |
|
| 722 | - $_nom = interprete_argument_balise(1,$p); |
|
| 723 | - // valeur par defaut |
|
| 724 | - $_sinon = interprete_argument_balise(2,$p); |
|
| 721 | + // cle du tableau desiree |
|
| 722 | + $_nom = interprete_argument_balise(1,$p); |
|
| 723 | + // valeur par defaut |
|
| 724 | + $_sinon = interprete_argument_balise(2,$p); |
|
| 725 | 725 | |
| 726 | - // $src est un tableau de donnees sources eventuellement transmis |
|
| 727 | - // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 726 | + // $src est un tableau de donnees sources eventuellement transmis |
|
| 727 | + // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 728 | 728 | |
| 729 | - if (!$_nom) { |
|
| 730 | - // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 731 | - // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 732 | - if ($src) { |
|
| 733 | - $p->code = '(is_array($a = ('.$src.')) ? serialize($a) : "")'; |
|
| 734 | - } else { |
|
| 735 | - $p->code = '@serialize($Pile[0])'; |
|
| 736 | - } |
|
| 737 | - } else { |
|
| 738 | - if (!$src) { |
|
| 739 | - $src = '@$Pile[0]'; |
|
| 740 | - } |
|
| 741 | - if ($_sinon) { |
|
| 742 | - $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 743 | - } else { |
|
| 744 | - $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - #$p->interdire_scripts = true; |
|
| 748 | - |
|
| 749 | - return $p; |
|
| 729 | + if (!$_nom) { |
|
| 730 | + // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 731 | + // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 732 | + if ($src) { |
|
| 733 | + $p->code = '(is_array($a = ('.$src.')) ? serialize($a) : "")'; |
|
| 734 | + } else { |
|
| 735 | + $p->code = '@serialize($Pile[0])'; |
|
| 736 | + } |
|
| 737 | + } else { |
|
| 738 | + if (!$src) { |
|
| 739 | + $src = '@$Pile[0]'; |
|
| 740 | + } |
|
| 741 | + if ($_sinon) { |
|
| 742 | + $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 743 | + } else { |
|
| 744 | + $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + #$p->interdire_scripts = true; |
|
| 748 | + |
|
| 749 | + return $p; |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** |
@@ -766,24 +766,24 @@ discard block |
||
| 766 | 766 | * @return Object |
| 767 | 767 | */ |
| 768 | 768 | function balise_CONFIG_dist($p) { |
| 769 | - if (!$arg = interprete_argument_balise(1,$p)) { |
|
| 770 | - $arg = "''"; |
|
| 771 | - } |
|
| 772 | - $_sinon = interprete_argument_balise(2,$p); |
|
| 773 | - $_unserialize = sinon(interprete_argument_balise(3,$p),"false"); |
|
| 769 | + if (!$arg = interprete_argument_balise(1,$p)) { |
|
| 770 | + $arg = "''"; |
|
| 771 | + } |
|
| 772 | + $_sinon = interprete_argument_balise(2,$p); |
|
| 773 | + $_unserialize = sinon(interprete_argument_balise(3,$p),"false"); |
|
| 774 | 774 | |
| 775 | - $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 776 | - ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 775 | + $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 776 | + ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 777 | 777 | |
| 778 | - return $p; |
|
| 778 | + return $p; |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
| 782 | 782 | // http://doc.spip.org/@balise_CONNECT_dist |
| 783 | 783 | function balise_CONNECT_dist($p) { |
| 784 | - $p->code = '($connect ? $connect : NULL)'; |
|
| 785 | - $p->interdire_scripts = false; |
|
| 786 | - return $p; |
|
| 784 | + $p->code = '($connect ? $connect : NULL)'; |
|
| 785 | + $p->interdire_scripts = false; |
|
| 786 | + return $p; |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | // |
@@ -794,14 +794,14 @@ discard block |
||
| 794 | 794 | // pas la meme session |
| 795 | 795 | // http://doc.spip.org/@balise_SESSION_dist |
| 796 | 796 | function balise_SESSION_dist($p) { |
| 797 | - $p->descr['session'] = true; |
|
| 797 | + $p->descr['session'] = true; |
|
| 798 | 798 | |
| 799 | - $f = function_exists('balise_ENV') |
|
| 800 | - ? 'balise_ENV' |
|
| 801 | - : 'balise_ENV_dist'; |
|
| 799 | + $f = function_exists('balise_ENV') |
|
| 800 | + ? 'balise_ENV' |
|
| 801 | + : 'balise_ENV_dist'; |
|
| 802 | 802 | |
| 803 | - $p = $f($p, '$GLOBALS["visiteur_session"]'); |
|
| 804 | - return $p; |
|
| 803 | + $p = $f($p, '$GLOBALS["visiteur_session"]'); |
|
| 804 | + return $p; |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | // |
@@ -809,16 +809,16 @@ discard block |
||
| 809 | 809 | // Ajoute x=y dans la session du visiteur |
| 810 | 810 | // http://doc.spip.org/@balise_SESSION_SET_dist |
| 811 | 811 | function balise_SESSION_SET_dist($p) { |
| 812 | - $_nom = interprete_argument_balise(1,$p); |
|
| 813 | - $_val = interprete_argument_balise(2,$p); |
|
| 814 | - if (!$_nom OR !$_val) { |
|
| 815 | - $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => 'SESSION_SET')); |
|
| 816 | - erreur_squelette($err_b_s_a, $p); |
|
| 817 | - } else $p->code = '(include_spip("inc/session") AND session_set('.$_nom.','.$_val.'))'; |
|
| 812 | + $_nom = interprete_argument_balise(1,$p); |
|
| 813 | + $_val = interprete_argument_balise(2,$p); |
|
| 814 | + if (!$_nom OR !$_val) { |
|
| 815 | + $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => 'SESSION_SET')); |
|
| 816 | + erreur_squelette($err_b_s_a, $p); |
|
| 817 | + } else $p->code = '(include_spip("inc/session") AND session_set('.$_nom.','.$_val.'))'; |
|
| 818 | 818 | |
| 819 | - $p->interdire_scripts = false; |
|
| 819 | + $p->interdire_scripts = false; |
|
| 820 | 820 | |
| 821 | - return $p; |
|
| 821 | + return $p; |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | |
@@ -836,23 +836,23 @@ discard block |
||
| 836 | 836 | // #EVAL{'str_replace("r","z", "roger")'} (attention les "'" sont interdits) |
| 837 | 837 | // http://doc.spip.org/@balise_EVAL_dist |
| 838 | 838 | function balise_EVAL_dist($p) { |
| 839 | - $php = interprete_argument_balise(1,$p); |
|
| 840 | - if ($php) { |
|
| 841 | - # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 842 | - # attention au commentaire "// x signes" qui precede |
|
| 843 | - if (preg_match(",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 844 | - $php,$r)) |
|
| 845 | - $p->code = /* $r[1]. */'('.$r[2].')'; |
|
| 846 | - else |
|
| 847 | - $p->code = "eval('return '.$php.';')"; |
|
| 848 | - } else { |
|
| 849 | - $msg = array('zbug_balise_sans_argument', array('balise' => ' EVAL')); |
|
| 850 | - erreur_squelette($msg, $p); |
|
| 851 | - } |
|
| 839 | + $php = interprete_argument_balise(1,$p); |
|
| 840 | + if ($php) { |
|
| 841 | + # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 842 | + # attention au commentaire "// x signes" qui precede |
|
| 843 | + if (preg_match(",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 844 | + $php,$r)) |
|
| 845 | + $p->code = /* $r[1]. */'('.$r[2].')'; |
|
| 846 | + else |
|
| 847 | + $p->code = "eval('return '.$php.';')"; |
|
| 848 | + } else { |
|
| 849 | + $msg = array('zbug_balise_sans_argument', array('balise' => ' EVAL')); |
|
| 850 | + erreur_squelette($msg, $p); |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | - #$p->interdire_scripts = true; |
|
| 853 | + #$p->interdire_scripts = true; |
|
| 854 | 854 | |
| 855 | - return $p; |
|
| 855 | + return $p; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | // #CHAMP_SQL{x} renvoie la valeur du champ sql 'x' |
@@ -862,27 +862,27 @@ discard block |
||
| 862 | 862 | // http://doc.spip.org/@balise_CHAMP_SQL_dist |
| 863 | 863 | function balise_CHAMP_SQL_dist($p){ |
| 864 | 864 | |
| 865 | - if ($p->param |
|
| 866 | - AND isset($p->param[0][1][0]) |
|
| 867 | - AND $champ = ($p->param[0][1][0]->texte)) |
|
| 868 | - $p->code = champ_sql($champ, $p); |
|
| 869 | - else { |
|
| 870 | - $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => ' CHAMP_SQL')); |
|
| 871 | - erreur_squelette($err_b_s_a, $p); |
|
| 872 | - } |
|
| 873 | - #$p->interdire_scripts = true; |
|
| 874 | - return $p; |
|
| 865 | + if ($p->param |
|
| 866 | + AND isset($p->param[0][1][0]) |
|
| 867 | + AND $champ = ($p->param[0][1][0]->texte)) |
|
| 868 | + $p->code = champ_sql($champ, $p); |
|
| 869 | + else { |
|
| 870 | + $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => ' CHAMP_SQL')); |
|
| 871 | + erreur_squelette($err_b_s_a, $p); |
|
| 872 | + } |
|
| 873 | + #$p->interdire_scripts = true; |
|
| 874 | + return $p; |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | // #VAL{x} renvoie 'x' (permet d'appliquer un filtre a une chaine) |
| 878 | 878 | // Attention #VAL{1,2} renvoie '1', indiquer #VAL{'1,2'} |
| 879 | 879 | // http://doc.spip.org/@balise_VAL_dist |
| 880 | 880 | function balise_VAL_dist($p){ |
| 881 | - $p->code = interprete_argument_balise(1,$p); |
|
| 882 | - if (!strlen($p->code)) |
|
| 883 | - $p->code = "''"; |
|
| 884 | - $p->interdire_scripts = false; |
|
| 885 | - return $p; |
|
| 881 | + $p->code = interprete_argument_balise(1,$p); |
|
| 882 | + if (!strlen($p->code)) |
|
| 883 | + $p->code = "''"; |
|
| 884 | + $p->interdire_scripts = false; |
|
| 885 | + return $p; |
|
| 886 | 886 | } |
| 887 | 887 | // #NOOP est un alias pour regler #948, ne pas documenter |
| 888 | 888 | // http://doc.spip.org/@balise_NOOP_dist |
@@ -894,9 +894,9 @@ discard block |
||
| 894 | 894 | // |
| 895 | 895 | // http://doc.spip.org/@balise_REM_dist |
| 896 | 896 | function balise_REM_dist($p) { |
| 897 | - $p->code="''"; |
|
| 898 | - $p->interdire_scripts = false; |
|
| 899 | - return $p; |
|
| 897 | + $p->code="''"; |
|
| 898 | + $p->interdire_scripts = false; |
|
| 899 | + return $p; |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | |
@@ -921,18 +921,18 @@ discard block |
||
| 921 | 921 | **/ |
| 922 | 922 | function balise_HTTP_HEADER_dist($p) { |
| 923 | 923 | |
| 924 | - $header = interprete_argument_balise(1, $p); |
|
| 925 | - if (!$header) { |
|
| 926 | - $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => 'HTTP_HEADER')); |
|
| 927 | - erreur_squelette($err_b_s_a, $p); |
|
| 928 | - } else { |
|
| 929 | - $p->code = "'<'.'?php header(' . _q(" |
|
| 930 | - . $header |
|
| 931 | - . ") . '); ?'.'>'"; |
|
| 932 | - } |
|
| 933 | - $p->interdire_scripts = false; |
|
| 924 | + $header = interprete_argument_balise(1, $p); |
|
| 925 | + if (!$header) { |
|
| 926 | + $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => 'HTTP_HEADER')); |
|
| 927 | + erreur_squelette($err_b_s_a, $p); |
|
| 928 | + } else { |
|
| 929 | + $p->code = "'<'.'?php header(' . _q(" |
|
| 930 | + . $header |
|
| 931 | + . ") . '); ?'.'>'"; |
|
| 932 | + } |
|
| 933 | + $p->interdire_scripts = false; |
|
| 934 | 934 | |
| 935 | - return $p; |
|
| 935 | + return $p; |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | |
@@ -941,18 +941,18 @@ discard block |
||
| 941 | 941 | // (filtrage fait au niveau du squelette, et sans s'appliquer aux <INCLURE>) |
| 942 | 942 | // http://doc.spip.org/@balise_FILTRE_dist |
| 943 | 943 | function balise_FILTRE_dist($p) { |
| 944 | - if ($p->param) { |
|
| 945 | - $args = array(); |
|
| 946 | - foreach ($p->param as $i => $ignore) |
|
| 947 | - $args[] = interprete_argument_balise($i+1,$p); |
|
| 948 | - $p->code = "'<' . '" |
|
| 949 | - .'?php header("X-Spip-Filtre: \'.' |
|
| 950 | - .join('.\'|\'.', $args) |
|
| 951 | - . " . '\"); ?'.'>'"; |
|
| 944 | + if ($p->param) { |
|
| 945 | + $args = array(); |
|
| 946 | + foreach ($p->param as $i => $ignore) |
|
| 947 | + $args[] = interprete_argument_balise($i+1,$p); |
|
| 948 | + $p->code = "'<' . '" |
|
| 949 | + .'?php header("X-Spip-Filtre: \'.' |
|
| 950 | + .join('.\'|\'.', $args) |
|
| 951 | + . " . '\"); ?'.'>'"; |
|
| 952 | 952 | |
| 953 | - $p->interdire_scripts = false; |
|
| 954 | - return $p; |
|
| 955 | - } |
|
| 953 | + $p->interdire_scripts = false; |
|
| 954 | + return $p; |
|
| 955 | + } |
|
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | // |
@@ -968,46 +968,46 @@ discard block |
||
| 968 | 968 | // http://doc.spip.org/@balise_CACHE_dist |
| 969 | 969 | function balise_CACHE_dist($p) { |
| 970 | 970 | |
| 971 | - if ($p->param) { |
|
| 972 | - $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 973 | - |
|
| 974 | - // noter la duree du cache dans un entete proprietaire |
|
| 975 | - |
|
| 976 | - $code = '\'<'.'?php header("X-Spip-Cache: ' |
|
| 977 | - . $duree |
|
| 978 | - . '"); ?'.'>\''; |
|
| 979 | - |
|
| 980 | - // Remplir le header Cache-Control |
|
| 981 | - // cas #CACHE{0} |
|
| 982 | - if ($duree == 0) |
|
| 983 | - $code .= '.\'<' |
|
| 984 | - .'?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 985 | - .'><' |
|
| 986 | - .'?php header("Pragma: no-cache"); ?' |
|
| 987 | - .'>\''; |
|
| 988 | - |
|
| 989 | - // recuperer les parametres suivants |
|
| 990 | - $i = 1; |
|
| 991 | - while (isset($p->param[0][++$i])) { |
|
| 992 | - $pa = ($p->param[0][$i][0]->texte); |
|
| 993 | - |
|
| 994 | - if ($pa == 'cache-client' |
|
| 995 | - AND $duree > 0) { |
|
| 996 | - $code .= '.\'<'.'?php header("Cache-Control: max-age=' |
|
| 997 | - . $duree |
|
| 998 | - . '"); ?'.'>\''; |
|
| 999 | - // il semble logique, si on cache-client, de ne pas invalider |
|
| 1000 | - $pa = 'statique'; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - if ($pa == 'statique' |
|
| 1004 | - AND $duree > 0) |
|
| 1005 | - $code .= '.\'<'.'?php header("X-Spip-Statique: oui"); ?'.'>\''; |
|
| 1006 | - } |
|
| 1007 | - } else $code = "''"; |
|
| 1008 | - $p->code = $code; |
|
| 1009 | - $p->interdire_scripts = false; |
|
| 1010 | - return $p; |
|
| 971 | + if ($p->param) { |
|
| 972 | + $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 973 | + |
|
| 974 | + // noter la duree du cache dans un entete proprietaire |
|
| 975 | + |
|
| 976 | + $code = '\'<'.'?php header("X-Spip-Cache: ' |
|
| 977 | + . $duree |
|
| 978 | + . '"); ?'.'>\''; |
|
| 979 | + |
|
| 980 | + // Remplir le header Cache-Control |
|
| 981 | + // cas #CACHE{0} |
|
| 982 | + if ($duree == 0) |
|
| 983 | + $code .= '.\'<' |
|
| 984 | + .'?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 985 | + .'><' |
|
| 986 | + .'?php header("Pragma: no-cache"); ?' |
|
| 987 | + .'>\''; |
|
| 988 | + |
|
| 989 | + // recuperer les parametres suivants |
|
| 990 | + $i = 1; |
|
| 991 | + while (isset($p->param[0][++$i])) { |
|
| 992 | + $pa = ($p->param[0][$i][0]->texte); |
|
| 993 | + |
|
| 994 | + if ($pa == 'cache-client' |
|
| 995 | + AND $duree > 0) { |
|
| 996 | + $code .= '.\'<'.'?php header("Cache-Control: max-age=' |
|
| 997 | + . $duree |
|
| 998 | + . '"); ?'.'>\''; |
|
| 999 | + // il semble logique, si on cache-client, de ne pas invalider |
|
| 1000 | + $pa = 'statique'; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + if ($pa == 'statique' |
|
| 1004 | + AND $duree > 0) |
|
| 1005 | + $code .= '.\'<'.'?php header("X-Spip-Statique: oui"); ?'.'>\''; |
|
| 1006 | + } |
|
| 1007 | + } else $code = "''"; |
|
| 1008 | + $p->code = $code; |
|
| 1009 | + $p->interdire_scripts = false; |
|
| 1010 | + return $p; |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | |
@@ -1030,13 +1030,13 @@ discard block |
||
| 1030 | 1030 | * @return object |
| 1031 | 1031 | */ |
| 1032 | 1032 | function balise_INSERT_HEAD_dist($p) { |
| 1033 | - $p->code = '\'<' |
|
| 1034 | - .'?php header("X-Spip-Filtre: \'.' |
|
| 1035 | - .'\'insert_head_css_conditionnel\'' |
|
| 1036 | - . " . '\"); ?'.'>'"; |
|
| 1037 | - $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1038 | - $p->interdire_scripts = false; |
|
| 1039 | - return $p; |
|
| 1033 | + $p->code = '\'<' |
|
| 1034 | + .'?php header("X-Spip-Filtre: \'.' |
|
| 1035 | + .'\'insert_head_css_conditionnel\'' |
|
| 1036 | + . " . '\"); ?'.'>'"; |
|
| 1037 | + $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1038 | + $p->interdire_scripts = false; |
|
| 1039 | + return $p; |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /** |
@@ -1049,9 +1049,9 @@ discard block |
||
| 1049 | 1049 | * @return object |
| 1050 | 1050 | */ |
| 1051 | 1051 | function balise_INSERT_HEAD_CSS_dist($p) { |
| 1052 | - $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1053 | - $p->interdire_scripts = false; |
|
| 1054 | - return $p; |
|
| 1052 | + $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1053 | + $p->interdire_scripts = false; |
|
| 1054 | + return $p; |
|
| 1055 | 1055 | } |
| 1056 | 1056 | // |
| 1057 | 1057 | // #INCLURE statique |
@@ -1061,119 +1061,119 @@ discard block |
||
| 1061 | 1061 | // (Incompatible avec les balises dynamiques) |
| 1062 | 1062 | // http://doc.spip.org/@balise_INCLUDE_dist |
| 1063 | 1063 | function balise_INCLUDE_dist($p) { |
| 1064 | - if(function_exists('balise_INCLURE')) |
|
| 1065 | - return balise_INCLURE($p); |
|
| 1066 | - else |
|
| 1067 | - return balise_INCLURE_dist($p); |
|
| 1064 | + if(function_exists('balise_INCLURE')) |
|
| 1065 | + return balise_INCLURE($p); |
|
| 1066 | + else |
|
| 1067 | + return balise_INCLURE_dist($p); |
|
| 1068 | 1068 | } |
| 1069 | 1069 | // http://doc.spip.org/@balise_INCLURE_dist |
| 1070 | 1070 | function balise_INCLURE_dist($p) { |
| 1071 | - $id_boucle = $p->id_boucle; |
|
| 1072 | - // la lang n'est pas passe de facon automatique par argumenter |
|
| 1073 | - // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1074 | - // en option |
|
| 1071 | + $id_boucle = $p->id_boucle; |
|
| 1072 | + // la lang n'est pas passe de facon automatique par argumenter |
|
| 1073 | + // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1074 | + // en option |
|
| 1075 | 1075 | |
| 1076 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1076 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1077 | 1077 | |
| 1078 | - // erreur de syntaxe = fond absent |
|
| 1079 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1080 | - if (!$_contexte) $contexte = array(); |
|
| 1078 | + // erreur de syntaxe = fond absent |
|
| 1079 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1080 | + if (!$_contexte) $contexte = array(); |
|
| 1081 | 1081 | |
| 1082 | - if (isset($_contexte['fond'])) { |
|
| 1082 | + if (isset($_contexte['fond'])) { |
|
| 1083 | 1083 | |
| 1084 | - $f = $_contexte['fond']; |
|
| 1085 | - // toujours vrai : |
|
| 1086 | - if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1087 | - $f = $r[1]; |
|
| 1088 | - unset($_contexte['fond']); |
|
| 1089 | - } else spip_log("compilation de #INCLURE a revoir"); |
|
| 1084 | + $f = $_contexte['fond']; |
|
| 1085 | + // toujours vrai : |
|
| 1086 | + if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1087 | + $f = $r[1]; |
|
| 1088 | + unset($_contexte['fond']); |
|
| 1089 | + } else spip_log("compilation de #INCLURE a revoir"); |
|
| 1090 | 1090 | |
| 1091 | - // #INCLURE{doublons} |
|
| 1092 | - if (isset($_contexte['doublons'])) { |
|
| 1093 | - $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 1094 | - } |
|
| 1091 | + // #INCLURE{doublons} |
|
| 1092 | + if (isset($_contexte['doublons'])) { |
|
| 1093 | + $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 1094 | + } |
|
| 1095 | 1095 | |
| 1096 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 1097 | - if (isset($_contexte['env']) |
|
| 1098 | - || isset($_contexte['self']) |
|
| 1099 | - ) { |
|
| 1100 | - $flag_env = true; |
|
| 1101 | - unset($_contexte['env']); |
|
| 1102 | - } else $flag_env = false; |
|
| 1096 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 1097 | + if (isset($_contexte['env']) |
|
| 1098 | + || isset($_contexte['self']) |
|
| 1099 | + ) { |
|
| 1100 | + $flag_env = true; |
|
| 1101 | + unset($_contexte['env']); |
|
| 1102 | + } else $flag_env = false; |
|
| 1103 | 1103 | |
| 1104 | - $_options = array(); |
|
| 1105 | - if (isset($_contexte['ajax'])) { |
|
| 1106 | - $_options[] = preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 1107 | - unset($_contexte['ajax']); |
|
| 1108 | - } |
|
| 1109 | - if ($p->etoile) $_options[] = "'etoile'=>true"; |
|
| 1110 | - $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) .")"; |
|
| 1104 | + $_options = array(); |
|
| 1105 | + if (isset($_contexte['ajax'])) { |
|
| 1106 | + $_options[] = preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 1107 | + unset($_contexte['ajax']); |
|
| 1108 | + } |
|
| 1109 | + if ($p->etoile) $_options[] = "'etoile'=>true"; |
|
| 1110 | + $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) .")"; |
|
| 1111 | 1111 | |
| 1112 | - $_l = 'array(' . join(",\n\t", $_contexte) .')'; |
|
| 1113 | - if ($flag_env) $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 1112 | + $_l = 'array(' . join(",\n\t", $_contexte) .')'; |
|
| 1113 | + if ($flag_env) $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 1114 | 1114 | |
| 1115 | - $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',',$_options),"''"); |
|
| 1115 | + $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',',$_options),"''"); |
|
| 1116 | 1116 | |
| 1117 | - } elseif (!isset($_contexte[1])) { |
|
| 1118 | - $msg = array('zbug_balise_sans_argument', array('balise' => ' INCLURE')); |
|
| 1119 | - erreur_squelette($msg, $p); |
|
| 1120 | - } else $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 1117 | + } elseif (!isset($_contexte[1])) { |
|
| 1118 | + $msg = array('zbug_balise_sans_argument', array('balise' => ' INCLURE')); |
|
| 1119 | + erreur_squelette($msg, $p); |
|
| 1120 | + } else $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 1121 | 1121 | |
| 1122 | - $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 1123 | - return $p; |
|
| 1122 | + $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 1123 | + return $p; |
|
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | // Inclure un modele : #MODELE{modele, params} |
| 1127 | 1127 | // http://doc.spip.org/@balise_MODELE_dist |
| 1128 | 1128 | function balise_MODELE_dist($p) { |
| 1129 | 1129 | |
| 1130 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 1130 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 1131 | 1131 | |
| 1132 | - // erreur de syntaxe = fond absent |
|
| 1133 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1134 | - if (!$_contexte) $contexte = array(); |
|
| 1132 | + // erreur de syntaxe = fond absent |
|
| 1133 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1134 | + if (!$_contexte) $contexte = array(); |
|
| 1135 | 1135 | |
| 1136 | - if (!isset($_contexte[1])) { |
|
| 1137 | - $msg = array('zbug_balise_sans_argument', array('balise' => ' MODELE')); |
|
| 1138 | - erreur_squelette($msg, $p); |
|
| 1139 | - } else { |
|
| 1140 | - $nom = $_contexte[1]; |
|
| 1141 | - unset($_contexte[1]); |
|
| 1136 | + if (!isset($_contexte[1])) { |
|
| 1137 | + $msg = array('zbug_balise_sans_argument', array('balise' => ' MODELE')); |
|
| 1138 | + erreur_squelette($msg, $p); |
|
| 1139 | + } else { |
|
| 1140 | + $nom = $_contexte[1]; |
|
| 1141 | + unset($_contexte[1]); |
|
| 1142 | 1142 | |
| 1143 | - if (preg_match("/^\s*'[^']*'/s", $nom)) |
|
| 1144 | - $nom = "'modeles/" . substr($nom,1); |
|
| 1145 | - else $nom = "'modeles/' . $nom"; |
|
| 1143 | + if (preg_match("/^\s*'[^']*'/s", $nom)) |
|
| 1144 | + $nom = "'modeles/" . substr($nom,1); |
|
| 1145 | + else $nom = "'modeles/' . $nom"; |
|
| 1146 | 1146 | |
| 1147 | - // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 1148 | - // Reserver la cle primaire de la boucle courante si elle existe |
|
| 1149 | - if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 1150 | - $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 1151 | - if (!strpos($primary,',')) { |
|
| 1152 | - $id = champ_sql($primary, $p); |
|
| 1153 | - $_contexte[] = "'$primary'=>".$id; |
|
| 1154 | - $_contexte[] = "'id'=>".$id; |
|
| 1155 | - } |
|
| 1156 | - } |
|
| 1157 | - $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 1158 | - $connect = ''; |
|
| 1159 | - if (isset($p->boucles[$p->id_boucle])) |
|
| 1160 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 1147 | + // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 1148 | + // Reserver la cle primaire de la boucle courante si elle existe |
|
| 1149 | + if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 1150 | + $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 1151 | + if (!strpos($primary,',')) { |
|
| 1152 | + $id = champ_sql($primary, $p); |
|
| 1153 | + $_contexte[] = "'$primary'=>".$id; |
|
| 1154 | + $_contexte[] = "'id'=>".$id; |
|
| 1155 | + } |
|
| 1156 | + } |
|
| 1157 | + $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 1158 | + $connect = ''; |
|
| 1159 | + if (isset($p->boucles[$p->id_boucle])) |
|
| 1160 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 1161 | 1161 | |
| 1162 | - $_options = memoriser_contexte_compil($p); |
|
| 1163 | - $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 1164 | - if (isset($_contexte['ajax'])){ |
|
| 1165 | - $_options .= ", ".preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 1166 | - unset($_contexte['ajax']); |
|
| 1167 | - } |
|
| 1162 | + $_options = memoriser_contexte_compil($p); |
|
| 1163 | + $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 1164 | + if (isset($_contexte['ajax'])){ |
|
| 1165 | + $_options .= ", ".preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 1166 | + unset($_contexte['ajax']); |
|
| 1167 | + } |
|
| 1168 | 1168 | |
| 1169 | - $page = sprintf(CODE_RECUPERER_FOND, $nom, 'array(' . join(',', $_contexte) .')', $_options, _q($connect)); |
|
| 1169 | + $page = sprintf(CODE_RECUPERER_FOND, $nom, 'array(' . join(',', $_contexte) .')', $_options, _q($connect)); |
|
| 1170 | 1170 | |
| 1171 | - $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 1171 | + $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 1172 | 1172 | |
| 1173 | - $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 1174 | - } |
|
| 1173 | + $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 1174 | + } |
|
| 1175 | 1175 | |
| 1176 | - return $p; |
|
| 1176 | + return $p; |
|
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | 1179 | // |
@@ -1183,19 +1183,19 @@ discard block |
||
| 1183 | 1183 | // la balise renvoie la valeur |
| 1184 | 1184 | // http://doc.spip.org/@balise_SET_dist |
| 1185 | 1185 | function balise_SET_dist($p){ |
| 1186 | - $_nom = interprete_argument_balise(1,$p); |
|
| 1187 | - $_val = interprete_argument_balise(2,$p); |
|
| 1186 | + $_nom = interprete_argument_balise(1,$p); |
|
| 1187 | + $_val = interprete_argument_balise(2,$p); |
|
| 1188 | 1188 | |
| 1189 | - if (!$_nom OR !$_val) { |
|
| 1190 | - $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => 'SET')); |
|
| 1191 | - erreur_squelette($err_b_s_a, $p); |
|
| 1192 | - } |
|
| 1193 | - // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 1194 | - // cf https://bugs.php.net/bug.php?id=65845 |
|
| 1195 | - else $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 1189 | + if (!$_nom OR !$_val) { |
|
| 1190 | + $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => 'SET')); |
|
| 1191 | + erreur_squelette($err_b_s_a, $p); |
|
| 1192 | + } |
|
| 1193 | + // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 1194 | + // cf https://bugs.php.net/bug.php?id=65845 |
|
| 1195 | + else $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 1196 | 1196 | |
| 1197 | - $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 1198 | - return $p; |
|
| 1197 | + $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 1198 | + return $p; |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | // |
@@ -1205,11 +1205,11 @@ discard block |
||
| 1205 | 1205 | // |
| 1206 | 1206 | // http://doc.spip.org/@balise_GET_dist |
| 1207 | 1207 | function balise_GET_dist($p) { |
| 1208 | - $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 1209 | - if (function_exists('balise_ENV')) |
|
| 1210 | - return balise_ENV($p, '$Pile["vars"]'); |
|
| 1211 | - else |
|
| 1212 | - return balise_ENV_dist($p, '$Pile["vars"]'); |
|
| 1208 | + $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 1209 | + if (function_exists('balise_ENV')) |
|
| 1210 | + return balise_ENV($p, '$Pile["vars"]'); |
|
| 1211 | + else |
|
| 1212 | + return balise_ENV_dist($p, '$Pile["vars"]'); |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | |
@@ -1229,20 +1229,20 @@ discard block |
||
| 1229 | 1229 | * Pile complétée par le code à générer |
| 1230 | 1230 | **/ |
| 1231 | 1231 | function balise_DOUBLONS_dist($p) { |
| 1232 | - if ($type = interprete_argument_balise(1,$p)) { |
|
| 1233 | - if ($famille = interprete_argument_balise(2,$p)) |
|
| 1234 | - $type .= '.' . $famille; |
|
| 1235 | - $p->code = '$doublons['.$type.']'; |
|
| 1236 | - if (!$p->etoile) |
|
| 1237 | - $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 1238 | - . $p->code . ')))'; |
|
| 1239 | - } |
|
| 1240 | - else |
|
| 1241 | - $p->code = '$doublons'; |
|
| 1232 | + if ($type = interprete_argument_balise(1,$p)) { |
|
| 1233 | + if ($famille = interprete_argument_balise(2,$p)) |
|
| 1234 | + $type .= '.' . $famille; |
|
| 1235 | + $p->code = '$doublons['.$type.']'; |
|
| 1236 | + if (!$p->etoile) |
|
| 1237 | + $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 1238 | + . $p->code . ')))'; |
|
| 1239 | + } |
|
| 1240 | + else |
|
| 1241 | + $p->code = '$doublons'; |
|
| 1242 | 1242 | |
| 1243 | - $p->interdire_scripts = false; |
|
| 1243 | + $p->interdire_scripts = false; |
|
| 1244 | 1244 | |
| 1245 | - return $p; |
|
| 1245 | + return $p; |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | |
@@ -1254,17 +1254,17 @@ discard block |
||
| 1254 | 1254 | // |
| 1255 | 1255 | // http://doc.spip.org/@balise_PIPELINE_dist |
| 1256 | 1256 | function balise_PIPELINE_dist($p) { |
| 1257 | - $_pipe = interprete_argument_balise(1,$p); |
|
| 1258 | - if (!$_pipe) { |
|
| 1259 | - $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => 'PIPELINE')); |
|
| 1260 | - erreur_squelette($err_b_s_a, $p); |
|
| 1261 | - } else { |
|
| 1262 | - $_flux = interprete_argument_balise(2,$p); |
|
| 1263 | - $_flux = $_flux?$_flux:"''"; |
|
| 1264 | - $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 1265 | - $p->interdire_scripts = false; |
|
| 1266 | - } |
|
| 1267 | - return $p; |
|
| 1257 | + $_pipe = interprete_argument_balise(1,$p); |
|
| 1258 | + if (!$_pipe) { |
|
| 1259 | + $err_b_s_a = array('zbug_balise_sans_argument', array('balise' => 'PIPELINE')); |
|
| 1260 | + erreur_squelette($err_b_s_a, $p); |
|
| 1261 | + } else { |
|
| 1262 | + $_flux = interprete_argument_balise(2,$p); |
|
| 1263 | + $_flux = $_flux?$_flux:"''"; |
|
| 1264 | + $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 1265 | + $p->interdire_scripts = false; |
|
| 1266 | + } |
|
| 1267 | + return $p; |
|
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | // |
@@ -1273,9 +1273,9 @@ discard block |
||
| 1273 | 1273 | // |
| 1274 | 1274 | // http://doc.spip.org/@balise_EDIT_dist |
| 1275 | 1275 | function balise_EDIT_dist($p) { |
| 1276 | - $p->code = "''"; |
|
| 1277 | - $p->interdire_scripts = false; |
|
| 1278 | - return $p; |
|
| 1276 | + $p->code = "''"; |
|
| 1277 | + $p->interdire_scripts = false; |
|
| 1278 | + return $p; |
|
| 1279 | 1279 | } |
| 1280 | 1280 | |
| 1281 | 1281 | |
@@ -1289,10 +1289,10 @@ discard block |
||
| 1289 | 1289 | // |
| 1290 | 1290 | // http://doc.spip.org/@balise_TOTAL_UNIQUE_dist |
| 1291 | 1291 | function balise_TOTAL_UNIQUE_dist($p) { |
| 1292 | - $_famille = interprete_argument_balise(1,$p); |
|
| 1293 | - $_famille = $_famille ? $_famille : "''"; |
|
| 1294 | - $p->code = "unique('', $_famille, true)"; |
|
| 1295 | - return $p; |
|
| 1292 | + $_famille = interprete_argument_balise(1,$p); |
|
| 1293 | + $_famille = $_famille ? $_famille : "''"; |
|
| 1294 | + $p->code = "unique('', $_famille, true)"; |
|
| 1295 | + return $p; |
|
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | // |
@@ -1302,16 +1302,16 @@ discard block |
||
| 1302 | 1302 | // |
| 1303 | 1303 | // http://doc.spip.org/@balise_ARRAY_dist |
| 1304 | 1304 | function balise_ARRAY_dist($p) { |
| 1305 | - $_code = array(); |
|
| 1306 | - $n=1; |
|
| 1307 | - do { |
|
| 1308 | - $_key = interprete_argument_balise($n++,$p); |
|
| 1309 | - $_val = interprete_argument_balise($n++,$p); |
|
| 1310 | - if ($_key AND $_val) $_code[] = "$_key => $_val"; |
|
| 1311 | - } while ($_key && $_val); |
|
| 1312 | - $p->code = 'array(' . join(', ',$_code).')'; |
|
| 1313 | - $p->interdire_scripts = false; |
|
| 1314 | - return $p; |
|
| 1305 | + $_code = array(); |
|
| 1306 | + $n=1; |
|
| 1307 | + do { |
|
| 1308 | + $_key = interprete_argument_balise($n++,$p); |
|
| 1309 | + $_val = interprete_argument_balise($n++,$p); |
|
| 1310 | + if ($_key AND $_val) $_code[] = "$_key => $_val"; |
|
| 1311 | + } while ($_key && $_val); |
|
| 1312 | + $p->code = 'array(' . join(', ',$_code).')'; |
|
| 1313 | + $p->interdire_scripts = false; |
|
| 1314 | + return $p; |
|
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | 1317 | /** |
@@ -1321,13 +1321,13 @@ discard block |
||
| 1321 | 1321 | * @return <type> |
| 1322 | 1322 | */ |
| 1323 | 1323 | function balise_LISTE_dist($p) { |
| 1324 | - $_code = array(); |
|
| 1325 | - $n=1; |
|
| 1326 | - while ($_val = interprete_argument_balise($n++,$p)) |
|
| 1327 | - $_code[] = $_val; |
|
| 1328 | - $p->code = 'array(' . join(', ',$_code).')'; |
|
| 1329 | - $p->interdire_scripts = false; |
|
| 1330 | - return $p; |
|
| 1324 | + $_code = array(); |
|
| 1325 | + $n=1; |
|
| 1326 | + while ($_val = interprete_argument_balise($n++,$p)) |
|
| 1327 | + $_code[] = $_val; |
|
| 1328 | + $p->code = 'array(' . join(', ',$_code).')'; |
|
| 1329 | + $p->interdire_scripts = false; |
|
| 1330 | + return $p; |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | // Appelle la fonction autoriser et renvoie ' ' si OK, '' si niet |
@@ -1335,54 +1335,54 @@ discard block |
||
| 1335 | 1335 | // Cette balise cree un cache par session |
| 1336 | 1336 | // http://doc.spip.org/@balise_AUTORISER_dist |
| 1337 | 1337 | function balise_AUTORISER_dist($p) { |
| 1338 | - $_code = array(); |
|
| 1339 | - $p->descr['session'] = true; // faire un cache par session |
|
| 1338 | + $_code = array(); |
|
| 1339 | + $p->descr['session'] = true; // faire un cache par session |
|
| 1340 | 1340 | |
| 1341 | - $n=1; |
|
| 1342 | - while ($_v = interprete_argument_balise($n++,$p)) |
|
| 1343 | - $_code[] = $_v; |
|
| 1341 | + $n=1; |
|
| 1342 | + while ($_v = interprete_argument_balise($n++,$p)) |
|
| 1343 | + $_code[] = $_v; |
|
| 1344 | 1344 | |
| 1345 | - $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join(', ',$_code).')?" ":"")'; |
|
| 1346 | - $p->interdire_scripts = false; |
|
| 1347 | - return $p; |
|
| 1345 | + $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join(', ',$_code).')?" ":"")'; |
|
| 1346 | + $p->interdire_scripts = false; |
|
| 1347 | + return $p; |
|
| 1348 | 1348 | } |
| 1349 | 1349 | |
| 1350 | 1350 | // Appelle la fonction info_plugin |
| 1351 | 1351 | // Afficher des informations sur les plugins dans le site public |
| 1352 | 1352 | // http://doc.spip.org/@balise_PLUGIN_dist |
| 1353 | 1353 | function balise_PLUGIN_dist($p) { |
| 1354 | - $plugin = interprete_argument_balise(1,$p); |
|
| 1355 | - $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 1356 | - $type_info = interprete_argument_balise(2,$p); |
|
| 1357 | - $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 1354 | + $plugin = interprete_argument_balise(1,$p); |
|
| 1355 | + $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 1356 | + $type_info = interprete_argument_balise(2,$p); |
|
| 1357 | + $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 1358 | 1358 | |
| 1359 | - $f = chercher_filtre('info_plugin'); |
|
| 1360 | - $p->code = $f.'('.$plugin.', '.$type_info.')'; |
|
| 1361 | - return $p; |
|
| 1359 | + $f = chercher_filtre('info_plugin'); |
|
| 1360 | + $p->code = $f.'('.$plugin.', '.$type_info.')'; |
|
| 1361 | + return $p; |
|
| 1362 | 1362 | } |
| 1363 | 1363 | |
| 1364 | 1364 | // Appelle la fonction inc_aider_dist |
| 1365 | 1365 | // http://doc.spip.org/@balise_AIDER_dist |
| 1366 | 1366 | function balise_AIDER_dist($p) { |
| 1367 | - $_motif = interprete_argument_balise(1,$p); |
|
| 1368 | - $s = "'" . addslashes($p->descr['sourcefile']) . "'"; |
|
| 1369 | - $aider = charger_fonction('aider','inc'); |
|
| 1370 | - $p->code = "((\$aider=charger_fonction('aider','inc'))?\$aider($_motif,$s, \$Pile[0]):'')"; |
|
| 1371 | - return $p; |
|
| 1367 | + $_motif = interprete_argument_balise(1,$p); |
|
| 1368 | + $s = "'" . addslashes($p->descr['sourcefile']) . "'"; |
|
| 1369 | + $aider = charger_fonction('aider','inc'); |
|
| 1370 | + $p->code = "((\$aider=charger_fonction('aider','inc'))?\$aider($_motif,$s, \$Pile[0]):'')"; |
|
| 1371 | + return $p; |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | // Insertion du contexte des formulaires charger/verifier/traiter |
| 1375 | 1375 | // avec les hidden de l'url d'action |
| 1376 | 1376 | // http://doc.spip.org/@balise_ACTION_FORMULAIRE |
| 1377 | 1377 | function balise_ACTION_FORMULAIRE($p){ |
| 1378 | - if (!$_url = interprete_argument_balise(1,$p)) |
|
| 1379 | - $_url = "@\$Pile[0]['action']"; |
|
| 1380 | - if (!$_form = interprete_argument_balise(2,$p)) |
|
| 1381 | - $_form = "@\$Pile[0]['form']"; |
|
| 1382 | - |
|
| 1383 | - // envoyer le nom du formulaire que l'on traite |
|
| 1384 | - // transmettre les eventuels args de la balise formulaire |
|
| 1385 | - $p->code = " '<div>' . |
|
| 1378 | + if (!$_url = interprete_argument_balise(1,$p)) |
|
| 1379 | + $_url = "@\$Pile[0]['action']"; |
|
| 1380 | + if (!$_form = interprete_argument_balise(2,$p)) |
|
| 1381 | + $_form = "@\$Pile[0]['form']"; |
|
| 1382 | + |
|
| 1383 | + // envoyer le nom du formulaire que l'on traite |
|
| 1384 | + // transmettre les eventuels args de la balise formulaire |
|
| 1385 | + $p->code = " '<div>' . |
|
| 1386 | 1386 | form_hidden($_url) . |
| 1387 | 1387 | '<input name=\'formulaire_action\' type=\'hidden\' |
| 1388 | 1388 | value=\'' . $_form . '\' />' . |
@@ -1391,8 +1391,8 @@ discard block |
||
| 1391 | 1391 | (@\$Pile[0]['_hidden']?@\$Pile[0]['_hidden']:'') . |
| 1392 | 1392 | '</div>'"; |
| 1393 | 1393 | |
| 1394 | - $p->interdire_scripts = false; |
|
| 1395 | - return $p; |
|
| 1394 | + $p->interdire_scripts = false; |
|
| 1395 | + return $p; |
|
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | 1398 | |
@@ -1412,29 +1412,29 @@ discard block |
||
| 1412 | 1412 | */ |
| 1413 | 1413 | function balise_BOUTON_ACTION_dist($p){ |
| 1414 | 1414 | |
| 1415 | - $args = array(); |
|
| 1416 | - for ($k=1;$k<=6;$k++){ |
|
| 1417 | - $_a = interprete_argument_balise($k,$p); |
|
| 1418 | - if (!$_a) $_a="''"; |
|
| 1419 | - $args[] = $_a; |
|
| 1420 | - } |
|
| 1421 | - // supprimer les args vides |
|
| 1422 | - while(end($args)=="''" AND count($args)>2) |
|
| 1423 | - array_pop($args); |
|
| 1424 | - $args = implode(",",$args); |
|
| 1415 | + $args = array(); |
|
| 1416 | + for ($k=1;$k<=6;$k++){ |
|
| 1417 | + $_a = interprete_argument_balise($k,$p); |
|
| 1418 | + if (!$_a) $_a="''"; |
|
| 1419 | + $args[] = $_a; |
|
| 1420 | + } |
|
| 1421 | + // supprimer les args vides |
|
| 1422 | + while(end($args)=="''" AND count($args)>2) |
|
| 1423 | + array_pop($args); |
|
| 1424 | + $args = implode(",",$args); |
|
| 1425 | 1425 | |
| 1426 | - $bouton_action = chercher_filtre("bouton_action"); |
|
| 1427 | - $p->code = "$bouton_action($args)"; |
|
| 1428 | - $p->interdire_scripts = false; |
|
| 1429 | - return $p; |
|
| 1426 | + $bouton_action = chercher_filtre("bouton_action"); |
|
| 1427 | + $p->code = "$bouton_action($args)"; |
|
| 1428 | + $p->interdire_scripts = false; |
|
| 1429 | + return $p; |
|
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | |
| 1433 | 1433 | |
| 1434 | 1434 | function balise_SLOGAN_SITE_SPIP_dist($p) { |
| 1435 | - $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 1436 | - #$p->interdire_scripts = true; |
|
| 1437 | - return $p; |
|
| 1435 | + $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 1436 | + #$p->interdire_scripts = true; |
|
| 1437 | + return $p; |
|
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | 1440 | // #HTML5 |
@@ -1442,9 +1442,9 @@ discard block |
||
| 1442 | 1442 | // le site public, et '' si le code doit etre strictement compatible HTML4 |
| 1443 | 1443 | // http://doc.spip.org/@balise_HTML5_dist |
| 1444 | 1444 | function balise_HTML5_dist($p) { |
| 1445 | - $p->code = html5_permis() ? "' '" : "''"; |
|
| 1446 | - $p->interdire_scripts = false; |
|
| 1447 | - return $p; |
|
| 1445 | + $p->code = html5_permis() ? "' '" : "''"; |
|
| 1446 | + $p->interdire_scripts = false; |
|
| 1447 | + return $p; |
|
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | |
@@ -1459,58 +1459,58 @@ discard block |
||
| 1459 | 1459 | * @return unknown |
| 1460 | 1460 | */ |
| 1461 | 1461 | function balise_TRI_dist($p, $liste='true') { |
| 1462 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 1463 | - |
|
| 1464 | - // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 1465 | - if ($b === '') { |
|
| 1466 | - erreur_squelette( |
|
| 1467 | - _T('zbug_champ_hors_boucle', |
|
| 1468 | - array('champ' => '#TRI') |
|
| 1469 | - ), $p->id_boucle); |
|
| 1470 | - $p->code = "''"; |
|
| 1471 | - return $p; |
|
| 1472 | - } |
|
| 1473 | - $boucle = $p->boucles[$b]; |
|
| 1474 | - |
|
| 1475 | - // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 1476 | - // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 1477 | - if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 1478 | - erreur_squelette( |
|
| 1479 | - _T('zbug_tri_sans_critere', |
|
| 1480 | - array('champ' => '#TRI') |
|
| 1481 | - ), $p->id_boucle); |
|
| 1482 | - $p->code = "''"; |
|
| 1483 | - return $p; |
|
| 1484 | - } |
|
| 1485 | - |
|
| 1486 | - $_champ = interprete_argument_balise(1,$p); |
|
| 1487 | - // si pas de champ, renvoyer le critere de tri utilise |
|
| 1488 | - if (!$_champ){ |
|
| 1489 | - $p->code = $boucle->modificateur['tri_champ']; |
|
| 1490 | - return $p; |
|
| 1491 | - } |
|
| 1492 | - // forcer la jointure si besoin, et si le champ est statique |
|
| 1493 | - if (preg_match(",^'([\w.]+)'$,i",$_champ,$m)){ |
|
| 1494 | - index_pile($b, $m[1], $p->boucles); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - $_libelle = interprete_argument_balise(2,$p); |
|
| 1498 | - $_libelle = $_libelle?$_libelle:$_champ; |
|
| 1499 | - |
|
| 1500 | - $_class = interprete_argument_balise(3,$p); |
|
| 1501 | - // si champ = ">" c'est un lien vers le tri croissant : de gauche a droite ==> 1 |
|
| 1502 | - // si champ = "<" c'est un lien vers le tri decroissant : (sens inverse) == -1 |
|
| 1503 | - $_issens = "in_array($_champ,array('>','<'))"; |
|
| 1504 | - $_sens = "(strpos('< >',$_champ)-1)"; |
|
| 1505 | - |
|
| 1506 | - $_variable = "((\$s=$_issens)?'sens':'tri').".$boucle->modificateur['tri_nom']; |
|
| 1507 | - $_url = "parametre_url(self(),$_variable,\$s?$_sens:$_champ)"; |
|
| 1508 | - $_on = "\$s?(".$boucle->modificateur['tri_sens']."==$_sens".'):('.$boucle->modificateur['tri_champ']."==$_champ)"; |
|
| 1509 | - |
|
| 1510 | - $p->code = "lien_ou_expose($_url,$_libelle,$_on".($_class?",$_class":"").")"; |
|
| 1511 | - //$p->code = "''"; |
|
| 1512 | - $p->interdire_scripts = false; |
|
| 1513 | - return $p; |
|
| 1462 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
|
| 1463 | + |
|
| 1464 | + // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 1465 | + if ($b === '') { |
|
| 1466 | + erreur_squelette( |
|
| 1467 | + _T('zbug_champ_hors_boucle', |
|
| 1468 | + array('champ' => '#TRI') |
|
| 1469 | + ), $p->id_boucle); |
|
| 1470 | + $p->code = "''"; |
|
| 1471 | + return $p; |
|
| 1472 | + } |
|
| 1473 | + $boucle = $p->boucles[$b]; |
|
| 1474 | + |
|
| 1475 | + // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 1476 | + // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 1477 | + if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 1478 | + erreur_squelette( |
|
| 1479 | + _T('zbug_tri_sans_critere', |
|
| 1480 | + array('champ' => '#TRI') |
|
| 1481 | + ), $p->id_boucle); |
|
| 1482 | + $p->code = "''"; |
|
| 1483 | + return $p; |
|
| 1484 | + } |
|
| 1485 | + |
|
| 1486 | + $_champ = interprete_argument_balise(1,$p); |
|
| 1487 | + // si pas de champ, renvoyer le critere de tri utilise |
|
| 1488 | + if (!$_champ){ |
|
| 1489 | + $p->code = $boucle->modificateur['tri_champ']; |
|
| 1490 | + return $p; |
|
| 1491 | + } |
|
| 1492 | + // forcer la jointure si besoin, et si le champ est statique |
|
| 1493 | + if (preg_match(",^'([\w.]+)'$,i",$_champ,$m)){ |
|
| 1494 | + index_pile($b, $m[1], $p->boucles); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + $_libelle = interprete_argument_balise(2,$p); |
|
| 1498 | + $_libelle = $_libelle?$_libelle:$_champ; |
|
| 1499 | + |
|
| 1500 | + $_class = interprete_argument_balise(3,$p); |
|
| 1501 | + // si champ = ">" c'est un lien vers le tri croissant : de gauche a droite ==> 1 |
|
| 1502 | + // si champ = "<" c'est un lien vers le tri decroissant : (sens inverse) == -1 |
|
| 1503 | + $_issens = "in_array($_champ,array('>','<'))"; |
|
| 1504 | + $_sens = "(strpos('< >',$_champ)-1)"; |
|
| 1505 | + |
|
| 1506 | + $_variable = "((\$s=$_issens)?'sens':'tri').".$boucle->modificateur['tri_nom']; |
|
| 1507 | + $_url = "parametre_url(self(),$_variable,\$s?$_sens:$_champ)"; |
|
| 1508 | + $_on = "\$s?(".$boucle->modificateur['tri_sens']."==$_sens".'):('.$boucle->modificateur['tri_champ']."==$_champ)"; |
|
| 1509 | + |
|
| 1510 | + $p->code = "lien_ou_expose($_url,$_libelle,$_on".($_class?",$_class":"").")"; |
|
| 1511 | + //$p->code = "''"; |
|
| 1512 | + $p->interdire_scripts = false; |
|
| 1513 | + return $p; |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | 1516 | |
@@ -1526,22 +1526,22 @@ discard block |
||
| 1526 | 1526 | * @return <type> |
| 1527 | 1527 | */ |
| 1528 | 1528 | function balise_SAUTER_dist($p){ |
| 1529 | - $id_boucle = $p->id_boucle; |
|
| 1530 | - $boucle = $p->boucles[$id_boucle]; |
|
| 1529 | + $id_boucle = $p->id_boucle; |
|
| 1530 | + $boucle = $p->boucles[$id_boucle]; |
|
| 1531 | 1531 | |
| 1532 | - if (!$boucle) { |
|
| 1533 | - $msg = array('zbug_champ_hors_boucle', array('champ' => '#SAUTER')); |
|
| 1534 | - erreur_squelette($msg, $p); |
|
| 1535 | - } |
|
| 1536 | - else { |
|
| 1537 | - $_saut = interprete_argument_balise(1,$p); |
|
| 1538 | - $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 1539 | - $_total = "\$Numrows['$id_boucle']['total']"; |
|
| 1532 | + if (!$boucle) { |
|
| 1533 | + $msg = array('zbug_champ_hors_boucle', array('champ' => '#SAUTER')); |
|
| 1534 | + erreur_squelette($msg, $p); |
|
| 1535 | + } |
|
| 1536 | + else { |
|
| 1537 | + $_saut = interprete_argument_balise(1,$p); |
|
| 1538 | + $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 1539 | + $_total = "\$Numrows['$id_boucle']['total']"; |
|
| 1540 | 1540 | |
| 1541 | - $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 1542 | - } |
|
| 1543 | - $p->interdire_scripts = false; |
|
| 1544 | - return $p; |
|
| 1541 | + $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 1542 | + } |
|
| 1543 | + $p->interdire_scripts = false; |
|
| 1544 | + return $p; |
|
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | 1547 | |
@@ -1552,18 +1552,18 @@ discard block |
||
| 1552 | 1552 | * @return <type> |
| 1553 | 1553 | */ |
| 1554 | 1554 | function balise_PUBLIE_dist($p) { |
| 1555 | - if (!$_type = interprete_argument_balise(1,$p)){ |
|
| 1556 | - $_type = _q($p->type_requete); |
|
| 1557 | - $_id = champ_sql($p->boucles[$p->id_boucle]->primary,$p); |
|
| 1558 | - } |
|
| 1559 | - else |
|
| 1560 | - $_id = interprete_argument_balise(2,$p); |
|
| 1555 | + if (!$_type = interprete_argument_balise(1,$p)){ |
|
| 1556 | + $_type = _q($p->type_requete); |
|
| 1557 | + $_id = champ_sql($p->boucles[$p->id_boucle]->primary,$p); |
|
| 1558 | + } |
|
| 1559 | + else |
|
| 1560 | + $_id = interprete_argument_balise(2,$p); |
|
| 1561 | 1561 | |
| 1562 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 1562 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 1563 | 1563 | |
| 1564 | - $p->code = "(objet_test_si_publie(".$_type.",intval(".$_id."),"._q($connect).")?' ':'')"; |
|
| 1565 | - $p->interdire_scripts = false; |
|
| 1566 | - return $p; |
|
| 1564 | + $p->code = "(objet_test_si_publie(".$_type.",intval(".$_id."),"._q($connect).")?' ':'')"; |
|
| 1565 | + $p->interdire_scripts = false; |
|
| 1566 | + return $p; |
|
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | 1569 | /** |
@@ -1582,12 +1582,12 @@ discard block |
||
| 1582 | 1582 | * @return object |
| 1583 | 1583 | */ |
| 1584 | 1584 | function balise_PRODUIRE_dist($p){ |
| 1585 | - $balise_inclure = charger_fonction('INCLURE','balise'); |
|
| 1586 | - $p = $balise_inclure($p); |
|
| 1585 | + $balise_inclure = charger_fonction('INCLURE','balise'); |
|
| 1586 | + $p = $balise_inclure($p); |
|
| 1587 | 1587 | |
| 1588 | - $p->code = str_replace('recuperer_fond(','produire_fond_statique(',$p->code); |
|
| 1588 | + $p->code = str_replace('recuperer_fond(','produire_fond_statique(',$p->code); |
|
| 1589 | 1589 | |
| 1590 | - return $p; |
|
| 1590 | + return $p; |
|
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | 1593 | /** |
@@ -1598,9 +1598,9 @@ discard block |
||
| 1598 | 1598 | * @return |
| 1599 | 1599 | */ |
| 1600 | 1600 | function balise_LARGEUR_ECRAN_dist($p){ |
| 1601 | - $_class = interprete_argument_balise(1,$p); |
|
| 1602 | - if (!$_class) $_class='null'; |
|
| 1603 | - $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 1604 | - return $p; |
|
| 1601 | + $_class = interprete_argument_balise(1,$p); |
|
| 1602 | + if (!$_class) $_class='null'; |
|
| 1603 | + $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 1604 | + return $p; |
|
| 1605 | 1605 | } |
| 1606 | 1606 | ?> |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return array|bool|null |
| 30 | 30 | */ |
| 31 | 31 | function quete_virtuel($id_article, $connect) { |
| 32 | - return sql_getfetsel('virtuel', 'spip_articles', array("id_article=".intval($id_article), "statut='publie'"), '','','','',$connect); |
|
| 32 | + return sql_getfetsel('virtuel', 'spip_articles', array("id_article=".intval($id_article), "statut='publie'"), '','','','',$connect); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | 45 | function quete_parent_lang($table,$id,$connect=''){ |
| 46 | - static $cache_quete = array(); |
|
| 47 | - |
|
| 48 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 49 | - if (!isset($cache_quete[$connect][$table]['_select'])){ |
|
| 50 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 51 | - if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique'])) |
|
| 52 | - // pas de parent rubrique, on passe |
|
| 53 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 54 | - else { |
|
| 55 | - $select = ($table=='spip_rubriques'?'id_parent':'id_rubrique'); |
|
| 56 | - $select .= isset($desc['field']['lang'])?", lang":""; |
|
| 57 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 58 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - if ($cache_quete[$connect][$table]['_select']) |
|
| 62 | - $cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect); |
|
| 63 | - } |
|
| 64 | - return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 46 | + static $cache_quete = array(); |
|
| 47 | + |
|
| 48 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 49 | + if (!isset($cache_quete[$connect][$table]['_select'])){ |
|
| 50 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 51 | + if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique'])) |
|
| 52 | + // pas de parent rubrique, on passe |
|
| 53 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 54 | + else { |
|
| 55 | + $select = ($table=='spip_rubriques'?'id_parent':'id_rubrique'); |
|
| 56 | + $select .= isset($desc['field']['lang'])?", lang":""; |
|
| 57 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 58 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + if ($cache_quete[$connect][$table]['_select']) |
|
| 62 | + $cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect); |
|
| 63 | + } |
|
| 64 | + return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | * @return int |
| 78 | 78 | */ |
| 79 | 79 | function quete_parent($id_rubrique, $connect='') { |
| 80 | - if (!$id_rubrique = intval($id_rubrique)) |
|
| 81 | - return 0; |
|
| 82 | - $id_parent = quete_parent_lang('spip_rubriques',$id_rubrique,$connect); |
|
| 83 | - return $id_parent['id_parent']; |
|
| 80 | + if (!$id_rubrique = intval($id_rubrique)) |
|
| 81 | + return 0; |
|
| 82 | + $id_parent = quete_parent_lang('spip_rubriques',$id_rubrique,$connect); |
|
| 83 | + return $id_parent['id_parent']; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | * @return |
| 96 | 96 | */ |
| 97 | 97 | function quete_rubrique($id_article, $serveur) { |
| 98 | - $id_parent = quete_parent_lang('spip_articles',$id_article,$serveur); |
|
| 99 | - return $id_parent['id_rubrique']; |
|
| 98 | + $id_parent = quete_parent_lang('spip_articles',$id_article,$serveur); |
|
| 99 | + return $id_parent['id_rubrique']; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | * @return int |
| 111 | 111 | */ |
| 112 | 112 | function quete_profondeur($id, $connect='') { |
| 113 | - $n = 0; |
|
| 114 | - while ($id) { |
|
| 115 | - $n++; |
|
| 116 | - $id = quete_parent($id, $connect); |
|
| 117 | - } |
|
| 118 | - return $n; |
|
| 113 | + $n = 0; |
|
| 114 | + while ($id) { |
|
| 115 | + $n++; |
|
| 116 | + $id = quete_parent($id, $connect); |
|
| 117 | + } |
|
| 118 | + return $n; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -126,13 +126,13 @@ discard block |
||
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | 128 | function quete_condition_postdates($champ_date, $serveur='', $ignore_previsu=false) { |
| 129 | - if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 130 | - return "1=1"; |
|
| 131 | - return |
|
| 132 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 133 | - AND $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 134 | - ? "$champ_date<".sql_quote(date('Y-m-d H:i:s',$GLOBALS['meta']['date_prochain_postdate']),$serveur) |
|
| 135 | - : "1=1" ; |
|
| 129 | + if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 130 | + return "1=1"; |
|
| 131 | + return |
|
| 132 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 133 | + AND $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 134 | + ? "$champ_date<".sql_quote(date('Y-m-d H:i:s',$GLOBALS['meta']['date_prochain_postdate']),$serveur) |
|
| 135 | + : "1=1" ; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -150,67 +150,67 @@ discard block |
||
| 150 | 150 | * @return array |
| 151 | 151 | */ |
| 152 | 152 | function quete_condition_statut($mstatut,$previsu,$publie, $serveur='', $ignore_previsu=false){ |
| 153 | - static $cond = array(); |
|
| 154 | - $key = func_get_args(); |
|
| 155 | - $key = implode("-",$key); |
|
| 156 | - if (isset($cond[$key])) return $cond[$key]; |
|
| 157 | - |
|
| 158 | - $liste = $publie; |
|
| 159 | - if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 160 | - $liste = $previsu; |
|
| 161 | - $not = false; |
|
| 162 | - if (strncmp($liste,'!',1)==0){ |
|
| 163 | - $not = true; |
|
| 164 | - $liste = substr($liste,1); |
|
| 165 | - } |
|
| 166 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 167 | - if (!strlen($liste)) |
|
| 168 | - return $cond[$key]=($not?"1=1":"'0=1'"); |
|
| 169 | - |
|
| 170 | - $liste = explode(',',$liste); |
|
| 171 | - $where = array(); |
|
| 172 | - foreach($liste as $k=>$v) { |
|
| 173 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 174 | - // a ceux de l'auteur identifie |
|
| 175 | - if (strpos($v,"/")!==false){ |
|
| 176 | - $v = explode("/",$v); |
|
| 177 | - $filtre = end($v); |
|
| 178 | - $v = reset($v); |
|
| 179 | - $v = preg_replace(",\W,","",$v); |
|
| 180 | - if ($filtre=="auteur" |
|
| 181 | - AND isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 182 | - AND intval($GLOBALS['visiteur_session']['id_auteur']) |
|
| 183 | - AND (strpos($mstatut,".")!==false) |
|
| 184 | - AND $objet = explode(".",$mstatut) |
|
| 185 | - AND $id_table = reset($objet) |
|
| 186 | - AND $objet = objet_type($id_table)){ |
|
| 187 | - $primary = id_table_objet($objet); |
|
| 188 | - $where[] = "($mstatut<>".sql_quote($v)." OR $id_table.$primary IN (".sql_get_select("ssss.id_objet","spip_auteurs_liens AS ssss","ssss.objet=".sql_quote($objet)." AND ssss.id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']),'','','','',$serveur)."))"; |
|
| 189 | - } |
|
| 190 | - // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 191 | - else |
|
| 192 | - $v = ""; |
|
| 193 | - } |
|
| 194 | - // securite |
|
| 195 | - $liste[$k] = preg_replace(",\W,","",$v); |
|
| 196 | - } |
|
| 197 | - $liste = array_filter($liste); |
|
| 198 | - if (count($liste)==1){ |
|
| 199 | - $where[] = array('=', $mstatut, sql_quote(reset($liste),$serveur)); |
|
| 200 | - } |
|
| 201 | - else { |
|
| 202 | - $where[] = sql_in($mstatut,$liste,$not,$serveur); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - while (count($where)>1){ |
|
| 206 | - $and = array('AND',array_pop($where),array_pop($where)); |
|
| 207 | - $where[] = $and; |
|
| 208 | - } |
|
| 209 | - $cond[$key] = reset($where); |
|
| 210 | - if ($not) |
|
| 211 | - $cond[$key] = array('NOT',$cond[$key]); |
|
| 212 | - |
|
| 213 | - return $cond[$key]; |
|
| 153 | + static $cond = array(); |
|
| 154 | + $key = func_get_args(); |
|
| 155 | + $key = implode("-",$key); |
|
| 156 | + if (isset($cond[$key])) return $cond[$key]; |
|
| 157 | + |
|
| 158 | + $liste = $publie; |
|
| 159 | + if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 160 | + $liste = $previsu; |
|
| 161 | + $not = false; |
|
| 162 | + if (strncmp($liste,'!',1)==0){ |
|
| 163 | + $not = true; |
|
| 164 | + $liste = substr($liste,1); |
|
| 165 | + } |
|
| 166 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 167 | + if (!strlen($liste)) |
|
| 168 | + return $cond[$key]=($not?"1=1":"'0=1'"); |
|
| 169 | + |
|
| 170 | + $liste = explode(',',$liste); |
|
| 171 | + $where = array(); |
|
| 172 | + foreach($liste as $k=>$v) { |
|
| 173 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 174 | + // a ceux de l'auteur identifie |
|
| 175 | + if (strpos($v,"/")!==false){ |
|
| 176 | + $v = explode("/",$v); |
|
| 177 | + $filtre = end($v); |
|
| 178 | + $v = reset($v); |
|
| 179 | + $v = preg_replace(",\W,","",$v); |
|
| 180 | + if ($filtre=="auteur" |
|
| 181 | + AND isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 182 | + AND intval($GLOBALS['visiteur_session']['id_auteur']) |
|
| 183 | + AND (strpos($mstatut,".")!==false) |
|
| 184 | + AND $objet = explode(".",$mstatut) |
|
| 185 | + AND $id_table = reset($objet) |
|
| 186 | + AND $objet = objet_type($id_table)){ |
|
| 187 | + $primary = id_table_objet($objet); |
|
| 188 | + $where[] = "($mstatut<>".sql_quote($v)." OR $id_table.$primary IN (".sql_get_select("ssss.id_objet","spip_auteurs_liens AS ssss","ssss.objet=".sql_quote($objet)." AND ssss.id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']),'','','','',$serveur)."))"; |
|
| 189 | + } |
|
| 190 | + // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 191 | + else |
|
| 192 | + $v = ""; |
|
| 193 | + } |
|
| 194 | + // securite |
|
| 195 | + $liste[$k] = preg_replace(",\W,","",$v); |
|
| 196 | + } |
|
| 197 | + $liste = array_filter($liste); |
|
| 198 | + if (count($liste)==1){ |
|
| 199 | + $where[] = array('=', $mstatut, sql_quote(reset($liste),$serveur)); |
|
| 200 | + } |
|
| 201 | + else { |
|
| 202 | + $where[] = sql_in($mstatut,$liste,$not,$serveur); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + while (count($where)>1){ |
|
| 206 | + $and = array('AND',array_pop($where),array_pop($where)); |
|
| 207 | + $where[] = $and; |
|
| 208 | + } |
|
| 209 | + $cond[$key] = reset($where); |
|
| 210 | + if ($not) |
|
| 211 | + $cond[$key] = array('NOT',$cond[$key]); |
|
| 212 | + |
|
| 213 | + return $cond[$key]; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @return array|bool|null |
| 224 | 224 | */ |
| 225 | 225 | function quete_fichier($id_document, $serveur='') { |
| 226 | - return sql_getfetsel('fichier', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 226 | + return sql_getfetsel('fichier', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * @return array|bool |
| 235 | 235 | */ |
| 236 | 236 | function quete_document($id_document, $serveur='') { |
| 237 | - return sql_fetsel('*', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 237 | + return sql_fetsel('*', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | * @return array|bool|null |
| 248 | 248 | */ |
| 249 | 249 | function quete_meta($nom, $serveur) { |
| 250 | - return sql_getfetsel("valeur", "spip_meta", "nom=" . sql_quote($nom), |
|
| 251 | - '','','','',$serveur); |
|
| 250 | + return sql_getfetsel("valeur", "spip_meta", "nom=" . sql_quote($nom), |
|
| 251 | + '','','','',$serveur); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -265,38 +265,38 @@ discard block |
||
| 265 | 265 | * @return array|string |
| 266 | 266 | */ |
| 267 | 267 | function quete_logo($type, $onoff, $id, $id_rubrique, $flag) { |
| 268 | - static $chercher_logo; |
|
| 269 | - if (is_null($chercher_logo)) |
|
| 270 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 271 | - $nom = strtolower($onoff); |
|
| 272 | - |
|
| 273 | - while (1) { |
|
| 274 | - $on = $chercher_logo($id, $type, $nom); |
|
| 275 | - if ($on) { |
|
| 276 | - if ($flag) |
|
| 277 | - return "$on[2].$on[3]"; |
|
| 278 | - else { |
|
| 279 | - $taille = @getimagesize($on[0]); |
|
| 280 | - $off = ($onoff != 'ON') ? '' : |
|
| 281 | - $chercher_logo($id, $type, 'off'); |
|
| 282 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 283 | - // qui permet de distinguer le changement de logo |
|
| 284 | - // et placer un expire sur le dossier IMG/ |
|
| 285 | - return array ($on[0].($on[4]?"?$on[4]":""), |
|
| 286 | - ($off ? $off[0] . ($off[4]?"?$off[4]":"") : ''), |
|
| 287 | - (!$taille ? '' : (" ".$taille[3]))); |
|
| 288 | - } |
|
| 289 | - } |
|
| 268 | + static $chercher_logo; |
|
| 269 | + if (is_null($chercher_logo)) |
|
| 270 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 271 | + $nom = strtolower($onoff); |
|
| 272 | + |
|
| 273 | + while (1) { |
|
| 274 | + $on = $chercher_logo($id, $type, $nom); |
|
| 275 | + if ($on) { |
|
| 276 | + if ($flag) |
|
| 277 | + return "$on[2].$on[3]"; |
|
| 278 | + else { |
|
| 279 | + $taille = @getimagesize($on[0]); |
|
| 280 | + $off = ($onoff != 'ON') ? '' : |
|
| 281 | + $chercher_logo($id, $type, 'off'); |
|
| 282 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 283 | + // qui permet de distinguer le changement de logo |
|
| 284 | + // et placer un expire sur le dossier IMG/ |
|
| 285 | + return array ($on[0].($on[4]?"?$on[4]":""), |
|
| 286 | + ($off ? $off[0] . ($off[4]?"?$off[4]":"") : ''), |
|
| 287 | + (!$taille ? '' : (" ".$taille[3]))); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | else if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) |
| 291 | 291 | return ''; |
| 292 | - else if ($id_rubrique) { |
|
| 293 | - $type = 'id_rubrique'; |
|
| 294 | - $id = $id_rubrique; |
|
| 295 | - $id_rubrique = 0; |
|
| 296 | - } else if ($id AND $type == 'id_rubrique') |
|
| 297 | - $id = quete_parent($id); |
|
| 298 | - else return ''; |
|
| 299 | - } |
|
| 292 | + else if ($id_rubrique) { |
|
| 293 | + $type = 'id_rubrique'; |
|
| 294 | + $id = $id_rubrique; |
|
| 295 | + $id_rubrique = 0; |
|
| 296 | + } else if ($id AND $type == 'id_rubrique') |
|
| 297 | + $id = quete_parent($id); |
|
| 298 | + else return ''; |
|
| 299 | + } |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -309,19 +309,19 @@ discard block |
||
| 309 | 309 | * @return bool|string |
| 310 | 310 | */ |
| 311 | 311 | function quete_logo_file($row, $connect=NULL) { |
| 312 | - include_spip('inc/documents'); |
|
| 313 | - $logo = vignette_logo_document($row, $connect); |
|
| 314 | - if (!$logo) $logo = image_du_document($row); |
|
| 315 | - if (!$logo){ |
|
| 316 | - $f = charger_fonction('vignette','inc'); |
|
| 317 | - $logo = $f($row['extension'], false); |
|
| 318 | - } |
|
| 319 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 320 | - if (strcmp($logo,_DIR_PLUGINS)==0 |
|
| 321 | - OR strcmp($logo,_DIR_PLUGINS_DIST)==0 |
|
| 322 | - OR strcmp($logo,_DIR_RACINE.'prive/')==0) |
|
| 323 | - return $logo; |
|
| 324 | - return get_spip_doc($logo); |
|
| 312 | + include_spip('inc/documents'); |
|
| 313 | + $logo = vignette_logo_document($row, $connect); |
|
| 314 | + if (!$logo) $logo = image_du_document($row); |
|
| 315 | + if (!$logo){ |
|
| 316 | + $f = charger_fonction('vignette','inc'); |
|
| 317 | + $logo = $f($row['extension'], false); |
|
| 318 | + } |
|
| 319 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 320 | + if (strcmp($logo,_DIR_PLUGINS)==0 |
|
| 321 | + OR strcmp($logo,_DIR_PLUGINS_DIST)==0 |
|
| 322 | + OR strcmp($logo,_DIR_RACINE.'prive/')==0) |
|
| 323 | + return $logo; |
|
| 324 | + return get_spip_doc($logo); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -348,16 +348,16 @@ discard block |
||
| 348 | 348 | * @return string |
| 349 | 349 | */ |
| 350 | 350 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect=NULL) { |
| 351 | - include_spip('inc/documents'); |
|
| 352 | - $logo = ''; |
|
| 353 | - if (!in_array($mode_logo,array('icone','apercu'))) |
|
| 354 | - $logo = vignette_logo_document($row, $connect); |
|
| 355 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 356 | - if ($mode_logo == 'vignette' AND !$logo) |
|
| 357 | - return ''; |
|
| 358 | - if ($mode_logo == 'icone') |
|
| 359 | - $row['fichier'] = ''; |
|
| 360 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align); |
|
| 351 | + include_spip('inc/documents'); |
|
| 352 | + $logo = ''; |
|
| 353 | + if (!in_array($mode_logo,array('icone','apercu'))) |
|
| 354 | + $logo = vignette_logo_document($row, $connect); |
|
| 355 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 356 | + if ($mode_logo == 'vignette' AND !$logo) |
|
| 357 | + return ''; |
|
| 358 | + if ($mode_logo == 'icone') |
|
| 359 | + $row['fichier'] = ''; |
|
| 360 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -371,17 +371,17 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | function vignette_logo_document($row, $connect='') |
| 373 | 373 | { |
| 374 | - if (!$row['id_vignette']) return ''; |
|
| 375 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 376 | - if ($connect) { |
|
| 377 | - $site = quete_meta('adresse_site', $connect); |
|
| 378 | - $dir = quete_meta('dir_img', $connect); |
|
| 379 | - return "$site/$dir$fichier"; |
|
| 380 | - } |
|
| 381 | - $f = get_spip_doc($fichier); |
|
| 382 | - if ($f AND @file_exists($f)) return $f; |
|
| 383 | - if ($row['mode'] !== 'vignette') return ''; |
|
| 384 | - return generer_url_entite($row['id_document'], 'document','','', $connect); |
|
| 374 | + if (!$row['id_vignette']) return ''; |
|
| 375 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 376 | + if ($connect) { |
|
| 377 | + $site = quete_meta('adresse_site', $connect); |
|
| 378 | + $dir = quete_meta('dir_img', $connect); |
|
| 379 | + return "$site/$dir$fichier"; |
|
| 380 | + } |
|
| 381 | + $f = get_spip_doc($fichier); |
|
| 382 | + if ($f AND @file_exists($f)) return $f; |
|
| 383 | + if ($row['mode'] !== 'vignette') return ''; |
|
| 384 | + return generer_url_entite($row['id_document'], 'document','','', $connect); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -399,60 +399,60 @@ discard block |
||
| 399 | 399 | * @return bool|string |
| 400 | 400 | */ |
| 401 | 401 | function calcul_exposer ($id, $prim, $reference, $parent, $type, $connect='') { |
| 402 | - static $exposer = array(); |
|
| 403 | - |
|
| 404 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 405 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 406 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 407 | - // en static. |
|
| 408 | - if (!isset($exposer[$m=md5(serialize($reference))][$prim])) { |
|
| 409 | - $principal = isset($reference[$type])?$reference[$type]: |
|
| 410 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 411 | - // et donne la reference dynamique @type=xx dans le contexte |
|
| 412 | - (isset($reference["@$type"])?$reference["@$type"]:''); |
|
| 413 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 414 | - // il n'est donc pas utile |
|
| 415 | - $parent = 0; |
|
| 416 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 417 | - $enfants = array('id_rubrique'=>array('id_article'),'id_groupe'=>array('id_mot')); |
|
| 418 | - if (isset($enfants[$type])) |
|
| 419 | - foreach($enfants[$type] as $t) |
|
| 420 | - if (isset($reference[$t]) |
|
| 421 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 422 | - OR isset($reference["@$t"])) { |
|
| 423 | - $type = $t; |
|
| 424 | - $principal = isset($reference[$type])?$reference[$type]:$reference["@$type"]; |
|
| 425 | - continue; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - $exposer[$m][$type] = array(); |
|
| 429 | - if ($principal) { |
|
| 430 | - $principaux = is_array($principal)?$principal:array($principal); |
|
| 431 | - foreach($principaux as $principal){ |
|
| 432 | - $exposer[$m][$type][$principal] = true; |
|
| 433 | - if ($type == 'id_mot'){ |
|
| 434 | - if (!$parent) { |
|
| 435 | - $parent = sql_getfetsel('id_groupe','spip_mots',"id_mot=" . intval($principal), '','','','',$connect); |
|
| 436 | - } |
|
| 437 | - if ($parent) |
|
| 438 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 439 | - } |
|
| 440 | - else if ($type != 'id_groupe') { |
|
| 441 | - if (!$parent) { |
|
| 442 | - if ($type == 'id_rubrique') |
|
| 443 | - $parent = $principal; |
|
| 444 | - if ($type == 'id_article') { |
|
| 445 | - $parent = quete_rubrique($principal,$connect); |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - do { $exposer[$m]['id_rubrique'][$parent] = true; } |
|
| 449 | - while ($parent = quete_parent($parent, $connect)); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - // And the winner is... |
|
| 455 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 402 | + static $exposer = array(); |
|
| 403 | + |
|
| 404 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 405 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 406 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 407 | + // en static. |
|
| 408 | + if (!isset($exposer[$m=md5(serialize($reference))][$prim])) { |
|
| 409 | + $principal = isset($reference[$type])?$reference[$type]: |
|
| 410 | + // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 411 | + // et donne la reference dynamique @type=xx dans le contexte |
|
| 412 | + (isset($reference["@$type"])?$reference["@$type"]:''); |
|
| 413 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 414 | + // il n'est donc pas utile |
|
| 415 | + $parent = 0; |
|
| 416 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 417 | + $enfants = array('id_rubrique'=>array('id_article'),'id_groupe'=>array('id_mot')); |
|
| 418 | + if (isset($enfants[$type])) |
|
| 419 | + foreach($enfants[$type] as $t) |
|
| 420 | + if (isset($reference[$t]) |
|
| 421 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 422 | + OR isset($reference["@$t"])) { |
|
| 423 | + $type = $t; |
|
| 424 | + $principal = isset($reference[$type])?$reference[$type]:$reference["@$type"]; |
|
| 425 | + continue; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + $exposer[$m][$type] = array(); |
|
| 429 | + if ($principal) { |
|
| 430 | + $principaux = is_array($principal)?$principal:array($principal); |
|
| 431 | + foreach($principaux as $principal){ |
|
| 432 | + $exposer[$m][$type][$principal] = true; |
|
| 433 | + if ($type == 'id_mot'){ |
|
| 434 | + if (!$parent) { |
|
| 435 | + $parent = sql_getfetsel('id_groupe','spip_mots',"id_mot=" . intval($principal), '','','','',$connect); |
|
| 436 | + } |
|
| 437 | + if ($parent) |
|
| 438 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 439 | + } |
|
| 440 | + else if ($type != 'id_groupe') { |
|
| 441 | + if (!$parent) { |
|
| 442 | + if ($type == 'id_rubrique') |
|
| 443 | + $parent = $principal; |
|
| 444 | + if ($type == 'id_article') { |
|
| 445 | + $parent = quete_rubrique($principal,$connect); |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + do { $exposer[$m]['id_rubrique'][$parent] = true; } |
|
| 449 | + while ($parent = quete_parent($parent, $connect)); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + // And the winner is... |
|
| 455 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -467,20 +467,20 @@ discard block |
||
| 467 | 467 | * @return int |
| 468 | 468 | */ |
| 469 | 469 | function quete_debut_pagination($primary,$valeur,$pas,$iter){ |
| 470 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 471 | - // ou composee, mais verifions |
|
| 472 | - if (!$primary OR preg_match('/[,\s]/',$primary)) |
|
| 473 | - return 0; |
|
| 474 | - |
|
| 475 | - $pos = 0; |
|
| 476 | - while ($row = $iter->fetch() AND $row[$primary]!=$valeur){ |
|
| 477 | - $pos++; |
|
| 478 | - } |
|
| 479 | - // si on a pas trouve |
|
| 480 | - if ($row[$primary]!=$valeur) |
|
| 481 | - return 0; |
|
| 482 | - |
|
| 483 | - // sinon, calculer le bon numero de page |
|
| 484 | - return floor($pos/$pas)*$pas; |
|
| 470 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 471 | + // ou composee, mais verifions |
|
| 472 | + if (!$primary OR preg_match('/[,\s]/',$primary)) |
|
| 473 | + return 0; |
|
| 474 | + |
|
| 475 | + $pos = 0; |
|
| 476 | + while ($row = $iter->fetch() AND $row[$primary]!=$valeur){ |
|
| 477 | + $pos++; |
|
| 478 | + } |
|
| 479 | + // si on a pas trouve |
|
| 480 | + if ($row[$primary]!=$valeur) |
|
| 481 | + return 0; |
|
| 482 | + |
|
| 483 | + // sinon, calculer le bon numero de page |
|
| 484 | + return floor($pos/$pas)*$pas; |
|
| 485 | 485 | } |
| 486 | 486 | ?> |
@@ -32,74 +32,74 @@ discard block |
||
| 32 | 32 | * http://doc.spip.org/@public_styliser_dist |
| 33 | 33 | */ |
| 34 | 34 | function public_styliser_dist($fond, $contexte, $lang='', $connect='') { |
| 35 | - static $styliser_par_z; |
|
| 35 | + static $styliser_par_z; |
|
| 36 | 36 | |
| 37 | - // s'assurer que le fond est licite |
|
| 38 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 39 | - if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0) |
|
| 40 | - $fond = "404"; |
|
| 37 | + // s'assurer que le fond est licite |
|
| 38 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 39 | + if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0) |
|
| 40 | + $fond = "404"; |
|
| 41 | 41 | |
| 42 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 43 | - $id_rubrique = 0; |
|
| 44 | - // Chercher le fond qui va servir de squelette |
|
| 45 | - if ($r = quete_rubrique_fond($contexte)) |
|
| 46 | - list($id_rubrique, $lang) = $r; |
|
| 47 | - |
|
| 48 | - // trouver un squelette du nom demande |
|
| 49 | - // ne rien dire si on ne trouve pas, |
|
| 50 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 51 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 52 | - $squelette = trouver_fond($fond,"",true); |
|
| 53 | - $ext = $squelette['extension']; |
|
| 54 | - |
|
| 55 | - $flux = array( |
|
| 56 | - 'args' => array( |
|
| 57 | - 'id_rubrique' => $id_rubrique, |
|
| 58 | - 'ext' => $ext, |
|
| 59 | - 'fond' => $fond, |
|
| 60 | - 'lang' => $lang, |
|
| 61 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 62 | - 'connect' => $connect |
|
| 63 | - ), |
|
| 64 | - 'data' => $squelette['fond'], |
|
| 65 | - ); |
|
| 66 | - |
|
| 67 | - if (test_espace_prive() OR defined('_ZPIP')) { |
|
| 68 | - if (!$styliser_par_z) |
|
| 69 | - $styliser_par_z = charger_fonction('styliser_par_z','public'); |
|
| 70 | - $flux = $styliser_par_z($flux); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $flux = styliser_par_objets($flux); |
|
| 74 | - |
|
| 75 | - // pipeline styliser |
|
| 76 | - $squelette = pipeline('styliser', $flux); |
|
| 77 | - |
|
| 78 | - return array($squelette, $ext, $ext, "$squelette.$ext"); |
|
| 42 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 43 | + $id_rubrique = 0; |
|
| 44 | + // Chercher le fond qui va servir de squelette |
|
| 45 | + if ($r = quete_rubrique_fond($contexte)) |
|
| 46 | + list($id_rubrique, $lang) = $r; |
|
| 47 | + |
|
| 48 | + // trouver un squelette du nom demande |
|
| 49 | + // ne rien dire si on ne trouve pas, |
|
| 50 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 51 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 52 | + $squelette = trouver_fond($fond,"",true); |
|
| 53 | + $ext = $squelette['extension']; |
|
| 54 | + |
|
| 55 | + $flux = array( |
|
| 56 | + 'args' => array( |
|
| 57 | + 'id_rubrique' => $id_rubrique, |
|
| 58 | + 'ext' => $ext, |
|
| 59 | + 'fond' => $fond, |
|
| 60 | + 'lang' => $lang, |
|
| 61 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 62 | + 'connect' => $connect |
|
| 63 | + ), |
|
| 64 | + 'data' => $squelette['fond'], |
|
| 65 | + ); |
|
| 66 | + |
|
| 67 | + if (test_espace_prive() OR defined('_ZPIP')) { |
|
| 68 | + if (!$styliser_par_z) |
|
| 69 | + $styliser_par_z = charger_fonction('styliser_par_z','public'); |
|
| 70 | + $flux = $styliser_par_z($flux); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $flux = styliser_par_objets($flux); |
|
| 74 | + |
|
| 75 | + // pipeline styliser |
|
| 76 | + $squelette = pipeline('styliser', $flux); |
|
| 77 | + |
|
| 78 | + return array($squelette, $ext, $ext, "$squelette.$ext"); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | function styliser_par_objets($flux){ |
| 82 | - if (test_espace_prive() |
|
| 83 | - AND !$squelette = $flux['data'] |
|
| 84 | - AND strncmp($flux['args']['fond'],'prive/objets/',13)==0 |
|
| 85 | - AND $echafauder = charger_fonction('echafauder','prive',true)) { |
|
| 86 | - if (strncmp($flux['args']['fond'],'prive/objets/liste/',19)==0){ |
|
| 87 | - $table = table_objet(substr($flux['args']['fond'],19)); |
|
| 88 | - $table_sql = table_objet_sql($table); |
|
| 89 | - $objets = lister_tables_objets_sql(); |
|
| 90 | - if (isset($objets[$table_sql])) |
|
| 91 | - $flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']); |
|
| 92 | - } |
|
| 93 | - if (strncmp($flux['args']['fond'],'prive/objets/contenu/',21)==0){ |
|
| 94 | - $type = substr($flux['args']['fond'],21); |
|
| 95 | - $table = table_objet($type); |
|
| 96 | - $table_sql = table_objet_sql($table); |
|
| 97 | - $objets = lister_tables_objets_sql(); |
|
| 98 | - if (isset($objets[$table_sql])) |
|
| 99 | - $flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - return $flux; |
|
| 82 | + if (test_espace_prive() |
|
| 83 | + AND !$squelette = $flux['data'] |
|
| 84 | + AND strncmp($flux['args']['fond'],'prive/objets/',13)==0 |
|
| 85 | + AND $echafauder = charger_fonction('echafauder','prive',true)) { |
|
| 86 | + if (strncmp($flux['args']['fond'],'prive/objets/liste/',19)==0){ |
|
| 87 | + $table = table_objet(substr($flux['args']['fond'],19)); |
|
| 88 | + $table_sql = table_objet_sql($table); |
|
| 89 | + $objets = lister_tables_objets_sql(); |
|
| 90 | + if (isset($objets[$table_sql])) |
|
| 91 | + $flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']); |
|
| 92 | + } |
|
| 93 | + if (strncmp($flux['args']['fond'],'prive/objets/contenu/',21)==0){ |
|
| 94 | + $type = substr($flux['args']['fond'],21); |
|
| 95 | + $table = table_objet($type); |
|
| 96 | + $table_sql = table_objet_sql($table); |
|
| 97 | + $objets = lister_tables_objets_sql(); |
|
| 98 | + if (isset($objets[$table_sql])) |
|
| 99 | + $flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + return $flux; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -117,43 +117,43 @@ discard block |
||
| 117 | 117 | * @return array |
| 118 | 118 | */ |
| 119 | 119 | function quete_rubrique_fond($contexte) { |
| 120 | - static $liste_objets = null; |
|
| 121 | - static $quete = array(); |
|
| 122 | - if (is_null($liste_objets)) { |
|
| 123 | - $liste_objets = array(); |
|
| 124 | - include_spip('inc/urls'); |
|
| 125 | - include_spip('public/quete'); |
|
| 126 | - $l = urls_liste_objets(false); |
|
| 127 | - // placer la rubrique en tete des objets |
|
| 128 | - $l = array_diff($l,array('rubrique')); |
|
| 129 | - array_unshift($l, 'rubrique'); |
|
| 130 | - foreach($l as $objet){ |
|
| 131 | - $id = id_table_objet($objet); |
|
| 132 | - if (!isset($liste_objets[$id])) |
|
| 133 | - $liste_objets[$id] = objet_type($objet,false); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $c = array_intersect_key($contexte,$liste_objets); |
|
| 137 | - if (!count($c)) return false; |
|
| 138 | - |
|
| 139 | - $c = array_map('intval',$c); |
|
| 140 | - $s = serialize($c); |
|
| 141 | - if (isset($quete[$s])) |
|
| 142 | - return $quete[$s]; |
|
| 143 | - |
|
| 144 | - if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']){ |
|
| 145 | - unset($c['id_rubrique']); |
|
| 146 | - $c = array('id_rubrique'=>$r) + $c; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - foreach($c as $_id=>$id) { |
|
| 150 | - if ($id |
|
| 151 | - AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]),$id)) { |
|
| 152 | - $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 153 | - if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique'])) |
|
| 154 | - return $quete[$s] = array ($id, $lang); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - return $quete[$s] = false; |
|
| 120 | + static $liste_objets = null; |
|
| 121 | + static $quete = array(); |
|
| 122 | + if (is_null($liste_objets)) { |
|
| 123 | + $liste_objets = array(); |
|
| 124 | + include_spip('inc/urls'); |
|
| 125 | + include_spip('public/quete'); |
|
| 126 | + $l = urls_liste_objets(false); |
|
| 127 | + // placer la rubrique en tete des objets |
|
| 128 | + $l = array_diff($l,array('rubrique')); |
|
| 129 | + array_unshift($l, 'rubrique'); |
|
| 130 | + foreach($l as $objet){ |
|
| 131 | + $id = id_table_objet($objet); |
|
| 132 | + if (!isset($liste_objets[$id])) |
|
| 133 | + $liste_objets[$id] = objet_type($objet,false); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $c = array_intersect_key($contexte,$liste_objets); |
|
| 137 | + if (!count($c)) return false; |
|
| 138 | + |
|
| 139 | + $c = array_map('intval',$c); |
|
| 140 | + $s = serialize($c); |
|
| 141 | + if (isset($quete[$s])) |
|
| 142 | + return $quete[$s]; |
|
| 143 | + |
|
| 144 | + if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']){ |
|
| 145 | + unset($c['id_rubrique']); |
|
| 146 | + $c = array('id_rubrique'=>$r) + $c; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + foreach($c as $_id=>$id) { |
|
| 150 | + if ($id |
|
| 151 | + AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]),$id)) { |
|
| 152 | + $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 153 | + if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique'])) |
|
| 154 | + return $quete[$s] = array ($id, $lang); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + return $quete[$s] = false; |
|
| 158 | 158 | } |
| 159 | 159 | ?> |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | * @return array |
| 31 | 31 | */ |
| 32 | 32 | function decompose_champ_id_objet($champ){ |
| 33 | - if (($champ!=='id_objet') AND preg_match(',^id_([a-z_]+)$,', $champ, $regs)){ |
|
| 34 | - return array('id_objet', 'objet', objet_type($regs[1])); |
|
| 35 | - } |
|
| 36 | - return $champ; |
|
| 33 | + if (($champ!=='id_objet') AND preg_match(',^id_([a-z_]+)$,', $champ, $regs)){ |
|
| 34 | + return array('id_objet', 'objet', objet_type($regs[1])); |
|
| 35 | + } |
|
| 36 | + return $champ; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -46,16 +46,16 @@ discard block |
||
| 46 | 46 | * @return array |
| 47 | 47 | */ |
| 48 | 48 | function trouver_champs_decomposes($champ, $desc){ |
| 49 | - if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 50 | - OR array_key_exists($champ, $desc['field']) |
|
| 51 | - ) |
|
| 52 | - return array($champ); |
|
| 53 | - if (is_array($decompose = decompose_champ_id_objet($champ))){ |
|
| 54 | - array_pop($decompose); |
|
| 55 | - if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose)) |
|
| 56 | - return $decompose; |
|
| 57 | - } |
|
| 58 | - return array($champ); |
|
| 49 | + if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 50 | + OR array_key_exists($champ, $desc['field']) |
|
| 51 | + ) |
|
| 52 | + return array($champ); |
|
| 53 | + if (is_array($decompose = decompose_champ_id_objet($champ))){ |
|
| 54 | + array_pop($decompose); |
|
| 55 | + if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose)) |
|
| 56 | + return $decompose; |
|
| 57 | + } |
|
| 58 | + return array($champ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | |
@@ -79,21 +79,21 @@ discard block |
||
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | 81 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens=5){ |
| 82 | - // les jointures minimales sont optimales : |
|
| 83 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 84 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 85 | - $max = 1; |
|
| 86 | - $res = false; |
|
| 87 | - $milieu_exclus = ($col?$col:array()); |
|
| 88 | - while ($max<=$max_liens AND !$res){ |
|
| 89 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 90 | - $max++; |
|
| 91 | - } |
|
| 92 | - if (!$res) return ""; |
|
| 93 | - |
|
| 94 | - list($nom, $desc) = $depart; |
|
| 95 | - |
|
| 96 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 82 | + // les jointures minimales sont optimales : |
|
| 83 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 84 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 85 | + $max = 1; |
|
| 86 | + $res = false; |
|
| 87 | + $milieu_exclus = ($col?$col:array()); |
|
| 88 | + while ($max<=$max_liens AND !$res){ |
|
| 89 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 90 | + $max++; |
|
| 91 | + } |
|
| 92 | + if (!$res) return ""; |
|
| 93 | + |
|
| 94 | + list($nom, $desc) = $depart; |
|
| 95 | + |
|
| 96 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -125,66 +125,66 @@ discard block |
||
| 125 | 125 | * @return string |
| 126 | 126 | */ |
| 127 | 127 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = array(), $nom = '', $col = '', $echap = true){ |
| 128 | - static $num = array(); |
|
| 129 | - $id_table = ""; |
|
| 130 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 131 | - foreach ($res as $cle => $r){ |
|
| 132 | - list($d, $a, $j) = $r; |
|
| 133 | - if (!$id_table) $id_table = $d; |
|
| 134 | - $n = ++$cpt; |
|
| 135 | - if (is_array($j)){ // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 136 | - list($j1, $j2, $obj, $type) = $j; |
|
| 137 | - // trouver de quel cote est (id_objet,objet) |
|
| 138 | - if ($j1=="id_$obj") |
|
| 139 | - $obj = "$id_table.$obj"; |
|
| 140 | - else |
|
| 141 | - $obj = "L$n.$obj"; |
|
| 142 | - // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
|
| 143 | - // en cas d'optimisation |
|
| 144 | - //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
|
| 145 | - $boucle->join["L$n"] = |
|
| 146 | - $echap ? |
|
| 147 | - array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 148 | - : |
|
| 149 | - array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
|
| 150 | - } |
|
| 151 | - else |
|
| 152 | - $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 153 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - // pas besoin de group by |
|
| 158 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 159 | - // si une seule jointure et sur une table avec primary key formee |
|
| 160 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 161 | - // et operateur d'egalite (http://trac.rezo.net/trac/spip/ticket/477) |
|
| 162 | - |
|
| 163 | - if ($pk = (isset($a[1]) && (count($boucle->from)==2) && !$cond)){ |
|
| 164 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // pas de group by |
|
| 168 | - // si une seule jointure |
|
| 169 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 170 | - if (!$pk |
|
| 171 | - AND (count($boucle->from)==2) |
|
| 172 | - AND isset($a[1]['key']['PRIMARY KEY']) |
|
| 173 | - AND ($j==$a[1]['key']['PRIMARY KEY']) |
|
| 174 | - ) |
|
| 175 | - $pk = true; |
|
| 176 | - |
|
| 177 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 178 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 179 | - if (!$pk) foreach ($groups as $id_prim){ |
|
| 180 | - $id_field = $nom.'.'.$id_prim; |
|
| 181 | - if (!in_array($id_field, $boucle->group)){ |
|
| 182 | - $boucle->group[] = $id_field; |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $boucle->modificateur['lien'] = true; |
|
| 187 | - return "L$n"; |
|
| 128 | + static $num = array(); |
|
| 129 | + $id_table = ""; |
|
| 130 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 131 | + foreach ($res as $cle => $r){ |
|
| 132 | + list($d, $a, $j) = $r; |
|
| 133 | + if (!$id_table) $id_table = $d; |
|
| 134 | + $n = ++$cpt; |
|
| 135 | + if (is_array($j)){ // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 136 | + list($j1, $j2, $obj, $type) = $j; |
|
| 137 | + // trouver de quel cote est (id_objet,objet) |
|
| 138 | + if ($j1=="id_$obj") |
|
| 139 | + $obj = "$id_table.$obj"; |
|
| 140 | + else |
|
| 141 | + $obj = "L$n.$obj"; |
|
| 142 | + // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
|
| 143 | + // en cas d'optimisation |
|
| 144 | + //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
|
| 145 | + $boucle->join["L$n"] = |
|
| 146 | + $echap ? |
|
| 147 | + array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 148 | + : |
|
| 149 | + array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
|
| 150 | + } |
|
| 151 | + else |
|
| 152 | + $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 153 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + // pas besoin de group by |
|
| 158 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 159 | + // si une seule jointure et sur une table avec primary key formee |
|
| 160 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 161 | + // et operateur d'egalite (http://trac.rezo.net/trac/spip/ticket/477) |
|
| 162 | + |
|
| 163 | + if ($pk = (isset($a[1]) && (count($boucle->from)==2) && !$cond)){ |
|
| 164 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // pas de group by |
|
| 168 | + // si une seule jointure |
|
| 169 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 170 | + if (!$pk |
|
| 171 | + AND (count($boucle->from)==2) |
|
| 172 | + AND isset($a[1]['key']['PRIMARY KEY']) |
|
| 173 | + AND ($j==$a[1]['key']['PRIMARY KEY']) |
|
| 174 | + ) |
|
| 175 | + $pk = true; |
|
| 176 | + |
|
| 177 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 178 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 179 | + if (!$pk) foreach ($groups as $id_prim){ |
|
| 180 | + $id_field = $nom.'.'.$id_prim; |
|
| 181 | + if (!in_array($id_field, $boucle->group)){ |
|
| 182 | + $boucle->group[] = $id_field; |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $boucle->modificateur['lien'] = true; |
|
| 187 | + return "L$n"; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | * @return bool |
| 201 | 201 | */ |
| 202 | 202 | function nogroupby_if($depart, $arrivee, $col){ |
| 203 | - $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 204 | - if (!$pk) return false; |
|
| 205 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 206 | - if (is_array($col)) $col = implode(', *', $col); // cas id_objet, objet |
|
| 207 | - return (preg_match("/^$id_primary, *$col$/", $pk) OR |
|
| 208 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 203 | + $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 204 | + if (!$pk) return false; |
|
| 205 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 206 | + if (is_array($col)) $col = implode(', *', $col); // cas id_objet, objet |
|
| 207 | + return (preg_match("/^$id_primary, *$col$/", $pk) OR |
|
| 208 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -224,33 +224,33 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | function liste_champs_jointures($nom, $desc, $primary = false){ |
| 226 | 226 | |
| 227 | - static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 227 | + static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 228 | 228 | |
| 229 | - // si cle primaire demandee, la privilegier |
|
| 230 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) |
|
| 231 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 229 | + // si cle primaire demandee, la privilegier |
|
| 230 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) |
|
| 231 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 232 | 232 | |
| 233 | - // les champs declares explicitement pour les jointures |
|
| 234 | - if (isset($desc['join'])) return $desc['join']; |
|
| 235 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 233 | + // les champs declares explicitement pour les jointures |
|
| 234 | + if (isset($desc['join'])) return $desc['join']; |
|
| 235 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 236 | 236 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 237 | 237 | |
| 238 | - // si pas de cle, c'est fichu |
|
| 239 | - if (!isset($desc['key'])) return array(); |
|
| 238 | + // si pas de cle, c'est fichu |
|
| 239 | + if (!isset($desc['key'])) return array(); |
|
| 240 | 240 | |
| 241 | - // si cle primaire |
|
| 242 | - if (isset($desc['key']['PRIMARY KEY'])) |
|
| 243 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 241 | + // si cle primaire |
|
| 242 | + if (isset($desc['key']['PRIMARY KEY'])) |
|
| 243 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 244 | 244 | |
| 245 | - // ici on se rabat sur les cles secondaires, |
|
| 246 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 247 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 248 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 245 | + // ici on se rabat sur les cles secondaires, |
|
| 246 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 247 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 248 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 249 | 249 | |
| 250 | - $join = array(); |
|
| 251 | - foreach ($desc['key'] as $v) $join = split_key($v, $join); |
|
| 252 | - foreach ($join as $k) if (in_array($k, $nojoin)) unset($join[$k]); |
|
| 253 | - return $join; |
|
| 250 | + $join = array(); |
|
| 251 | + foreach ($desc['key'] as $v) $join = split_key($v, $join); |
|
| 252 | + foreach ($join as $k) if (in_array($k, $nojoin)) unset($join[$k]); |
|
| 253 | + return $join; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | * @return array |
| 264 | 264 | */ |
| 265 | 265 | function split_key($v, $join = array()){ |
| 266 | - foreach (preg_split('/,\s*/', $v) as $k) $join[$k] = $k; |
|
| 267 | - return $join; |
|
| 266 | + foreach (preg_split('/,\s*/', $v) as $k) $join[$k] = $k; |
|
| 267 | + return $join; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -286,112 +286,112 @@ discard block |
||
| 286 | 286 | * @return array |
| 287 | 287 | */ |
| 288 | 288 | function calculer_chaine_jointures(&$boucle, $depart, $arrivee, $vu = array(), $milieu_exclus = array(), $max_liens = 5){ |
| 289 | - static $trouver_table; |
|
| 290 | - if (!$trouver_table) |
|
| 291 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 292 | - |
|
| 293 | - if (is_string($milieu_exclus)) |
|
| 294 | - $milieu_exclus = array($milieu_exclus); |
|
| 295 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 296 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 297 | - if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus)) |
|
| 298 | - $milieu_exclus[] = 'objet'; |
|
| 299 | - |
|
| 300 | - list($dnom, $ddesc) = $depart; |
|
| 301 | - list($anom, $adesc) = $arrivee; |
|
| 302 | - if (!count($vu)){ |
|
| 303 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 304 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $akeys = array(); |
|
| 308 | - foreach ($adesc['key'] as $k) { |
|
| 309 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 310 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 314 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 315 | - |
|
| 316 | - // cles candidates au depart |
|
| 317 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 318 | - // enlever les cles dde depart exclues par l'appel |
|
| 319 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 320 | - |
|
| 321 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 322 | - |
|
| 323 | - if ($v) |
|
| 324 | - return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 325 | - |
|
| 326 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 327 | - if (count(array_intersect(array('id_objet', 'objet'), $keys))==2){ |
|
| 328 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 329 | - // id_objet,objet |
|
| 330 | - // si oui on la prend |
|
| 331 | - foreach ($akeys as $key){ |
|
| 332 | - $v = decompose_champ_id_objet($key); |
|
| 333 | - if (is_array($v)){ |
|
| 334 | - $objet = array_shift($v); // objet,'article' |
|
| 335 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 336 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 337 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - else { |
|
| 342 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 343 | - // id_objet,objet a l'arrivee |
|
| 344 | - // si oui on la prend |
|
| 345 | - foreach ($keys as $key){ |
|
| 346 | - if (count($v = trouver_champs_decomposes($key, $adesc))>1){ |
|
| 347 | - if (count($v)==count(array_intersect($v, $akeys))){ |
|
| 348 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 349 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 350 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 356 | - if ($max_liens<=1) return array(); |
|
| 357 | - |
|
| 358 | - // sinon essayer de passer par une autre table |
|
| 359 | - $new = $vu; |
|
| 360 | - foreach ($boucle->jointures as $v){ |
|
| 361 | - if ($v |
|
| 362 | - AND !in_array($v, $vu) |
|
| 363 | - AND $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 364 | - AND !in_array($def['table_sql'], $vu) |
|
| 365 | - ){ |
|
| 366 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 367 | - // ie la cle de la jointure precedente |
|
| 368 | - $test_cles = $milieu_exclus; |
|
| 369 | - $new[] = $v; |
|
| 370 | - $max_iter = 50; // securite |
|
| 371 | - while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, $test_cles, 1)) |
|
| 372 | - AND $max_iter--){ |
|
| 373 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 374 | - $milieu = end($jointure_directe_possible); |
|
| 375 | - $exclure_fin = $milieu_exclus; |
|
| 376 | - if (is_string($milieu)){ |
|
| 377 | - $exclure_fin[] = $milieu; |
|
| 378 | - $test_cles[] = $milieu; |
|
| 379 | - } |
|
| 380 | - else{ |
|
| 381 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 382 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 383 | - } |
|
| 384 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 385 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 386 | - $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens-1); |
|
| 387 | - if ($r){ |
|
| 388 | - array_unshift($r, $jointure_directe_possible); |
|
| 389 | - return $r; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - return array(); |
|
| 289 | + static $trouver_table; |
|
| 290 | + if (!$trouver_table) |
|
| 291 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 292 | + |
|
| 293 | + if (is_string($milieu_exclus)) |
|
| 294 | + $milieu_exclus = array($milieu_exclus); |
|
| 295 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 296 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 297 | + if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus)) |
|
| 298 | + $milieu_exclus[] = 'objet'; |
|
| 299 | + |
|
| 300 | + list($dnom, $ddesc) = $depart; |
|
| 301 | + list($anom, $adesc) = $arrivee; |
|
| 302 | + if (!count($vu)){ |
|
| 303 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 304 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $akeys = array(); |
|
| 308 | + foreach ($adesc['key'] as $k) { |
|
| 309 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 310 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 314 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 315 | + |
|
| 316 | + // cles candidates au depart |
|
| 317 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 318 | + // enlever les cles dde depart exclues par l'appel |
|
| 319 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 320 | + |
|
| 321 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 322 | + |
|
| 323 | + if ($v) |
|
| 324 | + return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 325 | + |
|
| 326 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 327 | + if (count(array_intersect(array('id_objet', 'objet'), $keys))==2){ |
|
| 328 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 329 | + // id_objet,objet |
|
| 330 | + // si oui on la prend |
|
| 331 | + foreach ($akeys as $key){ |
|
| 332 | + $v = decompose_champ_id_objet($key); |
|
| 333 | + if (is_array($v)){ |
|
| 334 | + $objet = array_shift($v); // objet,'article' |
|
| 335 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 336 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 337 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + else { |
|
| 342 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 343 | + // id_objet,objet a l'arrivee |
|
| 344 | + // si oui on la prend |
|
| 345 | + foreach ($keys as $key){ |
|
| 346 | + if (count($v = trouver_champs_decomposes($key, $adesc))>1){ |
|
| 347 | + if (count($v)==count(array_intersect($v, $akeys))){ |
|
| 348 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 349 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 350 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 356 | + if ($max_liens<=1) return array(); |
|
| 357 | + |
|
| 358 | + // sinon essayer de passer par une autre table |
|
| 359 | + $new = $vu; |
|
| 360 | + foreach ($boucle->jointures as $v){ |
|
| 361 | + if ($v |
|
| 362 | + AND !in_array($v, $vu) |
|
| 363 | + AND $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 364 | + AND !in_array($def['table_sql'], $vu) |
|
| 365 | + ){ |
|
| 366 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 367 | + // ie la cle de la jointure precedente |
|
| 368 | + $test_cles = $milieu_exclus; |
|
| 369 | + $new[] = $v; |
|
| 370 | + $max_iter = 50; // securite |
|
| 371 | + while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, $test_cles, 1)) |
|
| 372 | + AND $max_iter--){ |
|
| 373 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 374 | + $milieu = end($jointure_directe_possible); |
|
| 375 | + $exclure_fin = $milieu_exclus; |
|
| 376 | + if (is_string($milieu)){ |
|
| 377 | + $exclure_fin[] = $milieu; |
|
| 378 | + $test_cles[] = $milieu; |
|
| 379 | + } |
|
| 380 | + else{ |
|
| 381 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 382 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 383 | + } |
|
| 384 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 385 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 386 | + $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens-1); |
|
| 387 | + if ($r){ |
|
| 388 | + array_unshift($r, $jointure_directe_possible); |
|
| 389 | + return $r; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + return array(); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -404,17 +404,17 @@ discard block |
||
| 404 | 404 | * @return array |
| 405 | 405 | */ |
| 406 | 406 | function trouver_cles_table($keys){ |
| 407 | - $res = array(); |
|
| 408 | - foreach ($keys as $v){ |
|
| 409 | - if (!strpos($v, ",")) |
|
| 410 | - $res[$v] = 1; |
|
| 411 | - else { |
|
| 412 | - foreach (preg_split("/\s*,\s*/", $v) as $k){ |
|
| 413 | - $res[$k] = 1; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - return array_keys($res); |
|
| 407 | + $res = array(); |
|
| 408 | + foreach ($keys as $v){ |
|
| 409 | + if (!strpos($v, ",")) |
|
| 410 | + $res[$v] = 1; |
|
| 411 | + else { |
|
| 412 | + foreach (preg_split("/\s*,\s*/", $v) as $k){ |
|
| 413 | + $res[$k] = 1; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + return array_keys($res); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -427,60 +427,60 @@ discard block |
||
| 427 | 427 | * @return array|string |
| 428 | 428 | */ |
| 429 | 429 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false){ |
| 430 | - static $trouver_table = ''; |
|
| 431 | - if (!$trouver_table) |
|
| 432 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 433 | - |
|
| 434 | - // support de la recherche multi champ : |
|
| 435 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 436 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 437 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 438 | - if (!is_array($cle)) |
|
| 439 | - $cle = array($cle); |
|
| 440 | - |
|
| 441 | - foreach ($joints as $k => $join){ |
|
| 442 | - if ($join && $table = $trouver_table($join, $boucle->sql_serveur)){ |
|
| 443 | - if (isset($table['field']) |
|
| 444 | - // verifier que toutes les cles cherchees sont la |
|
| 445 | - AND (count(array_intersect($cle, array_keys($table['field'])))==count($cle)) |
|
| 446 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 447 | - AND ($checkarrivee==false || $checkarrivee==$table['table']) |
|
| 448 | - ) |
|
| 449 | - return array($table['table'], $table); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // au premier coup, on essaye de decomposer, si possible |
|
| 454 | - if (count($cle)==1 |
|
| 455 | - AND $c = reset($cle) |
|
| 456 | - AND is_array($decompose = decompose_champ_id_objet($c)) |
|
| 457 | - ){ |
|
| 458 | - |
|
| 459 | - $desc = $boucle->show; |
|
| 460 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 461 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 462 | - if (isset($desc['field'][$c])){ |
|
| 463 | - $cle = array(); |
|
| 464 | - $cle[] = array_shift($decompose); // id_objet |
|
| 465 | - $cle[] = array_shift($decompose); // objet |
|
| 466 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 467 | - } |
|
| 468 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 469 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 470 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 471 | - else { |
|
| 472 | - $depart = liste_champs_jointures($desc['table'], $desc); |
|
| 473 | - foreach ($depart as $d){ |
|
| 474 | - $cle = array(); |
|
| 475 | - $cle[] = array_shift($decompose); // id_objet |
|
| 476 | - $cle[] = array_shift($decompose); // objet |
|
| 477 | - $cle[] = $d; |
|
| 478 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) |
|
| 479 | - return $ext; |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - return ""; |
|
| 430 | + static $trouver_table = ''; |
|
| 431 | + if (!$trouver_table) |
|
| 432 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 433 | + |
|
| 434 | + // support de la recherche multi champ : |
|
| 435 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 436 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 437 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 438 | + if (!is_array($cle)) |
|
| 439 | + $cle = array($cle); |
|
| 440 | + |
|
| 441 | + foreach ($joints as $k => $join){ |
|
| 442 | + if ($join && $table = $trouver_table($join, $boucle->sql_serveur)){ |
|
| 443 | + if (isset($table['field']) |
|
| 444 | + // verifier que toutes les cles cherchees sont la |
|
| 445 | + AND (count(array_intersect($cle, array_keys($table['field'])))==count($cle)) |
|
| 446 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 447 | + AND ($checkarrivee==false || $checkarrivee==$table['table']) |
|
| 448 | + ) |
|
| 449 | + return array($table['table'], $table); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // au premier coup, on essaye de decomposer, si possible |
|
| 454 | + if (count($cle)==1 |
|
| 455 | + AND $c = reset($cle) |
|
| 456 | + AND is_array($decompose = decompose_champ_id_objet($c)) |
|
| 457 | + ){ |
|
| 458 | + |
|
| 459 | + $desc = $boucle->show; |
|
| 460 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 461 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 462 | + if (isset($desc['field'][$c])){ |
|
| 463 | + $cle = array(); |
|
| 464 | + $cle[] = array_shift($decompose); // id_objet |
|
| 465 | + $cle[] = array_shift($decompose); // objet |
|
| 466 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 467 | + } |
|
| 468 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 469 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 470 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 471 | + else { |
|
| 472 | + $depart = liste_champs_jointures($desc['table'], $desc); |
|
| 473 | + foreach ($depart as $d){ |
|
| 474 | + $cle = array(); |
|
| 475 | + $cle[] = array_shift($decompose); // id_objet |
|
| 476 | + $cle[] = array_shift($decompose); // objet |
|
| 477 | + $cle[] = $d; |
|
| 478 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) |
|
| 479 | + return $ext; |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + return ""; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -506,17 +506,17 @@ discard block |
||
| 506 | 506 | * @return string |
| 507 | 507 | */ |
| 508 | 508 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false) { |
| 509 | - if ($jointures === false) { |
|
| 510 | - $jointures = $boucle->jointures; |
|
| 511 | - } |
|
| 512 | - $cle = trouver_champ_exterieur($champ, $jointures, $boucle); |
|
| 513 | - if ($cle){ |
|
| 514 | - $desc = $boucle->show; |
|
| 515 | - $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $cle, '', $cond); |
|
| 516 | - } |
|
| 517 | - if ($cle) return $cle; |
|
| 518 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 519 | - return ''; |
|
| 509 | + if ($jointures === false) { |
|
| 510 | + $jointures = $boucle->jointures; |
|
| 511 | + } |
|
| 512 | + $cle = trouver_champ_exterieur($champ, $jointures, $boucle); |
|
| 513 | + if ($cle){ |
|
| 514 | + $desc = $boucle->show; |
|
| 515 | + $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $cle, '', $cond); |
|
| 516 | + } |
|
| 517 | + if ($cle) return $cle; |
|
| 518 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 519 | + return ''; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | ?> |
@@ -20,537 +20,537 @@ |
||
| 20 | 20 | * |
| 21 | 21 | */ |
| 22 | 22 | class IterFactory{ |
| 23 | - public static function create($iterateur, $command, $info=null){ |
|
| 24 | - |
|
| 25 | - // cas des SI {si expression} analises tres tot |
|
| 26 | - // pour eviter le chargement de tout iterateur |
|
| 27 | - if (isset($command['si'])) { |
|
| 28 | - foreach ($command['si'] as $si) { |
|
| 29 | - if (!$si) { |
|
| 30 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 31 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 32 | - return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 38 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 39 | - // pour etre certain qu'on est sur un "php:") |
|
| 40 | - if (class_exists($iterateur)) { |
|
| 41 | - $a = isset($command['args']) ? $command['args'] : array() ; |
|
| 42 | - |
|
| 43 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 44 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 45 | - if (count($a)==1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 46 | - $iter = $a[0]; |
|
| 47 | - |
|
| 48 | - // sinon, on cree un iterateur du type donne |
|
| 49 | - } else { |
|
| 50 | - // arguments de creation de l'iterateur... |
|
| 51 | - // (pas glop) |
|
| 52 | - try { |
|
| 53 | - switch (count($a)) { |
|
| 54 | - case 0: $iter = new $iterateur(); break; |
|
| 55 | - case 1: $iter = new $iterateur($a[0]); break; |
|
| 56 | - case 2: $iter = new $iterateur($a[0], $a[1]); break; |
|
| 57 | - case 3: $iter = new $iterateur($a[0], $a[1], $a[2]); break; |
|
| 58 | - case 4: $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); break; |
|
| 59 | - } |
|
| 60 | - } catch (Exception $e) { |
|
| 61 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 62 | - spip_log($e->getMessage()); |
|
| 63 | - $iter = new EmptyIterator(); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } else { |
|
| 67 | - // chercher la classe d'iterateur |
|
| 68 | - // IterateurXXX |
|
| 69 | - // definie dans le fichier iterateurs/xxx.php |
|
| 70 | - $class = "Iterateur".$iterateur; |
|
| 71 | - if (!class_exists($class)){ |
|
| 72 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 73 | - OR !class_exists($class)) { |
|
| 74 | - die("Iterateur $iterateur non trouvé"); |
|
| 75 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 76 | - # $iter = new EmptyIterator(); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - $iter = new $class($command, $info); |
|
| 80 | - } |
|
| 81 | - return new IterDecorator($iter, $command, $info); |
|
| 82 | - } |
|
| 23 | + public static function create($iterateur, $command, $info=null){ |
|
| 24 | + |
|
| 25 | + // cas des SI {si expression} analises tres tot |
|
| 26 | + // pour eviter le chargement de tout iterateur |
|
| 27 | + if (isset($command['si'])) { |
|
| 28 | + foreach ($command['si'] as $si) { |
|
| 29 | + if (!$si) { |
|
| 30 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 31 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 32 | + return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 38 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 39 | + // pour etre certain qu'on est sur un "php:") |
|
| 40 | + if (class_exists($iterateur)) { |
|
| 41 | + $a = isset($command['args']) ? $command['args'] : array() ; |
|
| 42 | + |
|
| 43 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 44 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 45 | + if (count($a)==1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 46 | + $iter = $a[0]; |
|
| 47 | + |
|
| 48 | + // sinon, on cree un iterateur du type donne |
|
| 49 | + } else { |
|
| 50 | + // arguments de creation de l'iterateur... |
|
| 51 | + // (pas glop) |
|
| 52 | + try { |
|
| 53 | + switch (count($a)) { |
|
| 54 | + case 0: $iter = new $iterateur(); break; |
|
| 55 | + case 1: $iter = new $iterateur($a[0]); break; |
|
| 56 | + case 2: $iter = new $iterateur($a[0], $a[1]); break; |
|
| 57 | + case 3: $iter = new $iterateur($a[0], $a[1], $a[2]); break; |
|
| 58 | + case 4: $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); break; |
|
| 59 | + } |
|
| 60 | + } catch (Exception $e) { |
|
| 61 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 62 | + spip_log($e->getMessage()); |
|
| 63 | + $iter = new EmptyIterator(); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } else { |
|
| 67 | + // chercher la classe d'iterateur |
|
| 68 | + // IterateurXXX |
|
| 69 | + // definie dans le fichier iterateurs/xxx.php |
|
| 70 | + $class = "Iterateur".$iterateur; |
|
| 71 | + if (!class_exists($class)){ |
|
| 72 | + if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 73 | + OR !class_exists($class)) { |
|
| 74 | + die("Iterateur $iterateur non trouvé"); |
|
| 75 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 76 | + # $iter = new EmptyIterator(); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + $iter = new $class($command, $info); |
|
| 80 | + } |
|
| 81 | + return new IterDecorator($iter, $command, $info); |
|
| 82 | + } |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | class IterDecorator extends FilterIterator { |
| 89 | - private $iter; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Conditions de filtrage |
|
| 93 | - * ie criteres de selection |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $filtre = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 100 | - * @var string |
|
| 101 | - */ |
|
| 102 | - protected $func_filtre = null; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Critere {offset, limit} |
|
| 106 | - * @var int |
|
| 107 | - * @var int |
|
| 108 | - */ |
|
| 109 | - protected $offset = null; |
|
| 110 | - protected $limit = null; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * nombre d'elements recuperes depuis la position 0, |
|
| 114 | - * en tenant compte des filtres |
|
| 115 | - * @var int |
|
| 116 | - */ |
|
| 117 | - protected $fetched=0; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Y a t'il une erreur ? |
|
| 121 | - * |
|
| 122 | - * @var bool |
|
| 123 | - **/ |
|
| 124 | - protected $err = false; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Drapeau a activer en cas d'echec |
|
| 128 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 129 | - */ |
|
| 130 | - public function err() { |
|
| 131 | - if (method_exists($this->iter, 'err')) |
|
| 132 | - return $this->iter->err(); |
|
| 133 | - if (property_exists($this->iter, 'err')) |
|
| 134 | - return $this->iter->err; |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - public function __construct(Iterator $iter, $command, $info){ |
|
| 139 | - parent::__construct($iter); |
|
| 140 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 89 | + private $iter; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Conditions de filtrage |
|
| 93 | + * ie criteres de selection |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $filtre = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 100 | + * @var string |
|
| 101 | + */ |
|
| 102 | + protected $func_filtre = null; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Critere {offset, limit} |
|
| 106 | + * @var int |
|
| 107 | + * @var int |
|
| 108 | + */ |
|
| 109 | + protected $offset = null; |
|
| 110 | + protected $limit = null; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * nombre d'elements recuperes depuis la position 0, |
|
| 114 | + * en tenant compte des filtres |
|
| 115 | + * @var int |
|
| 116 | + */ |
|
| 117 | + protected $fetched=0; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Y a t'il une erreur ? |
|
| 121 | + * |
|
| 122 | + * @var bool |
|
| 123 | + **/ |
|
| 124 | + protected $err = false; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Drapeau a activer en cas d'echec |
|
| 128 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 129 | + */ |
|
| 130 | + public function err() { |
|
| 131 | + if (method_exists($this->iter, 'err')) |
|
| 132 | + return $this->iter->err(); |
|
| 133 | + if (property_exists($this->iter, 'err')) |
|
| 134 | + return $this->iter->err; |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + public function __construct(Iterator $iter, $command, $info){ |
|
| 139 | + parent::__construct($iter); |
|
| 140 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 141 | 141 | |
| 142 | - // recuperer l'iterateur transmis |
|
| 143 | - $this->iter = $this->getInnerIterator(); |
|
| 144 | - $this->command = $command; |
|
| 145 | - $this->info = $info; |
|
| 146 | - $this->pos = 0; |
|
| 147 | - $this->fetched = 0; |
|
| 148 | - |
|
| 149 | - // chercher la liste des champs a retourner par |
|
| 150 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 151 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 152 | - $this->calculer_select(); |
|
| 153 | - $this->calculer_filtres(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 157 | - if (isset($this->iter->err)) { |
|
| 158 | - $this->err = $this->iter->err; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 162 | - //$this->total = $this->count(); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - // calcule les elements a retournes par fetch() |
|
| 167 | - // enleve les elements inutiles du select() |
|
| 168 | - // |
|
| 169 | - private function calculer_select() { |
|
| 170 | - if ($select = &$this->command['select']) { |
|
| 171 | - foreach($select as $s) { |
|
| 172 | - // /!\ $s = '.nom' |
|
| 173 | - if ($s[0] == '.') { |
|
| 174 | - $s = substr($s, 1); |
|
| 175 | - } |
|
| 176 | - $this->select[] = $s; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // recuperer la valeur d'une balise #X |
|
| 182 | - // en fonction des methodes |
|
| 183 | - // et proprietes disponibles |
|
| 184 | - public function get_select($nom) { |
|
| 185 | - if (is_object($this->iter) |
|
| 186 | - AND method_exists($this->iter, $nom)) { |
|
| 187 | - try { |
|
| 188 | - return $this->iter->$nom(); |
|
| 189 | - } catch(Exception $e) { |
|
| 190 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 191 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 192 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 193 | - return ''; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - /* |
|
| 142 | + // recuperer l'iterateur transmis |
|
| 143 | + $this->iter = $this->getInnerIterator(); |
|
| 144 | + $this->command = $command; |
|
| 145 | + $this->info = $info; |
|
| 146 | + $this->pos = 0; |
|
| 147 | + $this->fetched = 0; |
|
| 148 | + |
|
| 149 | + // chercher la liste des champs a retourner par |
|
| 150 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 151 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 152 | + $this->calculer_select(); |
|
| 153 | + $this->calculer_filtres(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 157 | + if (isset($this->iter->err)) { |
|
| 158 | + $this->err = $this->iter->err; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 162 | + //$this->total = $this->count(); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + // calcule les elements a retournes par fetch() |
|
| 167 | + // enleve les elements inutiles du select() |
|
| 168 | + // |
|
| 169 | + private function calculer_select() { |
|
| 170 | + if ($select = &$this->command['select']) { |
|
| 171 | + foreach($select as $s) { |
|
| 172 | + // /!\ $s = '.nom' |
|
| 173 | + if ($s[0] == '.') { |
|
| 174 | + $s = substr($s, 1); |
|
| 175 | + } |
|
| 176 | + $this->select[] = $s; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // recuperer la valeur d'une balise #X |
|
| 182 | + // en fonction des methodes |
|
| 183 | + // et proprietes disponibles |
|
| 184 | + public function get_select($nom) { |
|
| 185 | + if (is_object($this->iter) |
|
| 186 | + AND method_exists($this->iter, $nom)) { |
|
| 187 | + try { |
|
| 188 | + return $this->iter->$nom(); |
|
| 189 | + } catch(Exception $e) { |
|
| 190 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 191 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 192 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 193 | + return ''; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + /* |
|
| 197 | 197 | if (property_exists($this->iter, $nom)) { |
| 198 | 198 | return $this->iter->$nom; |
| 199 | 199 | }*/ |
| 200 | - // cle et valeur par defaut |
|
| 201 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 202 | - if (in_array($nom, array('cle', 'valeur')) |
|
| 203 | - AND method_exists($this, $nom)) { |
|
| 204 | - return $this->$nom(); |
|
| 205 | - } |
|
| 200 | + // cle et valeur par defaut |
|
| 201 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 202 | + if (in_array($nom, array('cle', 'valeur')) |
|
| 203 | + AND method_exists($this, $nom)) { |
|
| 204 | + return $this->$nom(); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - // Par defaut chercher en xpath dans la valeur() |
|
| 208 | - return table_valeur($this->valeur(), $nom, null); |
|
| 209 | - } |
|
| 207 | + // Par defaut chercher en xpath dans la valeur() |
|
| 208 | + return table_valeur($this->valeur(), $nom, null); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | |
| 212 | - private function calculer_filtres() { |
|
| 212 | + private function calculer_filtres() { |
|
| 213 | 213 | |
| 214 | - // Issu de calculer_select() de public/composer L.519 |
|
| 215 | - // TODO: externaliser... |
|
| 216 | - // |
|
| 217 | - // retirer les criteres vides: |
|
| 218 | - // {X ?} avec X absent de l'URL |
|
| 219 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 220 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 221 | - if ($where = &$this->command['where']) { |
|
| 222 | - $menage = false; |
|
| 223 | - foreach($where as $k => $v) { |
|
| 224 | - if (is_array($v)){ |
|
| 225 | - if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 226 | - elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 227 | - else $op = $v[0] ? $v[0] : $v; |
|
| 228 | - } else $op = $v; |
|
| 229 | - if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 230 | - unset($where[$k]); |
|
| 231 | - $menage = true; |
|
| 232 | - } |
|
| 233 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 234 | - // prendre en compte le cas particulier de sous-requetes |
|
| 235 | - // produites par sql_in quand plus de 255 valeurs passees a IN |
|
| 236 | - if (preg_match_all(',\s+IN\s+(\(.*\)),', $op, $s_req)) { |
|
| 237 | - $req = ''; |
|
| 238 | - foreach($s_req[1] as $key => $val) { |
|
| 239 | - $req .= trim($val, '(,)') . ','; |
|
| 240 | - } |
|
| 241 | - $req = '(' . rtrim($req, ',') . ')'; |
|
| 242 | - } |
|
| 243 | - if (preg_match(',^\(\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)(?:\s+(AND|OR)\s+\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\))*\)$,', $op, $regs)) { |
|
| 244 | - $this->ajouter_filtre($regs[1], 'IN', strlen($req) ? $req : $regs[3], $regs[2]); |
|
| 245 | - unset($op); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - foreach($where as $k => $v) { |
|
| 249 | - // 3 possibilites : count($v) = |
|
| 250 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 251 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 252 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 253 | - |
|
| 254 | - // 1 : forcement traite par un critere, on passe |
|
| 255 | - if (count($v) == 1) { |
|
| 256 | - continue; |
|
| 257 | - } |
|
| 258 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 259 | - $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 260 | - } |
|
| 261 | - if (count($v) == 3) { |
|
| 262 | - $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // critere {2,7} |
|
| 268 | - if (isset($this->command['limit']) AND $this->command['limit']) { |
|
| 269 | - $limit = explode(',',$this->command['limit']); |
|
| 270 | - $this->offset = $limit[0]; |
|
| 271 | - $this->limit = $limit[1]; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Creer la fonction de filtrage sur $this |
|
| 275 | - if ($this->filtre) { |
|
| 276 | - $this->func_filtre = create_function('$me', $b = 'return ('.join(') AND (', $this->filtre).');'); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - protected function ajouter_filtre($cle, $op, $valeur, $not=false) { |
|
| 283 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 284 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 285 | - return; |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 289 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 290 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 291 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 292 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 214 | + // Issu de calculer_select() de public/composer L.519 |
|
| 215 | + // TODO: externaliser... |
|
| 216 | + // |
|
| 217 | + // retirer les criteres vides: |
|
| 218 | + // {X ?} avec X absent de l'URL |
|
| 219 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 220 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 221 | + if ($where = &$this->command['where']) { |
|
| 222 | + $menage = false; |
|
| 223 | + foreach($where as $k => $v) { |
|
| 224 | + if (is_array($v)){ |
|
| 225 | + if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 226 | + elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 227 | + else $op = $v[0] ? $v[0] : $v; |
|
| 228 | + } else $op = $v; |
|
| 229 | + if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 230 | + unset($where[$k]); |
|
| 231 | + $menage = true; |
|
| 232 | + } |
|
| 233 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 234 | + // prendre en compte le cas particulier de sous-requetes |
|
| 235 | + // produites par sql_in quand plus de 255 valeurs passees a IN |
|
| 236 | + if (preg_match_all(',\s+IN\s+(\(.*\)),', $op, $s_req)) { |
|
| 237 | + $req = ''; |
|
| 238 | + foreach($s_req[1] as $key => $val) { |
|
| 239 | + $req .= trim($val, '(,)') . ','; |
|
| 240 | + } |
|
| 241 | + $req = '(' . rtrim($req, ',') . ')'; |
|
| 242 | + } |
|
| 243 | + if (preg_match(',^\(\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)(?:\s+(AND|OR)\s+\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\))*\)$,', $op, $regs)) { |
|
| 244 | + $this->ajouter_filtre($regs[1], 'IN', strlen($req) ? $req : $regs[3], $regs[2]); |
|
| 245 | + unset($op); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + foreach($where as $k => $v) { |
|
| 249 | + // 3 possibilites : count($v) = |
|
| 250 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 251 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 252 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 253 | + |
|
| 254 | + // 1 : forcement traite par un critere, on passe |
|
| 255 | + if (count($v) == 1) { |
|
| 256 | + continue; |
|
| 257 | + } |
|
| 258 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 259 | + $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 260 | + } |
|
| 261 | + if (count($v) == 3) { |
|
| 262 | + $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // critere {2,7} |
|
| 268 | + if (isset($this->command['limit']) AND $this->command['limit']) { |
|
| 269 | + $limit = explode(',',$this->command['limit']); |
|
| 270 | + $this->offset = $limit[0]; |
|
| 271 | + $this->limit = $limit[1]; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Creer la fonction de filtrage sur $this |
|
| 275 | + if ($this->filtre) { |
|
| 276 | + $this->func_filtre = create_function('$me', $b = 'return ('.join(') AND (', $this->filtre).');'); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + protected function ajouter_filtre($cle, $op, $valeur, $not=false) { |
|
| 283 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 284 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 285 | + return; |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 289 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 290 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 291 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 292 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 293 | 293 | |
| 294 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 295 | - # return; |
|
| 294 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 295 | + # return; |
|
| 296 | 296 | |
| 297 | - $a = '$me->get_select(\''.$cle.'\')'; |
|
| 297 | + $a = '$me->get_select(\''.$cle.'\')'; |
|
| 298 | 298 | |
| 299 | - $filtre = ''; |
|
| 299 | + $filtre = ''; |
|
| 300 | 300 | |
| 301 | - if ($op == 'REGEXP') { |
|
| 302 | - $filtre = 'match('.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 303 | - $op = ''; |
|
| 304 | - } else if ($op == 'LIKE') { |
|
| 305 | - $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 306 | - $filtre = 'match('.$a.', '.$valeur.')'; |
|
| 307 | - $op = ''; |
|
| 308 | - } else if ($op == '=') { |
|
| 309 | - $op = '=='; |
|
| 310 | - } else if ($op == 'IN') { |
|
| 311 | - $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 312 | - $op = ''; |
|
| 313 | - } else if (!in_array($op, array('<','<=', '>', '>='))) { |
|
| 314 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 315 | - $op = ''; |
|
| 316 | - } |
|
| 301 | + if ($op == 'REGEXP') { |
|
| 302 | + $filtre = 'match('.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 303 | + $op = ''; |
|
| 304 | + } else if ($op == 'LIKE') { |
|
| 305 | + $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 306 | + $filtre = 'match('.$a.', '.$valeur.')'; |
|
| 307 | + $op = ''; |
|
| 308 | + } else if ($op == '=') { |
|
| 309 | + $op = '=='; |
|
| 310 | + } else if ($op == 'IN') { |
|
| 311 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 312 | + $op = ''; |
|
| 313 | + } else if (!in_array($op, array('<','<=', '>', '>='))) { |
|
| 314 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 315 | + $op = ''; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - if ($op) |
|
| 319 | - $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 318 | + if ($op) |
|
| 319 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 320 | 320 | |
| 321 | - if ($not) |
|
| 322 | - $filtre = "!($filtre)"; |
|
| 321 | + if ($not) |
|
| 322 | + $filtre = "!($filtre)"; |
|
| 323 | 323 | |
| 324 | - if ($filtre) { |
|
| 325 | - $this->filtre[] = $filtre; |
|
| 326 | - } |
|
| 327 | - } |
|
| 324 | + if ($filtre) { |
|
| 325 | + $this->filtre[] = $filtre; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | 329 | |
| 330 | - public function next(){ |
|
| 331 | - $this->pos++; |
|
| 332 | - parent::next(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * revient au depart |
|
| 337 | - * @return void |
|
| 338 | - */ |
|
| 339 | - public function rewind() { |
|
| 340 | - $this->pos = 0; |
|
| 341 | - $this->fetched = 0; |
|
| 342 | - parent::rewind(); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - # Extension SPIP des iterateurs PHP |
|
| 347 | - /** |
|
| 348 | - * type de l'iterateur |
|
| 349 | - * @var string |
|
| 350 | - */ |
|
| 351 | - protected $type; |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * parametres de l'iterateur |
|
| 355 | - * @var array |
|
| 356 | - */ |
|
| 357 | - protected $command; |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * infos de compilateur |
|
| 361 | - * @var array |
|
| 362 | - */ |
|
| 363 | - protected $info; |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * position courante de l'iterateur |
|
| 367 | - * @var int |
|
| 368 | - */ |
|
| 369 | - protected $pos=null; |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * nombre total resultats dans l'iterateur |
|
| 373 | - * @var int |
|
| 374 | - */ |
|
| 375 | - protected $total=null; |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * nombre maximal de recherche pour $total |
|
| 379 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 380 | - */ |
|
| 381 | - protected $max=100000; |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Liste des champs a inserer dans les $row |
|
| 386 | - * retournes par ->fetch() |
|
| 387 | - */ |
|
| 388 | - protected $select=array(); |
|
| 330 | + public function next(){ |
|
| 331 | + $this->pos++; |
|
| 332 | + parent::next(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * revient au depart |
|
| 337 | + * @return void |
|
| 338 | + */ |
|
| 339 | + public function rewind() { |
|
| 340 | + $this->pos = 0; |
|
| 341 | + $this->fetched = 0; |
|
| 342 | + parent::rewind(); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + # Extension SPIP des iterateurs PHP |
|
| 347 | + /** |
|
| 348 | + * type de l'iterateur |
|
| 349 | + * @var string |
|
| 350 | + */ |
|
| 351 | + protected $type; |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * parametres de l'iterateur |
|
| 355 | + * @var array |
|
| 356 | + */ |
|
| 357 | + protected $command; |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * infos de compilateur |
|
| 361 | + * @var array |
|
| 362 | + */ |
|
| 363 | + protected $info; |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * position courante de l'iterateur |
|
| 367 | + * @var int |
|
| 368 | + */ |
|
| 369 | + protected $pos=null; |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * nombre total resultats dans l'iterateur |
|
| 373 | + * @var int |
|
| 374 | + */ |
|
| 375 | + protected $total=null; |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * nombre maximal de recherche pour $total |
|
| 379 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 380 | + */ |
|
| 381 | + protected $max=100000; |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Liste des champs a inserer dans les $row |
|
| 386 | + * retournes par ->fetch() |
|
| 387 | + */ |
|
| 388 | + protected $select=array(); |
|
| 389 | 389 | |
| 390 | 390 | |
| 391 | - /** |
|
| 392 | - * aller a la position absolue n, |
|
| 393 | - * comptee depuis le debut |
|
| 394 | - * |
|
| 395 | - * @param int $n |
|
| 396 | - * absolute pos |
|
| 397 | - * @param string $continue |
|
| 398 | - * param for sql_ api |
|
| 399 | - * @return bool |
|
| 400 | - * success or fail if not implemented |
|
| 401 | - */ |
|
| 402 | - public function seek($n=0, $continue=null) { |
|
| 403 | - if ($this->func_filtre OR !method_exists($this->iter, 'seek') OR !$this->iter->seek($n)) { |
|
| 404 | - $this->seek_loop($n); |
|
| 405 | - } |
|
| 406 | - $this->pos = $n; |
|
| 407 | - $this->fetched = $n; |
|
| 408 | - return true; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /* |
|
| 391 | + /** |
|
| 392 | + * aller a la position absolue n, |
|
| 393 | + * comptee depuis le debut |
|
| 394 | + * |
|
| 395 | + * @param int $n |
|
| 396 | + * absolute pos |
|
| 397 | + * @param string $continue |
|
| 398 | + * param for sql_ api |
|
| 399 | + * @return bool |
|
| 400 | + * success or fail if not implemented |
|
| 401 | + */ |
|
| 402 | + public function seek($n=0, $continue=null) { |
|
| 403 | + if ($this->func_filtre OR !method_exists($this->iter, 'seek') OR !$this->iter->seek($n)) { |
|
| 404 | + $this->seek_loop($n); |
|
| 405 | + } |
|
| 406 | + $this->pos = $n; |
|
| 407 | + $this->fetched = $n; |
|
| 408 | + return true; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /* |
|
| 412 | 412 | * aller a la position $n en parcourant |
| 413 | 413 | * un par un tous les elements |
| 414 | 414 | */ |
| 415 | - private function seek_loop($n) { |
|
| 416 | - if ($this->pos > $n) |
|
| 417 | - $this->rewind(); |
|
| 418 | - |
|
| 419 | - while ($this->pos < $n AND $this->valid()) { |
|
| 420 | - $this->next(); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return true; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Avancer de $saut pas |
|
| 428 | - * @param $saut |
|
| 429 | - * @param $max |
|
| 430 | - * @return int |
|
| 431 | - */ |
|
| 432 | - public function skip($saut, $max=null){ |
|
| 433 | - // pas de saut en arriere autorise pour cette fonction |
|
| 434 | - if (($saut=intval($saut))<=0) return $this->pos; |
|
| 435 | - $seek = $this->pos + $saut; |
|
| 436 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 437 | - // et on sort |
|
| 438 | - if (is_null($max)) |
|
| 439 | - $max = $this->count(); |
|
| 440 | - |
|
| 441 | - if ($seek>=$max OR $seek>=$this->count()) { |
|
| 442 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 443 | - $this->free(); |
|
| 444 | - return $max; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $this->seek($seek); |
|
| 448 | - return $this->pos; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Renvoyer un tableau des donnees correspondantes |
|
| 453 | - * a la position courante de l'iterateur |
|
| 454 | - * en controlant si on respecte le filtre |
|
| 455 | - * Appliquer aussi le critere {offset,limit} |
|
| 456 | - * |
|
| 457 | - * @return array|bool |
|
| 458 | - */ |
|
| 459 | - public function fetch() { |
|
| 460 | - if (method_exists($this->iter, 'fetch')) { |
|
| 461 | - return $this->iter->fetch(); |
|
| 462 | - } else { |
|
| 463 | - |
|
| 464 | - while ($this->valid() |
|
| 465 | - AND ( |
|
| 466 | - !$this->accept() |
|
| 467 | - OR (isset($this->offset) AND $this->fetched++ < $this->offset) |
|
| 468 | - )) |
|
| 469 | - $this->next(); |
|
| 470 | - |
|
| 471 | - if (!$this->valid()) |
|
| 472 | - return false; |
|
| 473 | - |
|
| 474 | - if (isset($this->limit) |
|
| 475 | - AND $this->fetched > $this->offset + $this->limit) |
|
| 476 | - return false; |
|
| 477 | - |
|
| 478 | - $r = array(); |
|
| 479 | - foreach ($this->select as $nom) { |
|
| 480 | - $r[$nom] = $this->get_select($nom); |
|
| 481 | - } |
|
| 482 | - $this->next(); |
|
| 483 | - return $r; |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - // retourner la cle pour #CLE |
|
| 488 | - public function cle() { |
|
| 489 | - return $this->key(); |
|
| 490 | - } |
|
| 415 | + private function seek_loop($n) { |
|
| 416 | + if ($this->pos > $n) |
|
| 417 | + $this->rewind(); |
|
| 418 | + |
|
| 419 | + while ($this->pos < $n AND $this->valid()) { |
|
| 420 | + $this->next(); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return true; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Avancer de $saut pas |
|
| 428 | + * @param $saut |
|
| 429 | + * @param $max |
|
| 430 | + * @return int |
|
| 431 | + */ |
|
| 432 | + public function skip($saut, $max=null){ |
|
| 433 | + // pas de saut en arriere autorise pour cette fonction |
|
| 434 | + if (($saut=intval($saut))<=0) return $this->pos; |
|
| 435 | + $seek = $this->pos + $saut; |
|
| 436 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 437 | + // et on sort |
|
| 438 | + if (is_null($max)) |
|
| 439 | + $max = $this->count(); |
|
| 440 | + |
|
| 441 | + if ($seek>=$max OR $seek>=$this->count()) { |
|
| 442 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 443 | + $this->free(); |
|
| 444 | + return $max; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $this->seek($seek); |
|
| 448 | + return $this->pos; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Renvoyer un tableau des donnees correspondantes |
|
| 453 | + * a la position courante de l'iterateur |
|
| 454 | + * en controlant si on respecte le filtre |
|
| 455 | + * Appliquer aussi le critere {offset,limit} |
|
| 456 | + * |
|
| 457 | + * @return array|bool |
|
| 458 | + */ |
|
| 459 | + public function fetch() { |
|
| 460 | + if (method_exists($this->iter, 'fetch')) { |
|
| 461 | + return $this->iter->fetch(); |
|
| 462 | + } else { |
|
| 463 | + |
|
| 464 | + while ($this->valid() |
|
| 465 | + AND ( |
|
| 466 | + !$this->accept() |
|
| 467 | + OR (isset($this->offset) AND $this->fetched++ < $this->offset) |
|
| 468 | + )) |
|
| 469 | + $this->next(); |
|
| 470 | + |
|
| 471 | + if (!$this->valid()) |
|
| 472 | + return false; |
|
| 473 | + |
|
| 474 | + if (isset($this->limit) |
|
| 475 | + AND $this->fetched > $this->offset + $this->limit) |
|
| 476 | + return false; |
|
| 477 | + |
|
| 478 | + $r = array(); |
|
| 479 | + foreach ($this->select as $nom) { |
|
| 480 | + $r[$nom] = $this->get_select($nom); |
|
| 481 | + } |
|
| 482 | + $this->next(); |
|
| 483 | + return $r; |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + // retourner la cle pour #CLE |
|
| 488 | + public function cle() { |
|
| 489 | + return $this->key(); |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | - // retourner la valeur pour #VALEUR |
|
| 493 | - public function valeur() { |
|
| 494 | - # attention PHP est mechant avec les objets, parfois il ne les |
|
| 495 | - # clone pas proprement (directoryiterator sous php 5.2.2) |
|
| 496 | - # on se rabat sur la version __toString() |
|
| 497 | - if (is_object($v = $this->current())) { |
|
| 498 | - if (method_exists($v, '__toString')) |
|
| 499 | - $v = $v->__toString(); |
|
| 500 | - else |
|
| 501 | - $v = (array) $v; |
|
| 502 | - } |
|
| 503 | - return $v; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Accepte-t-on l'entree courante lue ? |
|
| 508 | - * On execute les filtres pour le savoir. |
|
| 509 | - **/ |
|
| 510 | - public function accept() { |
|
| 511 | - if ($f = $this->func_filtre) { |
|
| 512 | - return $f($this); |
|
| 513 | - } |
|
| 514 | - return true; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * liberer la ressource |
|
| 519 | - * @return bool |
|
| 520 | - */ |
|
| 521 | - public function free() { |
|
| 522 | - if (method_exists($this->iter, 'free')) { |
|
| 523 | - $this->iter->free(); |
|
| 524 | - } |
|
| 525 | - $this->pos = $this->total = 0; |
|
| 526 | - return true; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Compter le nombre total de resultats |
|
| 531 | - * pour #TOTAL_BOUCLE |
|
| 532 | - * @return int |
|
| 533 | - */ |
|
| 534 | - public function count() { |
|
| 535 | - if (is_null($this->total)) { |
|
| 536 | - if (method_exists($this->iter, 'count') |
|
| 537 | - AND !$this->func_filtre) { |
|
| 538 | - return $this->total = $this->iter->count(); |
|
| 539 | - } else { |
|
| 540 | - // compter les lignes et rembobiner |
|
| 541 | - $total = 0; |
|
| 542 | - $pos = $this->pos; // sauver la position |
|
| 543 | - $this->rewind(); |
|
| 544 | - while ($this->fetch() and $total < $this->max) { |
|
| 545 | - $total++; |
|
| 546 | - } |
|
| 547 | - $this->seek($pos); |
|
| 548 | - $this->total = $total; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - return $this->total; |
|
| 553 | - } |
|
| 492 | + // retourner la valeur pour #VALEUR |
|
| 493 | + public function valeur() { |
|
| 494 | + # attention PHP est mechant avec les objets, parfois il ne les |
|
| 495 | + # clone pas proprement (directoryiterator sous php 5.2.2) |
|
| 496 | + # on se rabat sur la version __toString() |
|
| 497 | + if (is_object($v = $this->current())) { |
|
| 498 | + if (method_exists($v, '__toString')) |
|
| 499 | + $v = $v->__toString(); |
|
| 500 | + else |
|
| 501 | + $v = (array) $v; |
|
| 502 | + } |
|
| 503 | + return $v; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Accepte-t-on l'entree courante lue ? |
|
| 508 | + * On execute les filtres pour le savoir. |
|
| 509 | + **/ |
|
| 510 | + public function accept() { |
|
| 511 | + if ($f = $this->func_filtre) { |
|
| 512 | + return $f($this); |
|
| 513 | + } |
|
| 514 | + return true; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * liberer la ressource |
|
| 519 | + * @return bool |
|
| 520 | + */ |
|
| 521 | + public function free() { |
|
| 522 | + if (method_exists($this->iter, 'free')) { |
|
| 523 | + $this->iter->free(); |
|
| 524 | + } |
|
| 525 | + $this->pos = $this->total = 0; |
|
| 526 | + return true; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Compter le nombre total de resultats |
|
| 531 | + * pour #TOTAL_BOUCLE |
|
| 532 | + * @return int |
|
| 533 | + */ |
|
| 534 | + public function count() { |
|
| 535 | + if (is_null($this->total)) { |
|
| 536 | + if (method_exists($this->iter, 'count') |
|
| 537 | + AND !$this->func_filtre) { |
|
| 538 | + return $this->total = $this->iter->count(); |
|
| 539 | + } else { |
|
| 540 | + // compter les lignes et rembobiner |
|
| 541 | + $total = 0; |
|
| 542 | + $pos = $this->pos; // sauver la position |
|
| 543 | + $this->rewind(); |
|
| 544 | + while ($this->fetch() and $total < $this->max) { |
|
| 545 | + $total++; |
|
| 546 | + } |
|
| 547 | + $this->seek($pos); |
|
| 548 | + $this->total = $total; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $this->total; |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | 555 | } |
| 556 | 556 | |
@@ -24,28 +24,28 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function action_editer_objet_dist($id=null, $objet=null, $set=null) { |
| 26 | 26 | |
| 27 | - // appel direct depuis une url interdit |
|
| 28 | - if (is_null($id) OR is_null($objet)){ |
|
| 29 | - include_spip('inc/minipres'); |
|
| 30 | - echo minipres(_T('info_acces_interdit')); |
|
| 31 | - die(); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - // si id n'est pas un nombre, c'est une creation |
|
| 35 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 36 | - if (!$id = intval($id)) { |
|
| 37 | - // on ne sait pas si un parent existe mais on essaye |
|
| 38 | - $id_parent = _request('id_parent'); |
|
| 39 | - $id = objet_inserer($objet, $id_parent); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if (!($id = intval($id))>0) |
|
| 43 | - return array($id,_L('echec enregistrement en base')); |
|
| 44 | - |
|
| 45 | - // Enregistre l'envoi dans la BD |
|
| 46 | - $err = objet_modifier($objet, $id, $set); |
|
| 47 | - |
|
| 48 | - return array($id,$err); |
|
| 27 | + // appel direct depuis une url interdit |
|
| 28 | + if (is_null($id) OR is_null($objet)){ |
|
| 29 | + include_spip('inc/minipres'); |
|
| 30 | + echo minipres(_T('info_acces_interdit')); |
|
| 31 | + die(); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + // si id n'est pas un nombre, c'est une creation |
|
| 35 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 36 | + if (!$id = intval($id)) { |
|
| 37 | + // on ne sait pas si un parent existe mais on essaye |
|
| 38 | + $id_parent = _request('id_parent'); |
|
| 39 | + $id = objet_inserer($objet, $id_parent); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if (!($id = intval($id))>0) |
|
| 43 | + return array($id,_L('echec enregistrement en base')); |
|
| 44 | + |
|
| 45 | + // Enregistre l'envoi dans la BD |
|
| 46 | + $err = objet_modifier($objet, $id, $set); |
|
| 47 | + |
|
| 48 | + return array($id,$err); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -58,71 +58,71 @@ discard block |
||
| 58 | 58 | * @return mixed|string |
| 59 | 59 | */ |
| 60 | 60 | function objet_modifier($objet, $id, $set=null) { |
| 61 | - if (include_spip('action/editer_'.$objet) |
|
| 62 | - AND function_exists($modifier = $objet."_modifier")) |
|
| 63 | - return $modifier($id,$set); |
|
| 64 | - |
|
| 65 | - $table_sql = table_objet_sql($objet); |
|
| 66 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 67 | - $desc = $trouver_table($table_sql); |
|
| 68 | - if (!$desc OR !isset($desc['field'])) { |
|
| 69 | - spip_log("Objet $objet inconnu dans objet_modifier",_LOG_ERREUR); |
|
| 70 | - return _L("Erreur objet $objet inconnu"); |
|
| 71 | - } |
|
| 72 | - include_spip('inc/modifier'); |
|
| 73 | - |
|
| 74 | - $champ_date = ''; |
|
| 75 | - if (isset($desc['date']) AND $desc['date']) |
|
| 76 | - $champ_date = $desc['date']; |
|
| 77 | - elseif (isset($desc['field']['date'])) |
|
| 78 | - $champ_date = 'date'; |
|
| 79 | - |
|
| 80 | - $white = array_keys($desc['field']); |
|
| 81 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 82 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 83 | - $white = array_diff($white, array($desc['key']['PRIMARY KEY'])); |
|
| 84 | - |
|
| 85 | - if (isset($desc['champs_editables']) AND is_array($desc['champs_editables'])) { |
|
| 86 | - $white = $desc['champs_editables']; |
|
| 87 | - } |
|
| 88 | - $c = collecter_requests( |
|
| 89 | - // white list |
|
| 90 | - $white, |
|
| 91 | - // black list |
|
| 92 | - array($champ_date,'statut','id_parent','id_secteur'), |
|
| 93 | - // donnees eventuellement fournies |
|
| 94 | - $set |
|
| 95 | - ); |
|
| 96 | - |
|
| 97 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 98 | - if (objet_test_si_publie($objet,$id)){ |
|
| 99 | - $invalideur = "id='$objet/$id'"; |
|
| 100 | - $indexation = true; |
|
| 101 | - } |
|
| 102 | - else { |
|
| 103 | - $invalideur = ""; |
|
| 104 | - $indexation = false; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ($err = objet_modifier_champs($objet, $id, |
|
| 108 | - array( |
|
| 109 | - 'data' => $set, |
|
| 110 | - 'nonvide' => '', |
|
| 111 | - 'invalideur' => $invalideur, |
|
| 112 | - 'indexation' => $indexation, |
|
| 113 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 114 | - 'date_modif' => (isset($desc['field']['date_modif'])?'date_modif':'') |
|
| 115 | - ), |
|
| 116 | - $c)) |
|
| 117 | - return $err; |
|
| 118 | - |
|
| 119 | - // Modification de statut, changement de rubrique ? |
|
| 120 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 121 | - // le tableau $set hors black liste, mais du coup on a possiblement des champs en trop. |
|
| 122 | - $c = collecter_requests(array($champ_date, 'statut', 'id_parent'),array(),$set); |
|
| 123 | - $err = objet_instituer($objet, $id, $c); |
|
| 124 | - |
|
| 125 | - return $err; |
|
| 61 | + if (include_spip('action/editer_'.$objet) |
|
| 62 | + AND function_exists($modifier = $objet."_modifier")) |
|
| 63 | + return $modifier($id,$set); |
|
| 64 | + |
|
| 65 | + $table_sql = table_objet_sql($objet); |
|
| 66 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 67 | + $desc = $trouver_table($table_sql); |
|
| 68 | + if (!$desc OR !isset($desc['field'])) { |
|
| 69 | + spip_log("Objet $objet inconnu dans objet_modifier",_LOG_ERREUR); |
|
| 70 | + return _L("Erreur objet $objet inconnu"); |
|
| 71 | + } |
|
| 72 | + include_spip('inc/modifier'); |
|
| 73 | + |
|
| 74 | + $champ_date = ''; |
|
| 75 | + if (isset($desc['date']) AND $desc['date']) |
|
| 76 | + $champ_date = $desc['date']; |
|
| 77 | + elseif (isset($desc['field']['date'])) |
|
| 78 | + $champ_date = 'date'; |
|
| 79 | + |
|
| 80 | + $white = array_keys($desc['field']); |
|
| 81 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 82 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 83 | + $white = array_diff($white, array($desc['key']['PRIMARY KEY'])); |
|
| 84 | + |
|
| 85 | + if (isset($desc['champs_editables']) AND is_array($desc['champs_editables'])) { |
|
| 86 | + $white = $desc['champs_editables']; |
|
| 87 | + } |
|
| 88 | + $c = collecter_requests( |
|
| 89 | + // white list |
|
| 90 | + $white, |
|
| 91 | + // black list |
|
| 92 | + array($champ_date,'statut','id_parent','id_secteur'), |
|
| 93 | + // donnees eventuellement fournies |
|
| 94 | + $set |
|
| 95 | + ); |
|
| 96 | + |
|
| 97 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 98 | + if (objet_test_si_publie($objet,$id)){ |
|
| 99 | + $invalideur = "id='$objet/$id'"; |
|
| 100 | + $indexation = true; |
|
| 101 | + } |
|
| 102 | + else { |
|
| 103 | + $invalideur = ""; |
|
| 104 | + $indexation = false; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ($err = objet_modifier_champs($objet, $id, |
|
| 108 | + array( |
|
| 109 | + 'data' => $set, |
|
| 110 | + 'nonvide' => '', |
|
| 111 | + 'invalideur' => $invalideur, |
|
| 112 | + 'indexation' => $indexation, |
|
| 113 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 114 | + 'date_modif' => (isset($desc['field']['date_modif'])?'date_modif':'') |
|
| 115 | + ), |
|
| 116 | + $c)) |
|
| 117 | + return $err; |
|
| 118 | + |
|
| 119 | + // Modification de statut, changement de rubrique ? |
|
| 120 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 121 | + // le tableau $set hors black liste, mais du coup on a possiblement des champs en trop. |
|
| 122 | + $c = collecter_requests(array($champ_date, 'statut', 'id_parent'),array(),$set); |
|
| 123 | + $err = objet_instituer($objet, $id, $c); |
|
| 124 | + |
|
| 125 | + return $err; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -133,108 +133,108 @@ discard block |
||
| 133 | 133 | * @return bool|int |
| 134 | 134 | */ |
| 135 | 135 | function objet_inserer($objet, $id_parent=null, $set=null) { |
| 136 | - if (include_spip('action/editer_'.$objet) |
|
| 137 | - AND function_exists($inserer = $objet."_inserer")) |
|
| 138 | - return $inserer($id_parent); |
|
| 139 | - |
|
| 140 | - $table_sql = table_objet_sql($objet); |
|
| 141 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 142 | - $desc = $trouver_table($table_sql); |
|
| 143 | - if (!$desc OR !isset($desc['field'])) |
|
| 144 | - return 0; |
|
| 145 | - |
|
| 146 | - $lang_rub = ""; |
|
| 147 | - $champs = array(); |
|
| 148 | - if (isset($desc['field']['id_rubrique'])){ |
|
| 149 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 150 | - // dans la premiere rubrique racine |
|
| 151 | - if (!$id_rubrique = intval($id_parent)) { |
|
| 152 | - $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1"); |
|
| 153 | - $id_rubrique = $row['id_rubrique']; |
|
| 154 | - } |
|
| 155 | - else |
|
| 156 | - $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=".intval($id_rubrique)); |
|
| 157 | - |
|
| 158 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 159 | - if (isset($desc['field']['id_secteur'])) |
|
| 160 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 161 | - $lang_rub = $row['lang']; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 165 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 166 | - // ou a defaut celle de la rubrique |
|
| 167 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 168 | - if (isset($desc['field']['lang']) AND $GLOBALS['meta']['multi_objets'] AND in_array($table_sql, explode(',', $GLOBALS['meta']['multi_objets']))) { |
|
| 169 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 170 | - if (in_array($GLOBALS['spip_lang'], |
|
| 171 | - explode(',', $GLOBALS['meta']['langues_multilingue']))) { |
|
| 172 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 173 | - if (isset($desc['field']['langue_choisie'])) |
|
| 174 | - $champs['langue_choisie'] = 'oui'; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - elseif (isset($desc['field']['lang']) AND isset($desc['field']['langue_choisie'])) { |
|
| 178 | - $champs['lang'] = ($lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']); |
|
| 179 | - $champs['langue_choisie'] = 'non'; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($desc['field']['statut'])){ |
|
| 183 | - if (isset($desc['statut_textes_instituer'])){ |
|
| 184 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 185 | - $champs['statut'] = reset($cles_statut); |
|
| 186 | - } |
|
| 187 | - else |
|
| 188 | - $champs['statut'] = 'prepa'; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - if ((isset($desc['date']) AND $d=$desc['date']) OR isset($desc['field'][$d='date'])) |
|
| 193 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 194 | - |
|
| 195 | - if ($set) |
|
| 196 | - $champs = array_merge($champs, $set); |
|
| 197 | - |
|
| 198 | - // Envoyer aux plugins |
|
| 199 | - $champs = pipeline('pre_insertion', |
|
| 200 | - array( |
|
| 201 | - 'args' => array( |
|
| 202 | - 'table' => $table_sql, |
|
| 203 | - ), |
|
| 204 | - 'data' => $champs |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - |
|
| 208 | - $id = sql_insertq($table_sql, $champs); |
|
| 209 | - |
|
| 210 | - if ($id){ |
|
| 211 | - pipeline('post_insertion', |
|
| 212 | - array( |
|
| 213 | - 'args' => array( |
|
| 214 | - 'table' => $table_sql, |
|
| 215 | - 'id_objet' => $id, |
|
| 216 | - ), |
|
| 217 | - 'data' => $champs |
|
| 218 | - ) |
|
| 219 | - ); |
|
| 220 | - |
|
| 221 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 222 | - // et associer l'auteur sinon |
|
| 223 | - // si la table n'a pas deja un champ id_auteur |
|
| 224 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 225 | - if ($id > 0 |
|
| 226 | - AND !isset($desc['field']['id_auteur'])){ |
|
| 227 | - $id_auteur = ((is_null(_request('id_auteur')) AND isset($GLOBALS['visiteur_session']['id_auteur']))? |
|
| 228 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 229 | - :_request('id_auteur')); |
|
| 230 | - if ($id_auteur) { |
|
| 231 | - include_spip('action/editer_auteur'); |
|
| 232 | - auteur_associer($id_auteur, array($objet=>$id)); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return $id; |
|
| 136 | + if (include_spip('action/editer_'.$objet) |
|
| 137 | + AND function_exists($inserer = $objet."_inserer")) |
|
| 138 | + return $inserer($id_parent); |
|
| 139 | + |
|
| 140 | + $table_sql = table_objet_sql($objet); |
|
| 141 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 142 | + $desc = $trouver_table($table_sql); |
|
| 143 | + if (!$desc OR !isset($desc['field'])) |
|
| 144 | + return 0; |
|
| 145 | + |
|
| 146 | + $lang_rub = ""; |
|
| 147 | + $champs = array(); |
|
| 148 | + if (isset($desc['field']['id_rubrique'])){ |
|
| 149 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 150 | + // dans la premiere rubrique racine |
|
| 151 | + if (!$id_rubrique = intval($id_parent)) { |
|
| 152 | + $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1"); |
|
| 153 | + $id_rubrique = $row['id_rubrique']; |
|
| 154 | + } |
|
| 155 | + else |
|
| 156 | + $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=".intval($id_rubrique)); |
|
| 157 | + |
|
| 158 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 159 | + if (isset($desc['field']['id_secteur'])) |
|
| 160 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 161 | + $lang_rub = $row['lang']; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 165 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 166 | + // ou a defaut celle de la rubrique |
|
| 167 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 168 | + if (isset($desc['field']['lang']) AND $GLOBALS['meta']['multi_objets'] AND in_array($table_sql, explode(',', $GLOBALS['meta']['multi_objets']))) { |
|
| 169 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 170 | + if (in_array($GLOBALS['spip_lang'], |
|
| 171 | + explode(',', $GLOBALS['meta']['langues_multilingue']))) { |
|
| 172 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 173 | + if (isset($desc['field']['langue_choisie'])) |
|
| 174 | + $champs['langue_choisie'] = 'oui'; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + elseif (isset($desc['field']['lang']) AND isset($desc['field']['langue_choisie'])) { |
|
| 178 | + $champs['lang'] = ($lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']); |
|
| 179 | + $champs['langue_choisie'] = 'non'; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($desc['field']['statut'])){ |
|
| 183 | + if (isset($desc['statut_textes_instituer'])){ |
|
| 184 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 185 | + $champs['statut'] = reset($cles_statut); |
|
| 186 | + } |
|
| 187 | + else |
|
| 188 | + $champs['statut'] = 'prepa'; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + if ((isset($desc['date']) AND $d=$desc['date']) OR isset($desc['field'][$d='date'])) |
|
| 193 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 194 | + |
|
| 195 | + if ($set) |
|
| 196 | + $champs = array_merge($champs, $set); |
|
| 197 | + |
|
| 198 | + // Envoyer aux plugins |
|
| 199 | + $champs = pipeline('pre_insertion', |
|
| 200 | + array( |
|
| 201 | + 'args' => array( |
|
| 202 | + 'table' => $table_sql, |
|
| 203 | + ), |
|
| 204 | + 'data' => $champs |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + |
|
| 208 | + $id = sql_insertq($table_sql, $champs); |
|
| 209 | + |
|
| 210 | + if ($id){ |
|
| 211 | + pipeline('post_insertion', |
|
| 212 | + array( |
|
| 213 | + 'args' => array( |
|
| 214 | + 'table' => $table_sql, |
|
| 215 | + 'id_objet' => $id, |
|
| 216 | + ), |
|
| 217 | + 'data' => $champs |
|
| 218 | + ) |
|
| 219 | + ); |
|
| 220 | + |
|
| 221 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 222 | + // et associer l'auteur sinon |
|
| 223 | + // si la table n'a pas deja un champ id_auteur |
|
| 224 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 225 | + if ($id > 0 |
|
| 226 | + AND !isset($desc['field']['id_auteur'])){ |
|
| 227 | + $id_auteur = ((is_null(_request('id_auteur')) AND isset($GLOBALS['visiteur_session']['id_auteur']))? |
|
| 228 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 229 | + :_request('id_auteur')); |
|
| 230 | + if ($id_auteur) { |
|
| 231 | + include_spip('action/editer_auteur'); |
|
| 232 | + auteur_associer($id_auteur, array($objet=>$id)); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return $id; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
@@ -250,114 +250,114 @@ discard block |
||
| 250 | 250 | * @return mixed|string |
| 251 | 251 | */ |
| 252 | 252 | function objet_instituer($objet, $id, $c, $calcul_rub=true) { |
| 253 | - if (include_spip('action/editer_'.$objet) |
|
| 254 | - AND function_exists($instituer = $objet."_instituer")) |
|
| 255 | - return $instituer($id,$c,$calcul_rub); |
|
| 256 | - |
|
| 257 | - $table_sql = table_objet_sql($objet); |
|
| 258 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 259 | - $desc = $trouver_table($table_sql); |
|
| 260 | - if (!$desc OR !isset($desc['field'])) |
|
| 261 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 262 | - |
|
| 263 | - include_spip('inc/autoriser'); |
|
| 264 | - include_spip('inc/rubriques'); |
|
| 265 | - include_spip('inc/modifier'); |
|
| 266 | - |
|
| 267 | - $sel = array(); |
|
| 268 | - $sel[] = (isset($desc['field']['statut'])?"statut":"'' as statut"); |
|
| 269 | - |
|
| 270 | - $champ_date = ''; |
|
| 271 | - if (isset($desc['date']) AND $desc['date']) |
|
| 272 | - $champ_date = $desc['date']; |
|
| 273 | - elseif (isset($desc['field']['date'])) |
|
| 274 | - $champ_date = 'date'; |
|
| 275 | - |
|
| 276 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 277 | - $sel[] = (isset($desc['field']['id_rubrique'])?'id_rubrique':"0 as id_rubrique"); |
|
| 278 | - |
|
| 279 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet).'='.intval($id)); |
|
| 280 | - |
|
| 281 | - $id_rubrique = $row['id_rubrique']; |
|
| 282 | - $statut_ancien = $statut = $row['statut']; |
|
| 283 | - $date_ancienne = $date = $row['date']; |
|
| 284 | - $champs = array(); |
|
| 285 | - |
|
| 286 | - $d = ($date AND isset($c[$champ_date]))?$c[$champ_date]:null; |
|
| 287 | - $s = (isset($desc['field']['statut']) AND isset($c['statut']))?$c['statut']:$statut; |
|
| 288 | - |
|
| 289 | - // cf autorisations dans inc/instituer_objet |
|
| 290 | - if ($s != $statut OR ($d AND $d != $date)) { |
|
| 291 | - if ($id_rubrique ? |
|
| 292 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 293 | - : |
|
| 294 | - autoriser('instituer', $objet, $id, null, array('statut'=>$s)) |
|
| 295 | - ) |
|
| 296 | - $statut = $champs['statut'] = $s; |
|
| 297 | - else if ($s!='publie' AND autoriser('modifier', $objet, $id)) |
|
| 298 | - $statut = $champs['statut'] = $s; |
|
| 299 | - else |
|
| 300 | - spip_log("editer_objet $id refus " . join(' ', $c)); |
|
| 301 | - |
|
| 302 | - // En cas de publication, fixer la date a "maintenant" |
|
| 303 | - // sauf si $c commande autre chose |
|
| 304 | - // ou si l'objet est deja date dans le futur |
|
| 305 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 306 | - if ($champ_date) { |
|
| 307 | - if ($champs['statut'] == 'publie' |
|
| 308 | - OR ($champs['statut'] == 'prop' AND !in_array($statut_ancien, array('publie', 'prop'))) |
|
| 309 | - OR $d |
|
| 310 | - ) { |
|
| 311 | - if ($d OR strtotime($d=$date)>time()) |
|
| 312 | - $champs[$champ_date] = $date = $d; |
|
| 313 | - else |
|
| 314 | - $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // Verifier que la rubrique demandee existe et est differente |
|
| 320 | - // de la rubrique actuelle |
|
| 321 | - if ($id_rubrique |
|
| 322 | - AND $id_parent = $c['id_parent'] |
|
| 323 | - AND $id_parent != $id_rubrique |
|
| 324 | - AND (sql_fetsel('1', "spip_rubriques", "id_rubrique=".intval($id_parent)))) { |
|
| 325 | - $champs['id_rubrique'] = $id_parent; |
|
| 326 | - |
|
| 327 | - // si l'objet etait publie |
|
| 328 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 329 | - // repasser l'objet en statut 'propose'. |
|
| 330 | - if ($statut == 'publie' |
|
| 331 | - AND !autoriser('publierdans', 'rubrique', $id_rubrique)) |
|
| 332 | - $champs['statut'] = 'prop'; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - // Envoyer aux plugins |
|
| 337 | - $champs = pipeline('pre_edition', |
|
| 338 | - array( |
|
| 339 | - 'args' => array( |
|
| 340 | - 'table' => $table_sql, |
|
| 341 | - 'id_objet' => $id, |
|
| 342 | - 'action'=>'instituer', |
|
| 343 | - 'statut_ancien' => $statut_ancien, |
|
| 344 | - 'date_ancienne' => $date_ancienne, |
|
| 345 | - 'id_parent_ancien' => $id_rubrique, |
|
| 346 | - ), |
|
| 347 | - 'data' => $champs |
|
| 348 | - ) |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - if (!count($champs)) return ''; |
|
| 352 | - |
|
| 353 | - // Envoyer les modifs. |
|
| 354 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 355 | - |
|
| 356 | - // Invalider les caches |
|
| 357 | - include_spip('inc/invalideur'); |
|
| 358 | - suivre_invalideur("id='$objet/$id'"); |
|
| 359 | - |
|
| 360 | - /* |
|
| 253 | + if (include_spip('action/editer_'.$objet) |
|
| 254 | + AND function_exists($instituer = $objet."_instituer")) |
|
| 255 | + return $instituer($id,$c,$calcul_rub); |
|
| 256 | + |
|
| 257 | + $table_sql = table_objet_sql($objet); |
|
| 258 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 259 | + $desc = $trouver_table($table_sql); |
|
| 260 | + if (!$desc OR !isset($desc['field'])) |
|
| 261 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 262 | + |
|
| 263 | + include_spip('inc/autoriser'); |
|
| 264 | + include_spip('inc/rubriques'); |
|
| 265 | + include_spip('inc/modifier'); |
|
| 266 | + |
|
| 267 | + $sel = array(); |
|
| 268 | + $sel[] = (isset($desc['field']['statut'])?"statut":"'' as statut"); |
|
| 269 | + |
|
| 270 | + $champ_date = ''; |
|
| 271 | + if (isset($desc['date']) AND $desc['date']) |
|
| 272 | + $champ_date = $desc['date']; |
|
| 273 | + elseif (isset($desc['field']['date'])) |
|
| 274 | + $champ_date = 'date'; |
|
| 275 | + |
|
| 276 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 277 | + $sel[] = (isset($desc['field']['id_rubrique'])?'id_rubrique':"0 as id_rubrique"); |
|
| 278 | + |
|
| 279 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet).'='.intval($id)); |
|
| 280 | + |
|
| 281 | + $id_rubrique = $row['id_rubrique']; |
|
| 282 | + $statut_ancien = $statut = $row['statut']; |
|
| 283 | + $date_ancienne = $date = $row['date']; |
|
| 284 | + $champs = array(); |
|
| 285 | + |
|
| 286 | + $d = ($date AND isset($c[$champ_date]))?$c[$champ_date]:null; |
|
| 287 | + $s = (isset($desc['field']['statut']) AND isset($c['statut']))?$c['statut']:$statut; |
|
| 288 | + |
|
| 289 | + // cf autorisations dans inc/instituer_objet |
|
| 290 | + if ($s != $statut OR ($d AND $d != $date)) { |
|
| 291 | + if ($id_rubrique ? |
|
| 292 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 293 | + : |
|
| 294 | + autoriser('instituer', $objet, $id, null, array('statut'=>$s)) |
|
| 295 | + ) |
|
| 296 | + $statut = $champs['statut'] = $s; |
|
| 297 | + else if ($s!='publie' AND autoriser('modifier', $objet, $id)) |
|
| 298 | + $statut = $champs['statut'] = $s; |
|
| 299 | + else |
|
| 300 | + spip_log("editer_objet $id refus " . join(' ', $c)); |
|
| 301 | + |
|
| 302 | + // En cas de publication, fixer la date a "maintenant" |
|
| 303 | + // sauf si $c commande autre chose |
|
| 304 | + // ou si l'objet est deja date dans le futur |
|
| 305 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 306 | + if ($champ_date) { |
|
| 307 | + if ($champs['statut'] == 'publie' |
|
| 308 | + OR ($champs['statut'] == 'prop' AND !in_array($statut_ancien, array('publie', 'prop'))) |
|
| 309 | + OR $d |
|
| 310 | + ) { |
|
| 311 | + if ($d OR strtotime($d=$date)>time()) |
|
| 312 | + $champs[$champ_date] = $date = $d; |
|
| 313 | + else |
|
| 314 | + $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // Verifier que la rubrique demandee existe et est differente |
|
| 320 | + // de la rubrique actuelle |
|
| 321 | + if ($id_rubrique |
|
| 322 | + AND $id_parent = $c['id_parent'] |
|
| 323 | + AND $id_parent != $id_rubrique |
|
| 324 | + AND (sql_fetsel('1', "spip_rubriques", "id_rubrique=".intval($id_parent)))) { |
|
| 325 | + $champs['id_rubrique'] = $id_parent; |
|
| 326 | + |
|
| 327 | + // si l'objet etait publie |
|
| 328 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 329 | + // repasser l'objet en statut 'propose'. |
|
| 330 | + if ($statut == 'publie' |
|
| 331 | + AND !autoriser('publierdans', 'rubrique', $id_rubrique)) |
|
| 332 | + $champs['statut'] = 'prop'; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + // Envoyer aux plugins |
|
| 337 | + $champs = pipeline('pre_edition', |
|
| 338 | + array( |
|
| 339 | + 'args' => array( |
|
| 340 | + 'table' => $table_sql, |
|
| 341 | + 'id_objet' => $id, |
|
| 342 | + 'action'=>'instituer', |
|
| 343 | + 'statut_ancien' => $statut_ancien, |
|
| 344 | + 'date_ancienne' => $date_ancienne, |
|
| 345 | + 'id_parent_ancien' => $id_rubrique, |
|
| 346 | + ), |
|
| 347 | + 'data' => $champs |
|
| 348 | + ) |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + if (!count($champs)) return ''; |
|
| 352 | + |
|
| 353 | + // Envoyer les modifs. |
|
| 354 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 355 | + |
|
| 356 | + // Invalider les caches |
|
| 357 | + include_spip('inc/invalideur'); |
|
| 358 | + suivre_invalideur("id='$objet/$id'"); |
|
| 359 | + |
|
| 360 | + /* |
|
| 361 | 361 | if ($date) { |
| 362 | 362 | $t = strtotime($date); |
| 363 | 363 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -366,29 +366,29 @@ discard block |
||
| 366 | 366 | } |
| 367 | 367 | }*/ |
| 368 | 368 | |
| 369 | - // Pipeline |
|
| 370 | - pipeline('post_edition', |
|
| 371 | - array( |
|
| 372 | - 'args' => array( |
|
| 373 | - 'table' => $table_sql, |
|
| 374 | - 'id_objet' => $id, |
|
| 375 | - 'action'=>'instituer', |
|
| 376 | - 'statut_ancien' => $statut_ancien, |
|
| 377 | - 'date_ancienne' => $date_ancienne, |
|
| 378 | - 'id_parent_ancien' => $id_rubrique, |
|
| 379 | - ), |
|
| 380 | - 'data' => $champs |
|
| 381 | - ) |
|
| 382 | - ); |
|
| 383 | - |
|
| 384 | - // Notifications |
|
| 385 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 386 | - $notifications("instituer$objet", $id, |
|
| 387 | - array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date'=>$date, 'date_ancienne' => $date_ancienne) |
|
| 388 | - ); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - return ''; // pas d'erreur |
|
| 369 | + // Pipeline |
|
| 370 | + pipeline('post_edition', |
|
| 371 | + array( |
|
| 372 | + 'args' => array( |
|
| 373 | + 'table' => $table_sql, |
|
| 374 | + 'id_objet' => $id, |
|
| 375 | + 'action'=>'instituer', |
|
| 376 | + 'statut_ancien' => $statut_ancien, |
|
| 377 | + 'date_ancienne' => $date_ancienne, |
|
| 378 | + 'id_parent_ancien' => $id_rubrique, |
|
| 379 | + ), |
|
| 380 | + 'data' => $champs |
|
| 381 | + ) |
|
| 382 | + ); |
|
| 383 | + |
|
| 384 | + // Notifications |
|
| 385 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 386 | + $notifications("instituer$objet", $id, |
|
| 387 | + array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date'=>$date, 'date_ancienne' => $date_ancienne) |
|
| 388 | + ); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + return ''; // pas d'erreur |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -403,36 +403,36 @@ discard block |
||
| 403 | 403 | * @return |
| 404 | 404 | */ |
| 405 | 405 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond=true) { |
| 406 | - $table_sql = table_objet_sql($objet); |
|
| 407 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 408 | - $desc = $trouver_table($table_sql); |
|
| 409 | - |
|
| 410 | - // Si on deplace l'objet |
|
| 411 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 412 | - if (isset($champs['id_rubrique'])) { |
|
| 413 | - |
|
| 414 | - $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=".sql_quote($champs['id_rubrique'])); |
|
| 415 | - $langue = $row_rub['lang']; |
|
| 416 | - |
|
| 417 | - if (isset($desc['field']['id_secteur'])) |
|
| 418 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 419 | - |
|
| 420 | - if (isset($desc['field']['lang']) AND isset($desc['field']['langue_choisie'])) |
|
| 421 | - if (sql_fetsel('1', $table_sql, id_table_objet($objet)."=".intval($id)." AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) { |
|
| 422 | - $champs['lang'] = $langue; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - if (!$champs) return; |
|
| 427 | - sql_updateq($table_sql, $champs, id_table_objet($objet).'='.intval($id)); |
|
| 428 | - |
|
| 429 | - // Changer le statut des rubriques concernees |
|
| 430 | - if ($cond) { |
|
| 431 | - include_spip('inc/rubriques'); |
|
| 432 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 433 | - $postdate = false; |
|
| 434 | - calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate); |
|
| 435 | - } |
|
| 406 | + $table_sql = table_objet_sql($objet); |
|
| 407 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 408 | + $desc = $trouver_table($table_sql); |
|
| 409 | + |
|
| 410 | + // Si on deplace l'objet |
|
| 411 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 412 | + if (isset($champs['id_rubrique'])) { |
|
| 413 | + |
|
| 414 | + $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=".sql_quote($champs['id_rubrique'])); |
|
| 415 | + $langue = $row_rub['lang']; |
|
| 416 | + |
|
| 417 | + if (isset($desc['field']['id_secteur'])) |
|
| 418 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 419 | + |
|
| 420 | + if (isset($desc['field']['lang']) AND isset($desc['field']['langue_choisie'])) |
|
| 421 | + if (sql_fetsel('1', $table_sql, id_table_objet($objet)."=".intval($id)." AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) { |
|
| 422 | + $champs['lang'] = $langue; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + if (!$champs) return; |
|
| 427 | + sql_updateq($table_sql, $champs, id_table_objet($objet).'='.intval($id)); |
|
| 428 | + |
|
| 429 | + // Changer le statut des rubriques concernees |
|
| 430 | + if ($cond) { |
|
| 431 | + include_spip('inc/rubriques'); |
|
| 432 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 433 | + $postdate = false; |
|
| 434 | + calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate); |
|
| 435 | + } |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | ?> |
@@ -30,62 +30,62 @@ discard block |
||
| 30 | 30 | * @return array|string |
| 31 | 31 | */ |
| 32 | 32 | function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = array()){ |
| 33 | - if (!is_array($options)) |
|
| 34 | - $options = array('id'=>$options); |
|
| 35 | - |
|
| 36 | - if (function_exists('test_inscription')) |
|
| 37 | - $f = 'test_inscription'; |
|
| 38 | - else $f = 'test_inscription_dist'; |
|
| 39 | - $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 40 | - |
|
| 41 | - // erreur ? |
|
| 42 | - if (!is_array($desc)) |
|
| 43 | - return _T($desc); |
|
| 44 | - |
|
| 45 | - include_spip('base/abstract_sql'); |
|
| 46 | - $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email'])); |
|
| 47 | - // erreur ? |
|
| 48 | - if (!$res) |
|
| 49 | - return _T('titre_probleme_technique'); |
|
| 50 | - |
|
| 51 | - $row = sql_fetch($res); |
|
| 52 | - sql_free($res); |
|
| 53 | - if ($row){ |
|
| 54 | - if (isset($options['force_nouveau']) AND $options['force_nouveau']==true){ |
|
| 55 | - $desc['id_auteur'] = $row['id_auteur']; |
|
| 56 | - $desc = inscription_nouveau($desc); |
|
| 57 | - } |
|
| 58 | - else |
|
| 59 | - $desc = $row; |
|
| 60 | - } |
|
| 61 | - else |
|
| 62 | - // s'il n'existe pas deja, creer les identifiants |
|
| 63 | - $desc = inscription_nouveau($desc); |
|
| 64 | - |
|
| 65 | - // erreur ? |
|
| 66 | - if (!is_array($desc)) |
|
| 67 | - return $desc; |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 71 | - $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 72 | - |
|
| 73 | - // attribuer un jeton pour confirmation par clic sur un lien |
|
| 74 | - $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 75 | - |
|
| 76 | - // charger de suite cette fonction, pour ses utilitaires |
|
| 77 | - $envoyer_inscription = charger_fonction("envoyer_inscription",""); |
|
| 78 | - list($sujet,$msg,$from,$head) = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 79 | - |
|
| 80 | - $notifications = charger_fonction('notifications', 'inc'); |
|
| 81 | - notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 82 | - |
|
| 83 | - // Notifications |
|
| 84 | - $notifications('inscription', $desc['id_auteur'], |
|
| 85 | - array('nom' => $desc['nom'], 'email' => $desc['email']) |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - return $desc; |
|
| 33 | + if (!is_array($options)) |
|
| 34 | + $options = array('id'=>$options); |
|
| 35 | + |
|
| 36 | + if (function_exists('test_inscription')) |
|
| 37 | + $f = 'test_inscription'; |
|
| 38 | + else $f = 'test_inscription_dist'; |
|
| 39 | + $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 40 | + |
|
| 41 | + // erreur ? |
|
| 42 | + if (!is_array($desc)) |
|
| 43 | + return _T($desc); |
|
| 44 | + |
|
| 45 | + include_spip('base/abstract_sql'); |
|
| 46 | + $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email'])); |
|
| 47 | + // erreur ? |
|
| 48 | + if (!$res) |
|
| 49 | + return _T('titre_probleme_technique'); |
|
| 50 | + |
|
| 51 | + $row = sql_fetch($res); |
|
| 52 | + sql_free($res); |
|
| 53 | + if ($row){ |
|
| 54 | + if (isset($options['force_nouveau']) AND $options['force_nouveau']==true){ |
|
| 55 | + $desc['id_auteur'] = $row['id_auteur']; |
|
| 56 | + $desc = inscription_nouveau($desc); |
|
| 57 | + } |
|
| 58 | + else |
|
| 59 | + $desc = $row; |
|
| 60 | + } |
|
| 61 | + else |
|
| 62 | + // s'il n'existe pas deja, creer les identifiants |
|
| 63 | + $desc = inscription_nouveau($desc); |
|
| 64 | + |
|
| 65 | + // erreur ? |
|
| 66 | + if (!is_array($desc)) |
|
| 67 | + return $desc; |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 71 | + $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 72 | + |
|
| 73 | + // attribuer un jeton pour confirmation par clic sur un lien |
|
| 74 | + $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 75 | + |
|
| 76 | + // charger de suite cette fonction, pour ses utilitaires |
|
| 77 | + $envoyer_inscription = charger_fonction("envoyer_inscription",""); |
|
| 78 | + list($sujet,$msg,$from,$head) = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 79 | + |
|
| 80 | + $notifications = charger_fonction('notifications', 'inc'); |
|
| 81 | + notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 82 | + |
|
| 83 | + // Notifications |
|
| 84 | + $notifications('inscription', $desc['id_auteur'], |
|
| 85 | + array('nom' => $desc['nom'], 'email' => $desc['email']) |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + return $desc; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
@@ -107,18 +107,18 @@ discard block |
||
| 107 | 107 | * @return array|string |
| 108 | 108 | */ |
| 109 | 109 | function test_inscription_dist($statut, $mail, $nom, $options) { |
| 110 | - include_spip('inc/filtres'); |
|
| 111 | - if (!$r = email_valide($mail)) return 'info_email_invalide'; |
|
| 112 | - $nom = trim(corriger_caracteres($nom)); |
|
| 113 | - $res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut); |
|
| 114 | - if (isset($options['login'])) { |
|
| 115 | - $login = trim(corriger_caracteres($options['login'])); |
|
| 116 | - if((strlen ($login) >= _LOGIN_TROP_COURT) AND (strlen($nom) <= 64)) |
|
| 117 | - $res['login'] = $login; |
|
| 118 | - } |
|
| 119 | - if(!isset($res['login']) AND ((strlen ($nom) < _LOGIN_TROP_COURT) OR (strlen($nom) > 64))) |
|
| 120 | - return 'ecrire:info_login_trop_court'; |
|
| 121 | - return $res; |
|
| 110 | + include_spip('inc/filtres'); |
|
| 111 | + if (!$r = email_valide($mail)) return 'info_email_invalide'; |
|
| 112 | + $nom = trim(corriger_caracteres($nom)); |
|
| 113 | + $res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut); |
|
| 114 | + if (isset($options['login'])) { |
|
| 115 | + $login = trim(corriger_caracteres($options['login'])); |
|
| 116 | + if((strlen ($login) >= _LOGIN_TROP_COURT) AND (strlen($nom) <= 64)) |
|
| 117 | + $res['login'] = $login; |
|
| 118 | + } |
|
| 119 | + if(!isset($res['login']) AND ((strlen ($nom) < _LOGIN_TROP_COURT) OR (strlen($nom) > 64))) |
|
| 120 | + return 'ecrire:info_login_trop_court'; |
|
| 121 | + return $res; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -134,27 +134,27 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | function inscription_nouveau($desc) |
| 136 | 136 | { |
| 137 | - if (!isset($desc['login']) OR !strlen($desc['login'])) |
|
| 138 | - $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 137 | + if (!isset($desc['login']) OR !strlen($desc['login'])) |
|
| 138 | + $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 139 | 139 | |
| 140 | - $desc['statut'] = 'nouveau'; |
|
| 141 | - include_spip('action/editer_auteur'); |
|
| 142 | - if (isset($desc['id_auteur'])) |
|
| 143 | - $id_auteur = $desc['id_auteur']; |
|
| 144 | - else |
|
| 145 | - $id_auteur = auteur_inserer(); |
|
| 140 | + $desc['statut'] = 'nouveau'; |
|
| 141 | + include_spip('action/editer_auteur'); |
|
| 142 | + if (isset($desc['id_auteur'])) |
|
| 143 | + $id_auteur = $desc['id_auteur']; |
|
| 144 | + else |
|
| 145 | + $id_auteur = auteur_inserer(); |
|
| 146 | 146 | |
| 147 | - if (!$id_auteur) return _T('titre_probleme_technique'); |
|
| 147 | + if (!$id_auteur) return _T('titre_probleme_technique'); |
|
| 148 | 148 | |
| 149 | - include_spip('inc/autoriser'); |
|
| 150 | - // lever l'autorisation pour pouvoir modifier le statut |
|
| 151 | - autoriser_exception('modifier','auteur',$id_auteur); |
|
| 152 | - auteur_modifier($id_auteur, $desc); |
|
| 153 | - autoriser_exception('modifier','auteur',$id_auteur,false); |
|
| 149 | + include_spip('inc/autoriser'); |
|
| 150 | + // lever l'autorisation pour pouvoir modifier le statut |
|
| 151 | + autoriser_exception('modifier','auteur',$id_auteur); |
|
| 152 | + auteur_modifier($id_auteur, $desc); |
|
| 153 | + autoriser_exception('modifier','auteur',$id_auteur,false); |
|
| 154 | 154 | |
| 155 | - $desc['id_auteur'] = $id_auteur; |
|
| 155 | + $desc['id_auteur'] = $id_auteur; |
|
| 156 | 156 | |
| 157 | - return $desc; |
|
| 157 | + return $desc; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | |
@@ -166,26 +166,26 @@ discard block |
||
| 166 | 166 | * @return string |
| 167 | 167 | */ |
| 168 | 168 | function test_login($nom, $mail) { |
| 169 | - include_spip('inc/charsets'); |
|
| 170 | - $nom = strtolower(translitteration($nom)); |
|
| 171 | - $login_base = preg_replace("/[^\w\d_]/", "_", $nom); |
|
| 172 | - |
|
| 173 | - // il faut eviter que le login soit vraiment trop court |
|
| 174 | - if (strlen($login_base) < 3) { |
|
| 175 | - $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 176 | - $login_base = preg_replace("/[^\w\d]/", "_", $mail); |
|
| 177 | - } |
|
| 178 | - if (strlen($login_base) < 3) |
|
| 179 | - $login_base = 'user'; |
|
| 180 | - |
|
| 181 | - $login = $login_base; |
|
| 182 | - |
|
| 183 | - for ($i = 1; ; $i++) { |
|
| 184 | - if (!sql_countsel('spip_auteurs', "login='$login'")) |
|
| 185 | - return $login; |
|
| 186 | - $login = $login_base.$i; |
|
| 187 | - } |
|
| 188 | - return $login; |
|
| 169 | + include_spip('inc/charsets'); |
|
| 170 | + $nom = strtolower(translitteration($nom)); |
|
| 171 | + $login_base = preg_replace("/[^\w\d_]/", "_", $nom); |
|
| 172 | + |
|
| 173 | + // il faut eviter que le login soit vraiment trop court |
|
| 174 | + if (strlen($login_base) < 3) { |
|
| 175 | + $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 176 | + $login_base = preg_replace("/[^\w\d]/", "_", $mail); |
|
| 177 | + } |
|
| 178 | + if (strlen($login_base) < 3) |
|
| 179 | + $login_base = 'user'; |
|
| 180 | + |
|
| 181 | + $login = $login_base; |
|
| 182 | + |
|
| 183 | + for ($i = 1; ; $i++) { |
|
| 184 | + if (!sql_countsel('spip_auteurs', "login='$login'")) |
|
| 185 | + return $login; |
|
| 186 | + $login = $login_base.$i; |
|
| 187 | + } |
|
| 188 | + return $login; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -204,21 +204,21 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | function envoyer_inscription_dist($desc, $nom, $mode, $options=array()) { |
| 206 | 206 | |
| 207 | - $contexte = array_merge($desc,$options); |
|
| 208 | - $contexte['nom'] = $nom; |
|
| 209 | - $contexte['mode'] = $mode; |
|
| 210 | - $contexte['url_confirm'] = generer_url_action('confirmer_inscription','',true,true); |
|
| 211 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'],'email',$desc['email']); |
|
| 212 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'],'jeton',$desc['jeton']); |
|
| 213 | - |
|
| 214 | - $modele_mail = 'modeles/mail_inscription'; |
|
| 215 | - if (isset($options['modele_mail']) and $options['modele_mail']){ |
|
| 216 | - $modele_mail = $options['modele_mail']; |
|
| 217 | - } |
|
| 218 | - $message = recuperer_fond($modele_mail, $contexte); |
|
| 219 | - $from = (isset($options['from']) ? $options['from'] : null); |
|
| 220 | - $head = null; |
|
| 221 | - return array("", $message,$from,$head); |
|
| 207 | + $contexte = array_merge($desc,$options); |
|
| 208 | + $contexte['nom'] = $nom; |
|
| 209 | + $contexte['mode'] = $mode; |
|
| 210 | + $contexte['url_confirm'] = generer_url_action('confirmer_inscription','',true,true); |
|
| 211 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'],'email',$desc['email']); |
|
| 212 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'],'jeton',$desc['jeton']); |
|
| 213 | + |
|
| 214 | + $modele_mail = 'modeles/mail_inscription'; |
|
| 215 | + if (isset($options['modele_mail']) and $options['modele_mail']){ |
|
| 216 | + $modele_mail = $options['modele_mail']; |
|
| 217 | + } |
|
| 218 | + $message = recuperer_fond($modele_mail, $contexte); |
|
| 219 | + $from = (isset($options['from']) ? $options['from'] : null); |
|
| 220 | + $head = null; |
|
| 221 | + return array("", $message,$from,$head); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | * @return string |
| 232 | 232 | */ |
| 233 | 233 | function creer_pass_pour_auteur($id_auteur) { |
| 234 | - include_spip('inc/acces'); |
|
| 235 | - $pass = creer_pass_aleatoire(8, $id_auteur); |
|
| 236 | - include_spip('action/editer_auteur'); |
|
| 237 | - auteur_instituer($id_auteur, array('pass'=>$pass)); |
|
| 238 | - return $pass; |
|
| 234 | + include_spip('inc/acces'); |
|
| 235 | + $pass = creer_pass_aleatoire(8, $id_auteur); |
|
| 236 | + include_spip('action/editer_auteur'); |
|
| 237 | + auteur_instituer($id_auteur, array('pass'=>$pass)); |
|
| 238 | + return $pass; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -248,15 +248,15 @@ discard block |
||
| 248 | 248 | * @return string |
| 249 | 249 | */ |
| 250 | 250 | function tester_statut_inscription($statut_tmp, $id){ |
| 251 | - include_spip('inc/autoriser'); |
|
| 252 | - if ($statut_tmp) |
|
| 253 | - return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 254 | - elseif ( |
|
| 255 | - autoriser('inscrireauteur', $statut_tmp = "1comite", $id) |
|
| 256 | - OR autoriser('inscrireauteur', $statut_tmp = "6forum", $id)) |
|
| 257 | - return $statut_tmp; |
|
| 258 | - |
|
| 259 | - return ''; |
|
| 251 | + include_spip('inc/autoriser'); |
|
| 252 | + if ($statut_tmp) |
|
| 253 | + return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 254 | + elseif ( |
|
| 255 | + autoriser('inscrireauteur', $statut_tmp = "1comite", $id) |
|
| 256 | + OR autoriser('inscrireauteur', $statut_tmp = "6forum", $id)) |
|
| 257 | + return $statut_tmp; |
|
| 258 | + |
|
| 259 | + return ''; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
@@ -272,27 +272,27 @@ discard block |
||
| 272 | 272 | * @return array |
| 273 | 273 | */ |
| 274 | 274 | function confirmer_statut_inscription($auteur){ |
| 275 | - // securite |
|
| 276 | - if ($auteur['statut'] != 'nouveau') return $auteur; |
|
| 277 | - |
|
| 278 | - include_spip('inc/autoriser'); |
|
| 279 | - if (!autoriser('inscrireauteur', $auteur['prefs'])) |
|
| 280 | - return $auteur; |
|
| 281 | - $s = $auteur['prefs']; |
|
| 282 | - |
|
| 283 | - include_spip('inc/autoriser'); |
|
| 284 | - // accorder l'autorisation de modif du statut auteur |
|
| 285 | - autoriser_exception('modifier','auteur',$auteur['id_auteur']); |
|
| 286 | - include_spip('action/editer_auteur'); |
|
| 287 | - // changer le statut |
|
| 288 | - auteur_modifier($auteur['id_auteur'],array('statut'=> $s)); |
|
| 289 | - unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 290 | - // lever l'autorisation de modif du statut auteur |
|
| 291 | - autoriser_exception('modifier','auteur',$auteur['id_auteur'],false); |
|
| 292 | - |
|
| 293 | - // mettre a jour le statut |
|
| 294 | - $auteur['statut'] = $s; |
|
| 295 | - return $auteur; |
|
| 275 | + // securite |
|
| 276 | + if ($auteur['statut'] != 'nouveau') return $auteur; |
|
| 277 | + |
|
| 278 | + include_spip('inc/autoriser'); |
|
| 279 | + if (!autoriser('inscrireauteur', $auteur['prefs'])) |
|
| 280 | + return $auteur; |
|
| 281 | + $s = $auteur['prefs']; |
|
| 282 | + |
|
| 283 | + include_spip('inc/autoriser'); |
|
| 284 | + // accorder l'autorisation de modif du statut auteur |
|
| 285 | + autoriser_exception('modifier','auteur',$auteur['id_auteur']); |
|
| 286 | + include_spip('action/editer_auteur'); |
|
| 287 | + // changer le statut |
|
| 288 | + auteur_modifier($auteur['id_auteur'],array('statut'=> $s)); |
|
| 289 | + unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 290 | + // lever l'autorisation de modif du statut auteur |
|
| 291 | + autoriser_exception('modifier','auteur',$auteur['id_auteur'],false); |
|
| 292 | + |
|
| 293 | + // mettre a jour le statut |
|
| 294 | + $auteur['statut'] = $s; |
|
| 295 | + return $auteur; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | |
@@ -303,14 +303,14 @@ discard block |
||
| 303 | 303 | * @return string |
| 304 | 304 | */ |
| 305 | 305 | function auteur_attribuer_jeton($id_auteur){ |
| 306 | - include_spip('inc/acces'); |
|
| 307 | - // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 308 | - do { |
|
| 309 | - $jeton = creer_uniqid(); |
|
| 310 | - sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur)); |
|
| 311 | - } |
|
| 312 | - while (sql_countsel("spip_auteurs","cookie_oubli=".sql_quote($jeton))>1); |
|
| 313 | - return $jeton; |
|
| 306 | + include_spip('inc/acces'); |
|
| 307 | + // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 308 | + do { |
|
| 309 | + $jeton = creer_uniqid(); |
|
| 310 | + sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur)); |
|
| 311 | + } |
|
| 312 | + while (sql_countsel("spip_auteurs","cookie_oubli=".sql_quote($jeton))>1); |
|
| 313 | + return $jeton; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -319,12 +319,12 @@ discard block |
||
| 319 | 319 | * @return array|bool |
| 320 | 320 | */ |
| 321 | 321 | function auteur_verifier_jeton($jeton){ |
| 322 | - // refuser un jeton corrompu |
|
| 323 | - if (preg_match(',[^0-9a-f.],i',$jeton)) |
|
| 324 | - return false; |
|
| 322 | + // refuser un jeton corrompu |
|
| 323 | + if (preg_match(',[^0-9a-f.],i',$jeton)) |
|
| 324 | + return false; |
|
| 325 | 325 | |
| 326 | - $desc = sql_fetsel('*','spip_auteurs',"cookie_oubli=".sql_quote($jeton, $serveur, 'string')); |
|
| 327 | - return $desc; |
|
| 326 | + $desc = sql_fetsel('*','spip_auteurs',"cookie_oubli=".sql_quote($jeton, $serveur, 'string')); |
|
| 327 | + return $desc; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -334,5 +334,5 @@ discard block |
||
| 334 | 334 | * @return bool |
| 335 | 335 | */ |
| 336 | 336 | function auteur_effacer_jeton($id_auteur){ |
| 337 | - return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur)); |
|
| 337 | + return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur)); |
|
| 338 | 338 | } |
@@ -16,22 +16,22 @@ |
||
| 16 | 16 | |
| 17 | 17 | function action_redirect_dist() |
| 18 | 18 | { |
| 19 | - $type = _request('type'); |
|
| 20 | - if (!preg_match('/^\w+$/', $type)) return; |
|
| 21 | - if ($m = _request('var_mode')) { |
|
| 22 | - // forcer la mise a jour de l'url de cet objet ! |
|
| 23 | - if (!defined('_VAR_URLS')) define('_VAR_URLS',true); |
|
| 24 | - $m = 'var_mode='.urlencode($m); |
|
| 25 | - } |
|
| 26 | - $h = generer_url_entite_absolue(intval(_request('id')), $type, $m, '', true); |
|
| 27 | - $status = '302'; |
|
| 28 | - if (_request('status') AND _request('status')=='301') |
|
| 29 | - $status = '301'; |
|
| 19 | + $type = _request('type'); |
|
| 20 | + if (!preg_match('/^\w+$/', $type)) return; |
|
| 21 | + if ($m = _request('var_mode')) { |
|
| 22 | + // forcer la mise a jour de l'url de cet objet ! |
|
| 23 | + if (!defined('_VAR_URLS')) define('_VAR_URLS',true); |
|
| 24 | + $m = 'var_mode='.urlencode($m); |
|
| 25 | + } |
|
| 26 | + $h = generer_url_entite_absolue(intval(_request('id')), $type, $m, '', true); |
|
| 27 | + $status = '302'; |
|
| 28 | + if (_request('status') AND _request('status')=='301') |
|
| 29 | + $status = '301'; |
|
| 30 | 30 | |
| 31 | - if ($h) |
|
| 32 | - redirige_par_entete(str_replace('&', '&', $h),'',$status); |
|
| 33 | - else |
|
| 34 | - redirige_par_entete('/','',$status); |
|
| 31 | + if ($h) |
|
| 32 | + redirige_par_entete(str_replace('&', '&', $h),'',$status); |
|
| 33 | + else |
|
| 34 | + redirige_par_entete('/','',$status); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | ?> |
@@ -15,19 +15,19 @@ |
||
| 15 | 15 | // http://doc.spip.org/@action_instituer_collaboration_dist |
| 16 | 16 | function action_debloquer_edition_dist() { |
| 17 | 17 | |
| 18 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 19 | - $arg = $securiser_action(); |
|
| 18 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 19 | + $arg = $securiser_action(); |
|
| 20 | 20 | |
| 21 | - if ($arg) { |
|
| 22 | - include_spip('inc/drapeau_edition'); |
|
| 23 | - if ($arg == 'tous') { |
|
| 24 | - debloquer_tous($GLOBALS['visiteur_session']['id_auteur']); |
|
| 25 | - } |
|
| 26 | - else { |
|
| 27 | - $arg = explode("-",$arg); |
|
| 28 | - list($objet,$id_objet) = $arg; |
|
| 29 | - debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet); |
|
| 30 | - } |
|
| 31 | - } |
|
| 21 | + if ($arg) { |
|
| 22 | + include_spip('inc/drapeau_edition'); |
|
| 23 | + if ($arg == 'tous') { |
|
| 24 | + debloquer_tous($GLOBALS['visiteur_session']['id_auteur']); |
|
| 25 | + } |
|
| 26 | + else { |
|
| 27 | + $arg = explode("-",$arg); |
|
| 28 | + list($objet,$id_objet) = $arg; |
|
| 29 | + debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | } |
| 33 | 33 | ?> |