@@ -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 | ?> |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | 14 | |
| 15 | 15 | function action_supprimer_lien_dist($arg=null){ |
| 16 | - if (is_null($arg)){ |
|
| 17 | - $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 18 | - $arg = $securiser_action(); |
|
| 19 | - } |
|
| 16 | + if (is_null($arg)){ |
|
| 17 | + $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 18 | + $arg = $securiser_action(); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - $arg = explode("-",$arg); |
|
| 22 | - list($objet_source,$ids,$objet_lie,$idl) = $arg; |
|
| 21 | + $arg = explode("-",$arg); |
|
| 22 | + list($objet_source,$ids,$objet_lie,$idl) = $arg; |
|
| 23 | 23 | |
| 24 | - include_spip('action/editer_liens'); |
|
| 25 | - objet_dissocier(array($objet_source=>$ids), array($objet_lie=>$idl)); |
|
| 24 | + include_spip('action/editer_liens'); |
|
| 25 | + objet_dissocier(array($objet_source=>$ids), array($objet_lie=>$idl)); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |