@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * Identifiant de la rubrique parente. |
| 74 | 74 | * 0 pour la racine. |
| 75 | 75 | * @param array|null $set |
| 76 | - * @return int |
|
| 76 | + * @return boolean|string |
|
| 77 | 77 | * Identifiant de la rubrique crée |
| 78 | 78 | */ |
| 79 | 79 | function rubrique_inserer($id_parent, $set = null) { |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * Identifiant de la rubrique modifiée |
| 121 | 121 | * @param array|null $set |
| 122 | 122 | * Tableau qu'on peut proposer en lieu et place de _request() |
| 123 | - * @return bool|string |
|
| 123 | + * @return string|false |
|
| 124 | 124 | * - false : Aucune modification, aucun champ n'est à modifier |
| 125 | 125 | * - chaîne vide : Vide si tout s'est bien passé |
| 126 | 126 | * - chaîne : Texte d'un message d'erreur |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | * @param int $id_parent |
| 278 | 278 | * Identifiant de la rubrique parente. |
| 279 | 279 | * 0 pour la racine. |
| 280 | - * @return int |
|
| 280 | + * @return boolean|string |
|
| 281 | 281 | * Identifiant de la rubrique crée |
| 282 | 282 | **/ |
| 283 | 283 | function insert_rubrique($id_parent) { |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * Identifiant de la rubrique à instituer |
| 297 | 297 | * @param array|null $set |
| 298 | 298 | * Tableau qu'on peut proposer en lieu et place de _request() |
| 299 | - * @return bool|string |
|
| 299 | + * @return string|false |
|
| 300 | 300 | * - false : Aucune modification, aucun champ n'est à modifier |
| 301 | 301 | * - chaîne vide : Vide si tout s'est bien passé |
| 302 | 302 | * - chaîne : Texte d'un message d'erreur |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Rubriques\Edition |
| 17 | 17 | */ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rubriques'); |
@@ -38,31 +38,31 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | function action_editer_rubrique_dist($arg = null) { |
| 40 | 40 | |
| 41 | - if (is_null($arg)) { |
|
| 42 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | - $arg = $securiser_action(); |
|
| 44 | - } |
|
| 41 | + if (is_null($arg)) { |
|
| 42 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | + $arg = $securiser_action(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if (!$id_rubrique = intval($arg)) { |
|
| 47 | - if ($arg != 'oui') { |
|
| 48 | - include_spip('inc/headers'); |
|
| 49 | - redirige_url_ecrire(); |
|
| 50 | - } |
|
| 51 | - $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | - } |
|
| 46 | + if (!$id_rubrique = intval($arg)) { |
|
| 47 | + if ($arg != 'oui') { |
|
| 48 | + include_spip('inc/headers'); |
|
| 49 | + redirige_url_ecrire(); |
|
| 50 | + } |
|
| 51 | + $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - $err = rubrique_modifier($id_rubrique); |
|
| 54 | + $err = rubrique_modifier($id_rubrique); |
|
| 55 | 55 | |
| 56 | - if (_request('redirect')) { |
|
| 57 | - $redirect = parametre_url( |
|
| 58 | - urldecode(_request('redirect')), |
|
| 59 | - 'id_rubrique', $id_rubrique, '&'); |
|
| 56 | + if (_request('redirect')) { |
|
| 57 | + $redirect = parametre_url( |
|
| 58 | + urldecode(_request('redirect')), |
|
| 59 | + 'id_rubrique', $id_rubrique, '&'); |
|
| 60 | 60 | |
| 61 | - include_spip('inc/headers'); |
|
| 62 | - redirige_par_entete($redirect); |
|
| 63 | - } |
|
| 61 | + include_spip('inc/headers'); |
|
| 62 | + redirige_par_entete($redirect); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return array($id_rubrique, $err); |
|
| 65 | + return array($id_rubrique, $err); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
@@ -77,40 +77,40 @@ discard block |
||
| 77 | 77 | * Identifiant de la rubrique crée |
| 78 | 78 | */ |
| 79 | 79 | function rubrique_inserer($id_parent, $set = null) { |
| 80 | - $champs = array( |
|
| 81 | - 'titre' => _T('item_nouvelle_rubrique'), |
|
| 82 | - 'id_parent' => intval($id_parent), |
|
| 83 | - 'statut' => 'prepa' |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - if ($set) { |
|
| 87 | - $champs = array_merge($champs, $set); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Envoyer aux plugins |
|
| 91 | - $champs = pipeline('pre_insertion', |
|
| 92 | - array( |
|
| 93 | - 'args' => array( |
|
| 94 | - 'table' => 'spip_rubriques', |
|
| 95 | - ), |
|
| 96 | - 'data' => $champs |
|
| 97 | - ) |
|
| 98 | - ); |
|
| 99 | - |
|
| 100 | - $id_rubrique = sql_insertq("spip_rubriques", $champs); |
|
| 101 | - pipeline('post_insertion', |
|
| 102 | - array( |
|
| 103 | - 'args' => array( |
|
| 104 | - 'table' => 'spip_rubriques', |
|
| 105 | - 'id_objet' => $id_rubrique |
|
| 106 | - ), |
|
| 107 | - 'data' => $champs |
|
| 108 | - ) |
|
| 109 | - ); |
|
| 110 | - propager_les_secteurs(); |
|
| 111 | - calculer_langues_rubriques(); |
|
| 112 | - |
|
| 113 | - return $id_rubrique; |
|
| 80 | + $champs = array( |
|
| 81 | + 'titre' => _T('item_nouvelle_rubrique'), |
|
| 82 | + 'id_parent' => intval($id_parent), |
|
| 83 | + 'statut' => 'prepa' |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + if ($set) { |
|
| 87 | + $champs = array_merge($champs, $set); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Envoyer aux plugins |
|
| 91 | + $champs = pipeline('pre_insertion', |
|
| 92 | + array( |
|
| 93 | + 'args' => array( |
|
| 94 | + 'table' => 'spip_rubriques', |
|
| 95 | + ), |
|
| 96 | + 'data' => $champs |
|
| 97 | + ) |
|
| 98 | + ); |
|
| 99 | + |
|
| 100 | + $id_rubrique = sql_insertq("spip_rubriques", $champs); |
|
| 101 | + pipeline('post_insertion', |
|
| 102 | + array( |
|
| 103 | + 'args' => array( |
|
| 104 | + 'table' => 'spip_rubriques', |
|
| 105 | + 'id_objet' => $id_rubrique |
|
| 106 | + ), |
|
| 107 | + 'data' => $champs |
|
| 108 | + ) |
|
| 109 | + ); |
|
| 110 | + propager_les_secteurs(); |
|
| 111 | + calculer_langues_rubriques(); |
|
| 112 | + |
|
| 113 | + return $id_rubrique; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -126,42 +126,42 @@ discard block |
||
| 126 | 126 | * - chaîne : Texte d'un message d'erreur |
| 127 | 127 | */ |
| 128 | 128 | function rubrique_modifier($id_rubrique, $set = null) { |
| 129 | - include_spip('inc/autoriser'); |
|
| 130 | - include_spip('inc/filtres'); |
|
| 131 | - |
|
| 132 | - include_spip('inc/modifier'); |
|
| 133 | - $c = collecter_requests( |
|
| 134 | - // white list |
|
| 135 | - objet_info('rubrique', 'champs_editables'), |
|
| 136 | - // black list |
|
| 137 | - array('id_parent', 'confirme_deplace'), |
|
| 138 | - // donnees eventuellement fournies |
|
| 139 | - $set |
|
| 140 | - ); |
|
| 141 | - |
|
| 142 | - if ($err = objet_modifier_champs('rubrique', $id_rubrique, |
|
| 143 | - array( |
|
| 144 | - 'data' => $set, |
|
| 145 | - 'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique) |
|
| 146 | - ), |
|
| 147 | - $c) |
|
| 148 | - ) { |
|
| 149 | - return $err; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $c = collecter_requests(array('id_parent', 'confirme_deplace'), array(), $set); |
|
| 153 | - // Deplacer la rubrique |
|
| 154 | - if (isset($c['id_parent'])) { |
|
| 155 | - $err = rubrique_instituer($id_rubrique, $c); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // invalider les caches marques de cette rubrique |
|
| 159 | - include_spip('inc/invalideur'); |
|
| 160 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 161 | - // et celui de menu_rubriques |
|
| 162 | - effacer_meta("date_calcul_rubriques"); |
|
| 163 | - |
|
| 164 | - return $err; |
|
| 129 | + include_spip('inc/autoriser'); |
|
| 130 | + include_spip('inc/filtres'); |
|
| 131 | + |
|
| 132 | + include_spip('inc/modifier'); |
|
| 133 | + $c = collecter_requests( |
|
| 134 | + // white list |
|
| 135 | + objet_info('rubrique', 'champs_editables'), |
|
| 136 | + // black list |
|
| 137 | + array('id_parent', 'confirme_deplace'), |
|
| 138 | + // donnees eventuellement fournies |
|
| 139 | + $set |
|
| 140 | + ); |
|
| 141 | + |
|
| 142 | + if ($err = objet_modifier_champs('rubrique', $id_rubrique, |
|
| 143 | + array( |
|
| 144 | + 'data' => $set, |
|
| 145 | + 'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique) |
|
| 146 | + ), |
|
| 147 | + $c) |
|
| 148 | + ) { |
|
| 149 | + return $err; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $c = collecter_requests(array('id_parent', 'confirme_deplace'), array(), $set); |
|
| 153 | + // Deplacer la rubrique |
|
| 154 | + if (isset($c['id_parent'])) { |
|
| 155 | + $err = rubrique_instituer($id_rubrique, $c); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // invalider les caches marques de cette rubrique |
|
| 159 | + include_spip('inc/invalideur'); |
|
| 160 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 161 | + // et celui de menu_rubriques |
|
| 162 | + effacer_meta("date_calcul_rubriques"); |
|
| 163 | + |
|
| 164 | + return $err; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -184,21 +184,21 @@ discard block |
||
| 184 | 184 | * false si la confirmation du déplacement n'est pas présente |
| 185 | 185 | */ |
| 186 | 186 | function editer_rubrique_breves($id_rubrique, $id_parent, $c = array()) { |
| 187 | - if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 187 | + if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 191 | + if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - if ($id_secteur = sql_getfetsel("id_secteur", |
|
| 196 | - "spip_rubriques", "id_rubrique=$id_parent") |
|
| 197 | - ) { |
|
| 198 | - sql_updateq("spip_breves", array("id_rubrique" => $id_secteur), "id_rubrique=$id_rubrique"); |
|
| 199 | - } |
|
| 195 | + if ($id_secteur = sql_getfetsel("id_secteur", |
|
| 196 | + "spip_rubriques", "id_rubrique=$id_parent") |
|
| 197 | + ) { |
|
| 198 | + sql_updateq("spip_breves", array("id_rubrique" => $id_secteur), "id_rubrique=$id_rubrique"); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return true; |
|
| 201 | + return true; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -220,51 +220,51 @@ discard block |
||
| 220 | 220 | * Chaîne : Texte du message d'erreur |
| 221 | 221 | */ |
| 222 | 222 | function rubrique_instituer($id_rubrique, $c) { |
| 223 | - // traitement de la rubrique parente |
|
| 224 | - // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 225 | - // qu'on n'administre pas. |
|
| 226 | - |
|
| 227 | - if (null !== ($id_parent = $c['id_parent'])) { |
|
| 228 | - $id_parent = intval($id_parent); |
|
| 229 | - $filles = calcul_branche_in($id_rubrique); |
|
| 230 | - if (strpos(",$id_parent,", ",$filles,") !== false) { |
|
| 231 | - spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 232 | - } else { |
|
| 233 | - $s = sql_fetsel("id_parent, statut", "spip_rubriques", "id_rubrique=$id_rubrique"); |
|
| 234 | - $old_parent = $s['id_parent']; |
|
| 235 | - |
|
| 236 | - if (!($id_parent != $old_parent |
|
| 237 | - and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 238 | - and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 239 | - and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 240 | - ) |
|
| 241 | - ) { |
|
| 242 | - if ($s['statut'] != 'new') { |
|
| 243 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 244 | - } |
|
| 245 | - } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 246 | - $statut_ancien = $s['statut']; |
|
| 247 | - sql_updateq('spip_rubriques', array('id_parent' => $id_parent), "id_rubrique=$id_rubrique"); |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - propager_les_secteurs(); |
|
| 251 | - |
|
| 252 | - // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 253 | - if ($statut_ancien == 'publie') { |
|
| 254 | - calculer_rubriques_if($old_parent, array('id_rubrique' => $id_parent), $statut_ancien); |
|
| 255 | - } |
|
| 256 | - // Creation ou deplacement d'une rubrique non publiee |
|
| 257 | - // invalider le cache de leur menu |
|
| 258 | - elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 259 | - effacer_meta("date_calcul_rubriques"); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - calculer_langues_rubriques(); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return ''; // pas d'erreur |
|
| 223 | + // traitement de la rubrique parente |
|
| 224 | + // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 225 | + // qu'on n'administre pas. |
|
| 226 | + |
|
| 227 | + if (null !== ($id_parent = $c['id_parent'])) { |
|
| 228 | + $id_parent = intval($id_parent); |
|
| 229 | + $filles = calcul_branche_in($id_rubrique); |
|
| 230 | + if (strpos(",$id_parent,", ",$filles,") !== false) { |
|
| 231 | + spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 232 | + } else { |
|
| 233 | + $s = sql_fetsel("id_parent, statut", "spip_rubriques", "id_rubrique=$id_rubrique"); |
|
| 234 | + $old_parent = $s['id_parent']; |
|
| 235 | + |
|
| 236 | + if (!($id_parent != $old_parent |
|
| 237 | + and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 238 | + and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 239 | + and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 240 | + ) |
|
| 241 | + ) { |
|
| 242 | + if ($s['statut'] != 'new') { |
|
| 243 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 244 | + } |
|
| 245 | + } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 246 | + $statut_ancien = $s['statut']; |
|
| 247 | + sql_updateq('spip_rubriques', array('id_parent' => $id_parent), "id_rubrique=$id_rubrique"); |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + propager_les_secteurs(); |
|
| 251 | + |
|
| 252 | + // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 253 | + if ($statut_ancien == 'publie') { |
|
| 254 | + calculer_rubriques_if($old_parent, array('id_rubrique' => $id_parent), $statut_ancien); |
|
| 255 | + } |
|
| 256 | + // Creation ou deplacement d'une rubrique non publiee |
|
| 257 | + // invalider le cache de leur menu |
|
| 258 | + elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 259 | + effacer_meta("date_calcul_rubriques"); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + calculer_langues_rubriques(); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return ''; // pas d'erreur |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * Identifiant de la rubrique crée |
| 282 | 282 | **/ |
| 283 | 283 | function insert_rubrique($id_parent) { |
| 284 | - return rubrique_inserer($id_parent); |
|
| 284 | + return rubrique_inserer($id_parent); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * - chaîne : Texte d'un message d'erreur |
| 303 | 303 | **/ |
| 304 | 304 | function revisions_rubriques($id_rubrique, $set = null) { |
| 305 | - return rubrique_modifier($id_rubrique, $set); |
|
| 305 | + return rubrique_modifier($id_rubrique, $set); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -321,5 +321,5 @@ discard block |
||
| 321 | 321 | * Chaîne : Texte du message d'erreur |
| 322 | 322 | **/ |
| 323 | 323 | function instituer_rubrique($id_rubrique, $c) { |
| 324 | - return rubrique_instituer($id_rubrique, $c); |
|
| 324 | + return rubrique_instituer($id_rubrique, $c); |
|
| 325 | 325 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if ($err = objet_modifier_champs('rubrique', $id_rubrique, |
| 143 | 143 | array( |
| 144 | 144 | 'data' => $set, |
| 145 | - 'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique) |
|
| 145 | + 'nonvide' => array('titre' => _T('titre_nouvelle_rubrique')." "._T('info_numero_abbreviation').$id_rubrique) |
|
| 146 | 146 | ), |
| 147 | 147 | $c) |
| 148 | 148 | ) { |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | ) |
| 241 | 241 | ) { |
| 242 | 242 | if ($s['statut'] != 'new') { |
| 243 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 243 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a ".$GLOBALS['visiteur_session']['id_auteur'].' '.$GLOBALS['visiteur_session']['statut']); |
|
| 244 | 244 | } |
| 245 | 245 | } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
| 246 | 246 | $statut_ancien = $s['statut']; |
@@ -369,7 +369,7 @@ |
||
| 369 | 369 | * Effacer le jeton d'un auteur apres utilisation |
| 370 | 370 | * |
| 371 | 371 | * @param int $id_auteur |
| 372 | - * @return bool |
|
| 372 | + * @return boolean|string |
|
| 373 | 373 | */ |
| 374 | 374 | function auteur_effacer_jeton($id_auteur) { |
| 375 | 375 | return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur)); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | include_spip('base/abstract_sql'); |
| 58 | - $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email'])); |
|
| 58 | + $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=".sql_quote($desc['email'])); |
|
| 59 | 59 | // erreur ? |
| 60 | 60 | if (!$res) { |
| 61 | 61 | return _T('titre_probleme_technique'); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | if (!sql_countsel('spip_auteurs', "login='$login'")) { |
| 209 | 209 | return $login; |
| 210 | 210 | } |
| 211 | - $login = $login_base . $i; |
|
| 211 | + $login = $login_base.$i; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | return $login; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
| 238 | 238 | |
| 239 | 239 | $modele_mail = 'modeles/mail_inscription'; |
| 240 | - if (isset($options['modele_mail']) and $options['modele_mail']){ |
|
| 240 | + if (isset($options['modele_mail']) and $options['modele_mail']) { |
|
| 241 | 241 | $modele_mail = $options['modele_mail']; |
| 242 | 242 | } |
| 243 | 243 | $message = recuperer_fond($modele_mail, $contexte); |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
| 342 | 342 | do { |
| 343 | 343 | $jeton = creer_uniqid(); |
| 344 | - sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur)); |
|
| 345 | - } while (sql_countsel("spip_auteurs", "cookie_oubli=" . sql_quote($jeton)) > 1); |
|
| 344 | + sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=".intval($id_auteur)); |
|
| 345 | + } while (sql_countsel("spip_auteurs", "cookie_oubli=".sql_quote($jeton)) > 1); |
|
| 346 | 346 | |
| 347 | 347 | return $jeton; |
| 348 | 348 | } |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter |
| 363 | - $desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=" . sql_quote($jeton, '', 'string')); |
|
| 363 | + $desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=".sql_quote($jeton, '', 'string')); |
|
| 364 | 364 | |
| 365 | 365 | return $desc; |
| 366 | 366 | } |
@@ -372,5 +372,5 @@ discard block |
||
| 372 | 372 | * @return bool |
| 373 | 373 | */ |
| 374 | 374 | function auteur_effacer_jeton($id_auteur) { |
| 375 | - return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur)); |
|
| 375 | + return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=".intval($id_auteur)); |
|
| 376 | 376 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Inscription |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -38,68 +38,68 @@ discard block |
||
| 38 | 38 | * @return array|string |
| 39 | 39 | */ |
| 40 | 40 | function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = array()) { |
| 41 | - if (!is_array($options)) { |
|
| 42 | - $options = array('id' => $options); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if (function_exists('test_inscription')) { |
|
| 46 | - $f = 'test_inscription'; |
|
| 47 | - } else { |
|
| 48 | - $f = 'test_inscription_dist'; |
|
| 49 | - } |
|
| 50 | - $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 51 | - |
|
| 52 | - // erreur ? |
|
| 53 | - if (!is_array($desc)) { |
|
| 54 | - return _T($desc); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - include_spip('base/abstract_sql'); |
|
| 58 | - $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email'])); |
|
| 59 | - // erreur ? |
|
| 60 | - if (!$res) { |
|
| 61 | - return _T('titre_probleme_technique'); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $row = sql_fetch($res); |
|
| 65 | - sql_free($res); |
|
| 66 | - if ($row) { |
|
| 67 | - if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 68 | - $desc['id_auteur'] = $row['id_auteur']; |
|
| 69 | - $desc = inscription_nouveau($desc); |
|
| 70 | - } else { |
|
| 71 | - $desc = $row; |
|
| 72 | - } |
|
| 73 | - } else // s'il n'existe pas deja, creer les identifiants |
|
| 74 | - { |
|
| 75 | - $desc = inscription_nouveau($desc); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // erreur ? |
|
| 79 | - if (!is_array($desc)) { |
|
| 80 | - return $desc; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 85 | - $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 86 | - |
|
| 87 | - // attribuer un jeton pour confirmation par clic sur un lien |
|
| 88 | - $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 89 | - |
|
| 90 | - // charger de suite cette fonction, pour ses utilitaires |
|
| 91 | - $envoyer_inscription = charger_fonction("envoyer_inscription", ""); |
|
| 92 | - list($sujet, $msg, $from, $head) = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 93 | - |
|
| 94 | - $notifications = charger_fonction('notifications', 'inc'); |
|
| 95 | - notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 96 | - |
|
| 97 | - // Notifications |
|
| 98 | - $notifications('inscription', $desc['id_auteur'], |
|
| 99 | - array('nom' => $desc['nom'], 'email' => $desc['email']) |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - return $desc; |
|
| 41 | + if (!is_array($options)) { |
|
| 42 | + $options = array('id' => $options); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if (function_exists('test_inscription')) { |
|
| 46 | + $f = 'test_inscription'; |
|
| 47 | + } else { |
|
| 48 | + $f = 'test_inscription_dist'; |
|
| 49 | + } |
|
| 50 | + $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 51 | + |
|
| 52 | + // erreur ? |
|
| 53 | + if (!is_array($desc)) { |
|
| 54 | + return _T($desc); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + include_spip('base/abstract_sql'); |
|
| 58 | + $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email'])); |
|
| 59 | + // erreur ? |
|
| 60 | + if (!$res) { |
|
| 61 | + return _T('titre_probleme_technique'); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $row = sql_fetch($res); |
|
| 65 | + sql_free($res); |
|
| 66 | + if ($row) { |
|
| 67 | + if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 68 | + $desc['id_auteur'] = $row['id_auteur']; |
|
| 69 | + $desc = inscription_nouveau($desc); |
|
| 70 | + } else { |
|
| 71 | + $desc = $row; |
|
| 72 | + } |
|
| 73 | + } else // s'il n'existe pas deja, creer les identifiants |
|
| 74 | + { |
|
| 75 | + $desc = inscription_nouveau($desc); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // erreur ? |
|
| 79 | + if (!is_array($desc)) { |
|
| 80 | + return $desc; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 85 | + $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 86 | + |
|
| 87 | + // attribuer un jeton pour confirmation par clic sur un lien |
|
| 88 | + $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 89 | + |
|
| 90 | + // charger de suite cette fonction, pour ses utilitaires |
|
| 91 | + $envoyer_inscription = charger_fonction("envoyer_inscription", ""); |
|
| 92 | + list($sujet, $msg, $from, $head) = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 93 | + |
|
| 94 | + $notifications = charger_fonction('notifications', 'inc'); |
|
| 95 | + notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 96 | + |
|
| 97 | + // Notifications |
|
| 98 | + $notifications('inscription', $desc['id_auteur'], |
|
| 99 | + array('nom' => $desc['nom'], 'email' => $desc['email']) |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + return $desc; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -122,23 +122,23 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | */ |
| 124 | 124 | function test_inscription_dist($statut, $mail, $nom, $options) { |
| 125 | - include_spip('inc/filtres'); |
|
| 126 | - if (!$r = email_valide($mail)) { |
|
| 127 | - return 'info_email_invalide'; |
|
| 128 | - } |
|
| 129 | - $nom = trim(corriger_caracteres($nom)); |
|
| 130 | - $res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut); |
|
| 131 | - if (isset($options['login'])) { |
|
| 132 | - $login = trim(corriger_caracteres($options['login'])); |
|
| 133 | - if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 134 | - $res['login'] = $login; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 138 | - return 'ecrire:info_login_trop_court'; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $res; |
|
| 125 | + include_spip('inc/filtres'); |
|
| 126 | + if (!$r = email_valide($mail)) { |
|
| 127 | + return 'info_email_invalide'; |
|
| 128 | + } |
|
| 129 | + $nom = trim(corriger_caracteres($nom)); |
|
| 130 | + $res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut); |
|
| 131 | + if (isset($options['login'])) { |
|
| 132 | + $login = trim(corriger_caracteres($options['login'])); |
|
| 133 | + if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 134 | + $res['login'] = $login; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 138 | + return 'ecrire:info_login_trop_court'; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $res; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
@@ -151,33 +151,33 @@ discard block |
||
| 151 | 151 | * @return mixed|string |
| 152 | 152 | */ |
| 153 | 153 | function inscription_nouveau($desc) { |
| 154 | - if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 155 | - $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 156 | - } |
|
| 154 | + if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 155 | + $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - $desc['statut'] = 'nouveau'; |
|
| 159 | - include_spip('action/editer_auteur'); |
|
| 160 | - if (isset($desc['id_auteur'])) { |
|
| 161 | - $id_auteur = $desc['id_auteur']; |
|
| 162 | - } else { |
|
| 163 | - $id_auteur = auteur_inserer(); |
|
| 164 | - } |
|
| 158 | + $desc['statut'] = 'nouveau'; |
|
| 159 | + include_spip('action/editer_auteur'); |
|
| 160 | + if (isset($desc['id_auteur'])) { |
|
| 161 | + $id_auteur = $desc['id_auteur']; |
|
| 162 | + } else { |
|
| 163 | + $id_auteur = auteur_inserer(); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - if (!$id_auteur) { |
|
| 167 | - return _T('titre_probleme_technique'); |
|
| 168 | - } |
|
| 166 | + if (!$id_auteur) { |
|
| 167 | + return _T('titre_probleme_technique'); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 170 | + $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 171 | 171 | |
| 172 | - include_spip('inc/autoriser'); |
|
| 173 | - // lever l'autorisation pour pouvoir modifier le statut |
|
| 174 | - autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 175 | - auteur_modifier($id_auteur, $desc); |
|
| 176 | - autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 172 | + include_spip('inc/autoriser'); |
|
| 173 | + // lever l'autorisation pour pouvoir modifier le statut |
|
| 174 | + autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 175 | + auteur_modifier($id_auteur, $desc); |
|
| 176 | + autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 177 | 177 | |
| 178 | - $desc['id_auteur'] = $id_auteur; |
|
| 178 | + $desc['id_auteur'] = $id_auteur; |
|
| 179 | 179 | |
| 180 | - return $desc; |
|
| 180 | + return $desc; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
@@ -189,29 +189,29 @@ discard block |
||
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | 191 | function test_login($nom, $mail) { |
| 192 | - include_spip('inc/charsets'); |
|
| 193 | - $nom = strtolower(translitteration($nom)); |
|
| 194 | - $login_base = preg_replace("/[^\w\d_]/", "_", $nom); |
|
| 195 | - |
|
| 196 | - // il faut eviter que le login soit vraiment trop court |
|
| 197 | - if (strlen($login_base) < 3) { |
|
| 198 | - $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 199 | - $login_base = preg_replace("/[^\w\d]/", "_", $mail); |
|
| 200 | - } |
|
| 201 | - if (strlen($login_base) < 3) { |
|
| 202 | - $login_base = 'user'; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $login = $login_base; |
|
| 206 | - |
|
| 207 | - for ($i = 1; ; $i++) { |
|
| 208 | - if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 209 | - return $login; |
|
| 210 | - } |
|
| 211 | - $login = $login_base . $i; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return $login; |
|
| 192 | + include_spip('inc/charsets'); |
|
| 193 | + $nom = strtolower(translitteration($nom)); |
|
| 194 | + $login_base = preg_replace("/[^\w\d_]/", "_", $nom); |
|
| 195 | + |
|
| 196 | + // il faut eviter que le login soit vraiment trop court |
|
| 197 | + if (strlen($login_base) < 3) { |
|
| 198 | + $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 199 | + $login_base = preg_replace("/[^\w\d]/", "_", $mail); |
|
| 200 | + } |
|
| 201 | + if (strlen($login_base) < 3) { |
|
| 202 | + $login_base = 'user'; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $login = $login_base; |
|
| 206 | + |
|
| 207 | + for ($i = 1; ; $i++) { |
|
| 208 | + if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 209 | + return $login; |
|
| 210 | + } |
|
| 211 | + $login = $login_base . $i; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return $login; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -229,22 +229,22 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | function envoyer_inscription_dist($desc, $nom, $mode, $options = array()) { |
| 231 | 231 | |
| 232 | - $contexte = array_merge($desc, $options); |
|
| 233 | - $contexte['nom'] = $nom; |
|
| 234 | - $contexte['mode'] = $mode; |
|
| 235 | - $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 236 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 237 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 238 | - |
|
| 239 | - $modele_mail = 'modeles/mail_inscription'; |
|
| 240 | - if (isset($options['modele_mail']) and $options['modele_mail']){ |
|
| 241 | - $modele_mail = $options['modele_mail']; |
|
| 242 | - } |
|
| 243 | - $message = recuperer_fond($modele_mail, $contexte); |
|
| 244 | - $from = (isset($options['from']) ? $options['from'] : null); |
|
| 245 | - $head = null; |
|
| 246 | - |
|
| 247 | - return array("", $message, $from, $head); |
|
| 232 | + $contexte = array_merge($desc, $options); |
|
| 233 | + $contexte['nom'] = $nom; |
|
| 234 | + $contexte['mode'] = $mode; |
|
| 235 | + $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 236 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 237 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 238 | + |
|
| 239 | + $modele_mail = 'modeles/mail_inscription'; |
|
| 240 | + if (isset($options['modele_mail']) and $options['modele_mail']){ |
|
| 241 | + $modele_mail = $options['modele_mail']; |
|
| 242 | + } |
|
| 243 | + $message = recuperer_fond($modele_mail, $contexte); |
|
| 244 | + $from = (isset($options['from']) ? $options['from'] : null); |
|
| 245 | + $head = null; |
|
| 246 | + |
|
| 247 | + return array("", $message, $from, $head); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function creer_pass_pour_auteur($id_auteur) { |
| 258 | - include_spip('inc/acces'); |
|
| 259 | - $pass = creer_pass_aleatoire(16, $id_auteur); |
|
| 260 | - include_spip('action/editer_auteur'); |
|
| 261 | - auteur_instituer($id_auteur, array('pass' => $pass)); |
|
| 258 | + include_spip('inc/acces'); |
|
| 259 | + $pass = creer_pass_aleatoire(16, $id_auteur); |
|
| 260 | + include_spip('action/editer_auteur'); |
|
| 261 | + auteur_instituer($id_auteur, array('pass' => $pass)); |
|
| 262 | 262 | |
| 263 | - return $pass; |
|
| 263 | + return $pass; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -273,17 +273,17 @@ discard block |
||
| 273 | 273 | * @return string |
| 274 | 274 | */ |
| 275 | 275 | function tester_statut_inscription($statut_tmp, $id) { |
| 276 | - include_spip('inc/autoriser'); |
|
| 277 | - if ($statut_tmp) { |
|
| 278 | - return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 279 | - } elseif ( |
|
| 280 | - autoriser('inscrireauteur', $statut_tmp = "1comite", $id) |
|
| 281 | - or autoriser('inscrireauteur', $statut_tmp = "6forum", $id) |
|
| 282 | - ) { |
|
| 283 | - return $statut_tmp; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return ''; |
|
| 276 | + include_spip('inc/autoriser'); |
|
| 277 | + if ($statut_tmp) { |
|
| 278 | + return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 279 | + } elseif ( |
|
| 280 | + autoriser('inscrireauteur', $statut_tmp = "1comite", $id) |
|
| 281 | + or autoriser('inscrireauteur', $statut_tmp = "6forum", $id) |
|
| 282 | + ) { |
|
| 283 | + return $statut_tmp; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return ''; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
@@ -297,35 +297,35 @@ discard block |
||
| 297 | 297 | * @return array |
| 298 | 298 | */ |
| 299 | 299 | function confirmer_statut_inscription($auteur) { |
| 300 | - // securite |
|
| 301 | - if ($auteur['statut'] != 'nouveau') { |
|
| 302 | - return $auteur; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $s = $auteur['prefs']; |
|
| 306 | - // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 307 | - if (!preg_match(',^\w+$,', $s)) { |
|
| 308 | - $s = '6forum'; |
|
| 309 | - } |
|
| 310 | - include_spip('inc/autoriser'); |
|
| 311 | - if (!autoriser('inscrireauteur', $s)) { |
|
| 312 | - return $auteur; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - include_spip('inc/autoriser'); |
|
| 316 | - // accorder l'autorisation de modif du statut auteur |
|
| 317 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 318 | - include_spip('action/editer_auteur'); |
|
| 319 | - // changer le statut |
|
| 320 | - auteur_modifier($auteur['id_auteur'], array('statut' => $s)); |
|
| 321 | - unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 322 | - // lever l'autorisation de modif du statut auteur |
|
| 323 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 324 | - |
|
| 325 | - // mettre a jour le statut |
|
| 326 | - $auteur['statut'] = $s; |
|
| 327 | - |
|
| 328 | - return $auteur; |
|
| 300 | + // securite |
|
| 301 | + if ($auteur['statut'] != 'nouveau') { |
|
| 302 | + return $auteur; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $s = $auteur['prefs']; |
|
| 306 | + // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 307 | + if (!preg_match(',^\w+$,', $s)) { |
|
| 308 | + $s = '6forum'; |
|
| 309 | + } |
|
| 310 | + include_spip('inc/autoriser'); |
|
| 311 | + if (!autoriser('inscrireauteur', $s)) { |
|
| 312 | + return $auteur; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + include_spip('inc/autoriser'); |
|
| 316 | + // accorder l'autorisation de modif du statut auteur |
|
| 317 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 318 | + include_spip('action/editer_auteur'); |
|
| 319 | + // changer le statut |
|
| 320 | + auteur_modifier($auteur['id_auteur'], array('statut' => $s)); |
|
| 321 | + unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 322 | + // lever l'autorisation de modif du statut auteur |
|
| 323 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 324 | + |
|
| 325 | + // mettre a jour le statut |
|
| 326 | + $auteur['statut'] = $s; |
|
| 327 | + |
|
| 328 | + return $auteur; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | * @return string |
| 338 | 338 | */ |
| 339 | 339 | function auteur_attribuer_jeton($id_auteur) { |
| 340 | - include_spip('inc/acces'); |
|
| 341 | - // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 342 | - do { |
|
| 343 | - $jeton = creer_uniqid(); |
|
| 344 | - sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur)); |
|
| 345 | - } while (sql_countsel("spip_auteurs", "cookie_oubli=" . sql_quote($jeton)) > 1); |
|
| 346 | - |
|
| 347 | - return $jeton; |
|
| 340 | + include_spip('inc/acces'); |
|
| 341 | + // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 342 | + do { |
|
| 343 | + $jeton = creer_uniqid(); |
|
| 344 | + sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur)); |
|
| 345 | + } while (sql_countsel("spip_auteurs", "cookie_oubli=" . sql_quote($jeton)) > 1); |
|
| 346 | + |
|
| 347 | + return $jeton; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -354,15 +354,15 @@ discard block |
||
| 354 | 354 | * @return array|bool |
| 355 | 355 | */ |
| 356 | 356 | function auteur_verifier_jeton($jeton) { |
| 357 | - // refuser un jeton corrompu |
|
| 358 | - if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 359 | - return false; |
|
| 360 | - } |
|
| 357 | + // refuser un jeton corrompu |
|
| 358 | + if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 359 | + return false; |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - // on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter |
|
| 363 | - $desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=" . sql_quote($jeton, '', 'string')); |
|
| 362 | + // on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter |
|
| 363 | + $desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=" . sql_quote($jeton, '', 'string')); |
|
| 364 | 364 | |
| 365 | - return $desc; |
|
| 365 | + return $desc; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -372,5 +372,5 @@ discard block |
||
| 372 | 372 | * @return bool |
| 373 | 373 | */ |
| 374 | 374 | function auteur_effacer_jeton($id_auteur) { |
| 375 | - return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur)); |
|
| 375 | + return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur)); |
|
| 376 | 376 | } |
@@ -314,7 +314,7 @@ |
||
| 314 | 314 | * @param $new_pass |
| 315 | 315 | * @param $id_auteur |
| 316 | 316 | * @param string $serveur |
| 317 | - * @return bool |
|
| 317 | + * @return string|boolean |
|
| 318 | 318 | * Informe du succès ou de l'echec du changement du mot de passe |
| 319 | 319 | */ |
| 320 | 320 | function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 26 | 26 | // ne pas ecraser une definition perso dans mes_options |
| 27 | 27 | if (!isset($GLOBALS['ldap_attributes']) or !is_array($GLOBALS['ldap_attributes'])) { |
| 28 | - $GLOBALS['ldap_attributes'] = array( |
|
| 29 | - 'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'), |
|
| 30 | - 'nom' => "cn", |
|
| 31 | - 'email' => "mail", |
|
| 32 | - 'bio' => "description" |
|
| 33 | - ); |
|
| 28 | + $GLOBALS['ldap_attributes'] = array( |
|
| 29 | + 'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'), |
|
| 30 | + 'nom' => "cn", |
|
| 31 | + 'email' => "mail", |
|
| 32 | + 'bio' => "description" |
|
| 33 | + ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -56,49 +56,49 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function auth_ldap_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 58 | 58 | |
| 59 | - #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | - |
|
| 61 | - // Utilisateur connu ? |
|
| 62 | - // si http auth, inutile de reauthentifier: cela |
|
| 63 | - // ne marchera pas avec auth http autre que basic. |
|
| 64 | - $checkpass = isset($_SERVER["REMOTE_USER"]) ? false : true; |
|
| 65 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | - return array(); |
|
| 67 | - } |
|
| 68 | - $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass); |
|
| 69 | - |
|
| 70 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | - $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | - |
|
| 73 | - if ($r) { |
|
| 74 | - return array_merge($r, $credentials_ldap); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // sinon importer les infos depuis LDAP, |
|
| 78 | - |
|
| 79 | - if ($GLOBALS['meta']["ldap_statut_import"] |
|
| 80 | - and $desc = auth_ldap_retrouver($dn, array(), $serveur) |
|
| 81 | - ) { |
|
| 82 | - // rajouter le statut indique a l'install |
|
| 83 | - $desc['statut'] = $GLOBALS['meta']["ldap_statut_import"]; |
|
| 84 | - $desc['login'] = $login; |
|
| 85 | - $desc['source'] = 'ldap'; |
|
| 86 | - $desc['pass'] = ''; |
|
| 87 | - |
|
| 88 | - $r = sql_insertq('spip_auteurs', $desc, '', $serveur); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($r) { |
|
| 92 | - return array_merge( |
|
| 93 | - $credentials_ldap, |
|
| 94 | - sql_fetsel("*", "spip_auteurs", "id_auteur=" . intval($r), '', '', '', '', $serveur) |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // sinon echec |
|
| 99 | - spip_log("Creation de l'auteur '$login' impossible"); |
|
| 100 | - |
|
| 101 | - return array(); |
|
| 59 | + #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | + |
|
| 61 | + // Utilisateur connu ? |
|
| 62 | + // si http auth, inutile de reauthentifier: cela |
|
| 63 | + // ne marchera pas avec auth http autre que basic. |
|
| 64 | + $checkpass = isset($_SERVER["REMOTE_USER"]) ? false : true; |
|
| 65 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | + return array(); |
|
| 67 | + } |
|
| 68 | + $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass); |
|
| 69 | + |
|
| 70 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | + $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | + |
|
| 73 | + if ($r) { |
|
| 74 | + return array_merge($r, $credentials_ldap); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // sinon importer les infos depuis LDAP, |
|
| 78 | + |
|
| 79 | + if ($GLOBALS['meta']["ldap_statut_import"] |
|
| 80 | + and $desc = auth_ldap_retrouver($dn, array(), $serveur) |
|
| 81 | + ) { |
|
| 82 | + // rajouter le statut indique a l'install |
|
| 83 | + $desc['statut'] = $GLOBALS['meta']["ldap_statut_import"]; |
|
| 84 | + $desc['login'] = $login; |
|
| 85 | + $desc['source'] = 'ldap'; |
|
| 86 | + $desc['pass'] = ''; |
|
| 87 | + |
|
| 88 | + $r = sql_insertq('spip_auteurs', $desc, '', $serveur); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($r) { |
|
| 92 | + return array_merge( |
|
| 93 | + $credentials_ldap, |
|
| 94 | + sql_fetsel("*", "spip_auteurs", "id_auteur=" . intval($r), '', '', '', '', $serveur) |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // sinon echec |
|
| 99 | + spip_log("Creation de l'auteur '$login' impossible"); |
|
| 100 | + |
|
| 101 | + return array(); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -112,36 +112,36 @@ discard block |
||
| 112 | 112 | * @return array |
| 113 | 113 | */ |
| 114 | 114 | function auth_ldap_connect($serveur = '') { |
| 115 | - include_spip('base/connect_sql'); |
|
| 116 | - static $connexions_ldap = array(); |
|
| 117 | - if (isset($connexions_ldap[$serveur])) { |
|
| 118 | - return $connexions_ldap[$serveur]; |
|
| 119 | - } |
|
| 120 | - $connexion = spip_connect($serveur); |
|
| 121 | - if (!is_array($connexion['ldap'])) { |
|
| 122 | - if ($connexion['authentification']['ldap']) { |
|
| 123 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 124 | - unset($GLOBALS['ldap_link']); |
|
| 125 | - if (is_readable($f)) { |
|
| 126 | - include_once($f); |
|
| 127 | - }; |
|
| 128 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 129 | - $connexion['ldap'] = array( |
|
| 130 | - 'link' => $GLOBALS['ldap_link'], |
|
| 131 | - 'base' => $GLOBALS['ldap_base'] |
|
| 132 | - ); |
|
| 133 | - } else { |
|
| 134 | - spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 135 | - } |
|
| 136 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 137 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 138 | - } |
|
| 139 | - } else { |
|
| 140 | - spip_log("connection LDAP $serveur inconnue"); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 115 | + include_spip('base/connect_sql'); |
|
| 116 | + static $connexions_ldap = array(); |
|
| 117 | + if (isset($connexions_ldap[$serveur])) { |
|
| 118 | + return $connexions_ldap[$serveur]; |
|
| 119 | + } |
|
| 120 | + $connexion = spip_connect($serveur); |
|
| 121 | + if (!is_array($connexion['ldap'])) { |
|
| 122 | + if ($connexion['authentification']['ldap']) { |
|
| 123 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 124 | + unset($GLOBALS['ldap_link']); |
|
| 125 | + if (is_readable($f)) { |
|
| 126 | + include_once($f); |
|
| 127 | + }; |
|
| 128 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 129 | + $connexion['ldap'] = array( |
|
| 130 | + 'link' => $GLOBALS['ldap_link'], |
|
| 131 | + 'base' => $GLOBALS['ldap_base'] |
|
| 132 | + ); |
|
| 133 | + } else { |
|
| 134 | + spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 135 | + } |
|
| 136 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 137 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + spip_log("connection LDAP $serveur inconnue"); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -155,52 +155,52 @@ discard block |
||
| 155 | 155 | * Le login trouvé ou chaine vide si non trouvé |
| 156 | 156 | */ |
| 157 | 157 | function auth_ldap_search($login, $pass, $checkpass = true, $serveur = '') { |
| 158 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 159 | - $login_search = preg_replace("/[^-@._\s\d\w]/", "", $login); |
|
| 160 | - if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 161 | - return ''; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // verifier la connexion |
|
| 165 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 166 | - return ''; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
|
| 170 | - $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
|
| 171 | - $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 172 | - |
|
| 173 | - $logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']); |
|
| 174 | - |
|
| 175 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 176 | - foreach ($logins as $att) { |
|
| 177 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", array("dn")); |
|
| 178 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 179 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 180 | - // (on veut un attribut unique) |
|
| 181 | - |
|
| 182 | - if (is_array($info) and $info['count'] == 1) { |
|
| 183 | - $dn = $info[0]['dn']; |
|
| 184 | - if (!$checkpass) { |
|
| 185 | - return $dn; |
|
| 186 | - } |
|
| 187 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 188 | - return $dn; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if ($checkpass and !isset($dn)) { |
|
| 194 | - // Si echec, essayer de deviner le DN |
|
| 195 | - foreach ($logins as $att) { |
|
| 196 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 197 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 198 | - return "$att=$login_search, $ldap_base"; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - return ''; |
|
| 158 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 159 | + $login_search = preg_replace("/[^-@._\s\d\w]/", "", $login); |
|
| 160 | + if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 161 | + return ''; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // verifier la connexion |
|
| 165 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 166 | + return ''; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
|
| 170 | + $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
|
| 171 | + $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 172 | + |
|
| 173 | + $logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']); |
|
| 174 | + |
|
| 175 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 176 | + foreach ($logins as $att) { |
|
| 177 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", array("dn")); |
|
| 178 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 179 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 180 | + // (on veut un attribut unique) |
|
| 181 | + |
|
| 182 | + if (is_array($info) and $info['count'] == 1) { |
|
| 183 | + $dn = $info[0]['dn']; |
|
| 184 | + if (!$checkpass) { |
|
| 185 | + return $dn; |
|
| 186 | + } |
|
| 187 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 188 | + return $dn; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if ($checkpass and !isset($dn)) { |
|
| 194 | + // Si echec, essayer de deviner le DN |
|
| 195 | + foreach ($logins as $att) { |
|
| 196 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 197 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 198 | + return "$att=$login_search, $ldap_base"; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + return ''; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -212,40 +212,40 @@ discard block |
||
| 212 | 212 | * @return array |
| 213 | 213 | */ |
| 214 | 214 | function auth_ldap_retrouver($dn, $desc = array(), $serveur = '') { |
| 215 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 215 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 216 | 216 | |
| 217 | - if (!$ldap = spip_connect_ldap($serveur)) { |
|
| 218 | - spip_log("ldap $serveur injoignable"); |
|
| 217 | + if (!$ldap = spip_connect_ldap($serveur)) { |
|
| 218 | + spip_log("ldap $serveur injoignable"); |
|
| 219 | 219 | |
| 220 | - return array(); |
|
| 221 | - } |
|
| 220 | + return array(); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - $ldap_link = $ldap['link']; |
|
| 224 | - if (!$desc) { |
|
| 225 | - $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 226 | - unset($desc['login']); |
|
| 227 | - } |
|
| 228 | - $result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc)); |
|
| 223 | + $ldap_link = $ldap['link']; |
|
| 224 | + if (!$desc) { |
|
| 225 | + $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 226 | + unset($desc['login']); |
|
| 227 | + } |
|
| 228 | + $result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc)); |
|
| 229 | 229 | |
| 230 | - if (!$result) { |
|
| 231 | - return array(); |
|
| 232 | - } |
|
| 230 | + if (!$result) { |
|
| 231 | + return array(); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 235 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 236 | - if (!is_array($val) or !is_array($val[0])) { |
|
| 237 | - return array(); |
|
| 238 | - } |
|
| 239 | - $val = $val[0]; |
|
| 234 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 235 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 236 | + if (!is_array($val) or !is_array($val[0])) { |
|
| 237 | + return array(); |
|
| 238 | + } |
|
| 239 | + $val = $val[0]; |
|
| 240 | 240 | |
| 241 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 242 | - include_spip('inc/charsets'); |
|
| 241 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 242 | + include_spip('inc/charsets'); |
|
| 243 | 243 | |
| 244 | - foreach ($desc as $k => $v) { |
|
| 245 | - $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 246 | - } |
|
| 244 | + foreach ($desc as $k => $v) { |
|
| 245 | + $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - return $desc; |
|
| 248 | + return $desc; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | 259 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 260 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 260 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -277,9 +277,9 @@ discard block |
||
| 277 | 277 | * Message d'erreur si login non valide, chaîne vide sinon |
| 278 | 278 | */ |
| 279 | 279 | function auth_ldap_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 280 | - include_spip('auth/spip'); |
|
| 280 | + include_spip('auth/spip'); |
|
| 281 | 281 | |
| 282 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 282 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * ``` |
| 301 | 301 | */ |
| 302 | 302 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 303 | - return true; |
|
| 303 | + return true; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -318,23 +318,23 @@ discard block |
||
| 318 | 318 | * Informe du succès ou de l'echec du changement du mot de passe |
| 319 | 319 | */ |
| 320 | 320 | function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 321 | - if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 325 | - return ''; |
|
| 326 | - } |
|
| 327 | - $link = $ldap['link']; |
|
| 328 | - include_spip("inc/session"); |
|
| 329 | - $dn = session_get('ldap_dn'); |
|
| 330 | - if ('' == $dn) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 334 | - return false; |
|
| 335 | - } |
|
| 336 | - $encoded_pass = "{MD5}" . base64_encode(pack("H*", md5($new_pass))); |
|
| 337 | - $success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass)); |
|
| 338 | - |
|
| 339 | - return $success; |
|
| 321 | + if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 325 | + return ''; |
|
| 326 | + } |
|
| 327 | + $link = $ldap['link']; |
|
| 328 | + include_spip("inc/session"); |
|
| 329 | + $dn = session_get('ldap_dn'); |
|
| 330 | + if ('' == $dn) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + $encoded_pass = "{MD5}" . base64_encode(pack("H*", md5($new_pass))); |
|
| 337 | + $success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass)); |
|
| 338 | + |
|
| 339 | + return $success; |
|
| 340 | 340 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass); |
| 69 | 69 | |
| 70 | 70 | // Si l'utilisateur figure deja dans la base, y recuperer les infos |
| 71 | - $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | + $r = sql_fetsel("*", "spip_auteurs", "login=".sql_quote($login)." AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | 72 | |
| 73 | 73 | if ($r) { |
| 74 | 74 | return array_merge($r, $credentials_ldap); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | if ($r) { |
| 92 | 92 | return array_merge( |
| 93 | 93 | $credentials_ldap, |
| 94 | - sql_fetsel("*", "spip_auteurs", "id_auteur=" . intval($r), '', '', '', '', $serveur) |
|
| 94 | + sql_fetsel("*", "spip_auteurs", "id_auteur=".intval($r), '', '', '', '', $serveur) |
|
| 95 | 95 | ); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $connexion = spip_connect($serveur); |
| 121 | 121 | if (!is_array($connexion['ldap'])) { |
| 122 | 122 | if ($connexion['authentification']['ldap']) { |
| 123 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 123 | + $f = _DIR_CONNECT.$connexion['authentification']['ldap']; |
|
| 124 | 124 | unset($GLOBALS['ldap_link']); |
| 125 | 125 | if (is_readable($f)) { |
| 126 | 126 | include_once($f); |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
| 170 | 170 | $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
| 171 | - $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 171 | + $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 172 | 172 | |
| 173 | 173 | $logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']); |
| 174 | 174 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
| 334 | 334 | return false; |
| 335 | 335 | } |
| 336 | - $encoded_pass = "{MD5}" . base64_encode(pack("H*", md5($new_pass))); |
|
| 336 | + $encoded_pass = "{MD5}".base64_encode(pack("H*", md5($new_pass))); |
|
| 337 | 337 | $success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass)); |
| 338 | 338 | |
| 339 | 339 | return $success; |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | * @see trouver_fond() |
| 61 | 61 | * @param string $form |
| 62 | 62 | * Nom du formulaire |
| 63 | - * @return string|bool |
|
| 63 | + * @return string|false |
|
| 64 | 64 | * - string : chemin du squelette |
| 65 | 65 | * - false : pas de squelette trouvé |
| 66 | 66 | **/ |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Formulaires |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/filtres'); |
@@ -34,24 +34,24 @@ discard block |
||
| 34 | 34 | * Saisie protégée |
| 35 | 35 | **/ |
| 36 | 36 | function protege_champ($texte) { |
| 37 | - if (is_array($texte)) { |
|
| 38 | - $texte = array_map('protege_champ', $texte); |
|
| 39 | - } else { |
|
| 40 | - // ne pas corrompre une valeur serialize |
|
| 41 | - if ((preg_match(",^[abis]:\d+[:;],", $texte) and @unserialize($texte) != false) or is_null($texte)) { |
|
| 42 | - return $texte; |
|
| 43 | - } |
|
| 44 | - if (is_string($texte) |
|
| 45 | - and $texte |
|
| 46 | - and strpbrk($texte, "&\"'<>") !== false |
|
| 47 | - ) { |
|
| 48 | - $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 49 | - } elseif (is_bool($texte)) { |
|
| 50 | - $texte = ($texte ? '1' : ''); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return $texte; |
|
| 37 | + if (is_array($texte)) { |
|
| 38 | + $texte = array_map('protege_champ', $texte); |
|
| 39 | + } else { |
|
| 40 | + // ne pas corrompre une valeur serialize |
|
| 41 | + if ((preg_match(",^[abis]:\d+[:;],", $texte) and @unserialize($texte) != false) or is_null($texte)) { |
|
| 42 | + return $texte; |
|
| 43 | + } |
|
| 44 | + if (is_string($texte) |
|
| 45 | + and $texte |
|
| 46 | + and strpbrk($texte, "&\"'<>") !== false |
|
| 47 | + ) { |
|
| 48 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 49 | + } elseif (is_bool($texte)) { |
|
| 50 | + $texte = ($texte ? '1' : ''); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return $texte; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -65,17 +65,17 @@ discard block |
||
| 65 | 65 | * - false : pas de squelette trouvé |
| 66 | 66 | **/ |
| 67 | 67 | function existe_formulaire($form) { |
| 68 | - if (substr($form, 0, 11) == "FORMULAIRE_") { |
|
| 69 | - $form = strtolower(substr($form, 11)); |
|
| 70 | - } else { |
|
| 71 | - $form = strtolower($form); |
|
| 72 | - } |
|
| 68 | + if (substr($form, 0, 11) == "FORMULAIRE_") { |
|
| 69 | + $form = strtolower(substr($form, 11)); |
|
| 70 | + } else { |
|
| 71 | + $form = strtolower($form); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - if (!$form) { |
|
| 75 | - return ''; |
|
| 76 | - } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 74 | + if (!$form) { |
|
| 75 | + return ''; |
|
| 76 | + } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 77 | 77 | |
| 78 | - return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 78 | + return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,29 +84,29 @@ discard block |
||
| 84 | 84 | * @return false|array |
| 85 | 85 | */ |
| 86 | 86 | function test_formulaire_inclus_par_modele() { |
| 87 | - $trace = debug_backtrace(null, 20); |
|
| 88 | - $trace_fonctions = array_column($trace, 'function'); |
|
| 89 | - $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 90 | - |
|
| 91 | - // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 92 | - if (function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | - and $form = arguments_balise_dyn_depuis_modele(null, 'read')) { |
|
| 94 | - if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 95 | - $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 96 | - if ($trace[$k]['args'][0] === $form) { |
|
| 97 | - return $trace[$k]['args']; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 103 | - // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 104 | - if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 105 | - $k = array_search('inclure_modele', $trace_fonctions); |
|
| 106 | - // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 107 | - return $trace[$k-1]['args'][1]['args']; |
|
| 108 | - } |
|
| 109 | - return false; |
|
| 87 | + $trace = debug_backtrace(null, 20); |
|
| 88 | + $trace_fonctions = array_column($trace, 'function'); |
|
| 89 | + $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 90 | + |
|
| 91 | + // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 92 | + if (function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | + and $form = arguments_balise_dyn_depuis_modele(null, 'read')) { |
|
| 94 | + if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 95 | + $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 96 | + if ($trace[$k]['args'][0] === $form) { |
|
| 97 | + return $trace[$k]['args']; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 103 | + // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 104 | + if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 105 | + $k = array_search('inclure_modele', $trace_fonctions); |
|
| 106 | + // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 107 | + return $trace[$k-1]['args'][1]['args']; |
|
| 108 | + } |
|
| 109 | + return false; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -121,17 +121,17 @@ discard block |
||
| 121 | 121 | **/ |
| 122 | 122 | function balise_FORMULAIRE__dist($p) { |
| 123 | 123 | |
| 124 | - // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 125 | - // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 126 | - if (existe_formulaire($p->nom_champ) === false) { |
|
| 127 | - $p->code = "''"; |
|
| 128 | - $p->interdire_scripts = false; |
|
| 124 | + // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 125 | + // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 126 | + if (existe_formulaire($p->nom_champ) === false) { |
|
| 127 | + $p->code = "''"; |
|
| 128 | + $p->interdire_scripts = false; |
|
| 129 | 129 | |
| 130 | - return $p; |
|
| 131 | - } |
|
| 130 | + return $p; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // sinon renvoyer un code php dynamique |
|
| 134 | - return calculer_balise_dynamique($p, $p->nom_champ, array()); |
|
| 133 | + // sinon renvoyer un code php dynamique |
|
| 134 | + return calculer_balise_dynamique($p, $p->nom_champ, array()); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -144,27 +144,27 @@ discard block |
||
| 144 | 144 | * - string : texte à afficher directement |
| 145 | 145 | */ |
| 146 | 146 | function balise_FORMULAIRE__dyn($form) { |
| 147 | - $form = existe_formulaire($form); |
|
| 148 | - if (!$form) { |
|
| 149 | - return ''; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // deux moyen d'arriver ici : |
|
| 153 | - // soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg |
|
| 154 | - // soit #FORMULAIRE_{xx} |
|
| 155 | - |
|
| 156 | - // recuperer les arguments passes a la balise |
|
| 157 | - // on enleve le premier qui est le nom de la balise |
|
| 158 | - // deja recupere ci-dessus |
|
| 159 | - |
|
| 160 | - $args = func_get_args(); |
|
| 161 | - array_shift($args); |
|
| 162 | - $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 163 | - if (!is_array($contexte)) { |
|
| 164 | - return $contexte; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return array("formulaires/$form", 3600, $contexte); |
|
| 147 | + $form = existe_formulaire($form); |
|
| 148 | + if (!$form) { |
|
| 149 | + return ''; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // deux moyen d'arriver ici : |
|
| 153 | + // soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg |
|
| 154 | + // soit #FORMULAIRE_{xx} |
|
| 155 | + |
|
| 156 | + // recuperer les arguments passes a la balise |
|
| 157 | + // on enleve le premier qui est le nom de la balise |
|
| 158 | + // deja recupere ci-dessus |
|
| 159 | + |
|
| 160 | + $args = func_get_args(); |
|
| 161 | + array_shift($args); |
|
| 162 | + $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 163 | + if (!is_array($contexte)) { |
|
| 164 | + return $contexte; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return array("formulaires/$form", 3600, $contexte); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -178,120 +178,120 @@ discard block |
||
| 178 | 178 | * Contexte d'environnement à envoyer au squelette |
| 179 | 179 | **/ |
| 180 | 180 | function balise_FORMULAIRE__contexte($form, $args) { |
| 181 | - // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 182 | - // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 183 | - // si poste, on recupere les erreurs |
|
| 184 | - |
|
| 185 | - $je_suis_poste = false; |
|
| 186 | - if ($post_form = _request('formulaire_action') |
|
| 187 | - and $post_form == $form |
|
| 188 | - and $p = _request('formulaire_action_args') |
|
| 189 | - and is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 190 | - ) { |
|
| 191 | - // enlever le faux attribut de langue masque |
|
| 192 | - array_shift($p); |
|
| 193 | - if (formulaire__identifier($form, $args, $p)) { |
|
| 194 | - $je_suis_poste = true; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $editable = true; |
|
| 199 | - $erreurs = $post = array(); |
|
| 200 | - if ($je_suis_poste) { |
|
| 201 | - $post = traiter_formulaires_dynamiques(true); |
|
| 202 | - $e = "erreurs_$form"; |
|
| 203 | - $erreurs = isset($post[$e]) ? $post[$e] : array(); |
|
| 204 | - $editable = "editable_$form"; |
|
| 205 | - $editable = (!isset($post[$e])) |
|
| 206 | - || count($erreurs) |
|
| 207 | - || (isset($post[$editable]) && $post[$editable]); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 211 | - |
|
| 212 | - // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 213 | - // C'est plus fort qu'editable qui est gere par le squelette |
|
| 214 | - // Idealement $valeur doit etre alors un message explicatif. |
|
| 215 | - if (!is_array($valeurs)) { |
|
| 216 | - return is_string($valeurs) ? $valeurs : ''; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 220 | - // ou une action vide si elle ne sert pas |
|
| 221 | - $action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&', true); |
|
| 222 | - // bug IEx : si action finit par / |
|
| 223 | - // IE croit que le <form ... action=../ > est autoferme |
|
| 224 | - if (substr($action, -1) == '/') { |
|
| 225 | - // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 226 | - $action .= '#'; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // recuperer la saisie en cours si erreurs |
|
| 230 | - // seulement si c'est ce formulaire qui est poste |
|
| 231 | - // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 232 | - $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 233 | - foreach (array_keys($valeurs) as $champ) { |
|
| 234 | - if ($champ[0] !== '_' and !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) { |
|
| 235 | - if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 236 | - $valeurs[$champ] = $v; |
|
| 237 | - } |
|
| 238 | - // nettoyer l'url des champs qui vont etre saisis |
|
| 239 | - if ($action) { |
|
| 240 | - $action = parametre_url($action, $champ, ''); |
|
| 241 | - } |
|
| 242 | - // proteger les ' et les " dans les champs que l'on va injecter |
|
| 243 | - $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if ($action) { |
|
| 248 | - // nettoyer l'url |
|
| 249 | - $action = parametre_url($action, 'formulaire_action', ''); |
|
| 250 | - $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - if (isset($valeurs['_action'])) { |
|
| 254 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 255 | - $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
|
| 256 | - $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') . |
|
| 257 | - "<input type='hidden' name='arg' value='" . $secu['arg'] . "' />" |
|
| 258 | - . "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />"; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // empiler la lang en tant que premier argument implicite du CVT |
|
| 262 | - // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 263 | - array_unshift($args, $GLOBALS['spip_lang']); |
|
| 264 | - |
|
| 265 | - $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 266 | - $valeurs['erreurs'] = $erreurs; |
|
| 267 | - $valeurs['action'] = $action; |
|
| 268 | - $valeurs['form'] = $form; |
|
| 269 | - |
|
| 270 | - if (!isset($valeurs['id'])) { |
|
| 271 | - $valeurs['id'] = 'new'; |
|
| 272 | - } |
|
| 273 | - // editable peut venir de charger() ou de traiter() sinon |
|
| 274 | - if (!isset($valeurs['editable'])) { |
|
| 275 | - $valeurs['editable'] = $editable; |
|
| 276 | - } |
|
| 277 | - // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 278 | - $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 279 | - |
|
| 280 | - if ($je_suis_poste) { |
|
| 281 | - $valeurs['message_erreur'] = ""; |
|
| 282 | - if (isset($erreurs['message_erreur'])) { |
|
| 283 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $valeurs['message_ok'] = ""; |
|
| 287 | - if (isset($post["message_ok_$form"])) { |
|
| 288 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 289 | - } elseif (isset($erreurs['message_ok'])) { |
|
| 290 | - $valeurs['message_ok'] = $erreurs["message_ok"]; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - return $valeurs; |
|
| 181 | + // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 182 | + // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 183 | + // si poste, on recupere les erreurs |
|
| 184 | + |
|
| 185 | + $je_suis_poste = false; |
|
| 186 | + if ($post_form = _request('formulaire_action') |
|
| 187 | + and $post_form == $form |
|
| 188 | + and $p = _request('formulaire_action_args') |
|
| 189 | + and is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 190 | + ) { |
|
| 191 | + // enlever le faux attribut de langue masque |
|
| 192 | + array_shift($p); |
|
| 193 | + if (formulaire__identifier($form, $args, $p)) { |
|
| 194 | + $je_suis_poste = true; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $editable = true; |
|
| 199 | + $erreurs = $post = array(); |
|
| 200 | + if ($je_suis_poste) { |
|
| 201 | + $post = traiter_formulaires_dynamiques(true); |
|
| 202 | + $e = "erreurs_$form"; |
|
| 203 | + $erreurs = isset($post[$e]) ? $post[$e] : array(); |
|
| 204 | + $editable = "editable_$form"; |
|
| 205 | + $editable = (!isset($post[$e])) |
|
| 206 | + || count($erreurs) |
|
| 207 | + || (isset($post[$editable]) && $post[$editable]); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 211 | + |
|
| 212 | + // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 213 | + // C'est plus fort qu'editable qui est gere par le squelette |
|
| 214 | + // Idealement $valeur doit etre alors un message explicatif. |
|
| 215 | + if (!is_array($valeurs)) { |
|
| 216 | + return is_string($valeurs) ? $valeurs : ''; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 220 | + // ou une action vide si elle ne sert pas |
|
| 221 | + $action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&', true); |
|
| 222 | + // bug IEx : si action finit par / |
|
| 223 | + // IE croit que le <form ... action=../ > est autoferme |
|
| 224 | + if (substr($action, -1) == '/') { |
|
| 225 | + // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 226 | + $action .= '#'; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // recuperer la saisie en cours si erreurs |
|
| 230 | + // seulement si c'est ce formulaire qui est poste |
|
| 231 | + // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 232 | + $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 233 | + foreach (array_keys($valeurs) as $champ) { |
|
| 234 | + if ($champ[0] !== '_' and !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) { |
|
| 235 | + if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 236 | + $valeurs[$champ] = $v; |
|
| 237 | + } |
|
| 238 | + // nettoyer l'url des champs qui vont etre saisis |
|
| 239 | + if ($action) { |
|
| 240 | + $action = parametre_url($action, $champ, ''); |
|
| 241 | + } |
|
| 242 | + // proteger les ' et les " dans les champs que l'on va injecter |
|
| 243 | + $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if ($action) { |
|
| 248 | + // nettoyer l'url |
|
| 249 | + $action = parametre_url($action, 'formulaire_action', ''); |
|
| 250 | + $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + if (isset($valeurs['_action'])) { |
|
| 254 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 255 | + $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
|
| 256 | + $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') . |
|
| 257 | + "<input type='hidden' name='arg' value='" . $secu['arg'] . "' />" |
|
| 258 | + . "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />"; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // empiler la lang en tant que premier argument implicite du CVT |
|
| 262 | + // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 263 | + array_unshift($args, $GLOBALS['spip_lang']); |
|
| 264 | + |
|
| 265 | + $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 266 | + $valeurs['erreurs'] = $erreurs; |
|
| 267 | + $valeurs['action'] = $action; |
|
| 268 | + $valeurs['form'] = $form; |
|
| 269 | + |
|
| 270 | + if (!isset($valeurs['id'])) { |
|
| 271 | + $valeurs['id'] = 'new'; |
|
| 272 | + } |
|
| 273 | + // editable peut venir de charger() ou de traiter() sinon |
|
| 274 | + if (!isset($valeurs['editable'])) { |
|
| 275 | + $valeurs['editable'] = $editable; |
|
| 276 | + } |
|
| 277 | + // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 278 | + $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 279 | + |
|
| 280 | + if ($je_suis_poste) { |
|
| 281 | + $valeurs['message_erreur'] = ""; |
|
| 282 | + if (isset($erreurs['message_erreur'])) { |
|
| 283 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $valeurs['message_ok'] = ""; |
|
| 287 | + if (isset($post["message_ok_$form"])) { |
|
| 288 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 289 | + } elseif (isset($erreurs['message_ok'])) { |
|
| 290 | + $valeurs['message_ok'] = $erreurs["message_ok"]; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + return $valeurs; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -303,51 +303,51 @@ discard block |
||
| 303 | 303 | * @return array |
| 304 | 304 | */ |
| 305 | 305 | function formulaire__charger($form, $args, $poste) { |
| 306 | - if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) { |
|
| 307 | - $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 308 | - } else { |
|
| 309 | - $valeurs = array(); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $valeurs = pipeline( |
|
| 313 | - 'formulaire_charger', |
|
| 314 | - array( |
|
| 315 | - 'args' => array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), |
|
| 316 | - 'data' => $valeurs |
|
| 317 | - ) |
|
| 318 | - ); |
|
| 319 | - |
|
| 320 | - // prise en charge CVT multi etape |
|
| 321 | - if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 322 | - include_spip('inc/cvt_multietapes'); |
|
| 323 | - $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 324 | - array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), |
|
| 325 | - $valeurs |
|
| 326 | - ); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 330 | - if (is_array($valeurs)) { |
|
| 331 | - if (!isset($valeurs['_pipelines'])) { |
|
| 332 | - $valeurs['_pipelines'] = array(); |
|
| 333 | - } |
|
| 334 | - // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 335 | - // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 336 | - if (isset($valeurs['_pipeline'])) { |
|
| 337 | - $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 338 | - $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : array(); |
|
| 339 | - |
|
| 340 | - $pipelines = array($pipe => $args); |
|
| 341 | - $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 345 | - // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 346 | - // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 347 | - $valeurs['_pipelines']['formulaire_fond'] = array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return $valeurs; |
|
| 306 | + if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) { |
|
| 307 | + $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 308 | + } else { |
|
| 309 | + $valeurs = array(); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $valeurs = pipeline( |
|
| 313 | + 'formulaire_charger', |
|
| 314 | + array( |
|
| 315 | + 'args' => array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), |
|
| 316 | + 'data' => $valeurs |
|
| 317 | + ) |
|
| 318 | + ); |
|
| 319 | + |
|
| 320 | + // prise en charge CVT multi etape |
|
| 321 | + if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 322 | + include_spip('inc/cvt_multietapes'); |
|
| 323 | + $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 324 | + array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), |
|
| 325 | + $valeurs |
|
| 326 | + ); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 330 | + if (is_array($valeurs)) { |
|
| 331 | + if (!isset($valeurs['_pipelines'])) { |
|
| 332 | + $valeurs['_pipelines'] = array(); |
|
| 333 | + } |
|
| 334 | + // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 335 | + // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 336 | + if (isset($valeurs['_pipeline'])) { |
|
| 337 | + $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 338 | + $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : array(); |
|
| 339 | + |
|
| 340 | + $pipelines = array($pipe => $args); |
|
| 341 | + $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 345 | + // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 346 | + // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 347 | + $valeurs['_pipelines']['formulaire_fond'] = array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return $valeurs; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -366,9 +366,9 @@ discard block |
||
| 366 | 366 | * @return bool |
| 367 | 367 | */ |
| 368 | 368 | function formulaire__identifier($form, $args, $p) { |
| 369 | - if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) { |
|
| 370 | - return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p); |
|
| 371 | - } |
|
| 369 | + if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) { |
|
| 370 | + return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p); |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - return $args === $p; |
|
| 373 | + return $args === $p; |
|
| 374 | 374 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
| 105 | 105 | $k = array_search('inclure_modele', $trace_fonctions); |
| 106 | 106 | // les arguments de recuperer_fond() passes par inclure_modele() |
| 107 | - return $trace[$k-1]['args'][1]['args']; |
|
| 107 | + return $trace[$k - 1]['args'][1]['args']; |
|
| 108 | 108 | } |
| 109 | 109 | return false; |
| 110 | 110 | } |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | if (isset($valeurs['_action'])) { |
| 254 | 254 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
| 255 | 255 | $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
| 256 | - $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') . |
|
| 257 | - "<input type='hidden' name='arg' value='" . $secu['arg'] . "' />" |
|
| 258 | - . "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />"; |
|
| 256 | + $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : ''). |
|
| 257 | + "<input type='hidden' name='arg' value='".$secu['arg']."' />" |
|
| 258 | + . "<input type='hidden' name='hash' value='".$secu['hash']."' />"; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // empiler la lang en tant que premier argument implicite du CVT |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * |
| 37 | 37 | * @param string $serveur Nom du connecteur |
| 38 | 38 | * @param string $version Version de l'API SQL |
| 39 | - * @return bool|array |
|
| 39 | + * @return string |
|
| 40 | 40 | * - false si la connexion a échouée, |
| 41 | 41 | * - tableau décrivant la connexion sinon |
| 42 | 42 | **/ |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | 19 | return; |
| 20 | 20 | } |
| 21 | -require_once _ROOT_RESTREINT . 'base/objets.php'; |
|
| 21 | +require_once _ROOT_RESTREINT.'base/objets.php'; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
| 60 | 60 | ? '' // nom de serveur mal ecrit |
| 61 | 61 | : ($serveur ? |
| 62 | - (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 62 | + (_DIR_CONNECT.$serveur.'.php') // serveur externe |
|
| 63 | 63 | : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
| 64 | 64 | : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
| 65 | 65 | : ''))); // installation pas faite |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | // chargement de la version du jeu de fonctions |
| 103 | 103 | // si pas dans le fichier par defaut |
| 104 | 104 | $type = $GLOBALS['db_ok']['type']; |
| 105 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 105 | + $jeu = 'spip_'.$type.'_functions_'.$version; |
|
| 106 | 106 | if (!isset($GLOBALS[$jeu])) { |
| 107 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 107 | + if (!find_in_path($type.'_'.$version.'.php', 'req/', true)) { |
|
| 108 | 108 | spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
| 109 | 109 | |
| 110 | 110 | // ne plus reessayer |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | $connexion = spip_connect($serveur); |
| 166 | 166 | $e = sql_errno($serveur); |
| 167 | 167 | $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
| 168 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | - $f = $t . $serveur; |
|
| 170 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 168 | + $m = "Erreur $e de $t: ".sql_error($serveur)."\nin ".sql_error_backtrace()."\n".trim($connexion['last']); |
|
| 169 | + $f = $t.$serveur; |
|
| 170 | + spip_log($m, $f.'.'._LOG_ERREUR); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | // si en cours d'installation ou si db=@test@ on ne pose rien |
| 250 | 250 | // car c'est un test de connexion |
| 251 | 251 | if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") { |
| 252 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 252 | + $f = _DIR_TMP.$type.'.'.substr(md5($host.$port.$db), 0, 8).'.out'; |
|
| 253 | 253 | } elseif ($db == '@test@') { |
| 254 | 254 | $db = ''; |
| 255 | 255 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | // En cas d'indisponibilite du serveur, eviter de le bombarder |
| 290 | 290 | if ($f) { |
| 291 | 291 | @touch($f); |
| 292 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 292 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | |
@@ -379,8 +379,7 @@ discard block |
||
| 379 | 379 | * @return string Valeur échappée. |
| 380 | 380 | **/ |
| 381 | 381 | function _q($a) { |
| 382 | - return (is_numeric($a)) ? strval($a) : |
|
| 383 | - (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 382 | + return (is_numeric($a)) ? strval($a) : (!is_array($a) ? ("'".addslashes($a)."'") |
|
| 384 | 383 | : join(",", array_map('_q', $a))); |
| 385 | 384 | } |
| 386 | 385 | |
@@ -452,7 +451,7 @@ discard block |
||
| 452 | 451 | break; |
| 453 | 452 | default: |
| 454 | 453 | $replace = range(1, count($textes)); |
| 455 | - $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 454 | + $replace = '%'.implode('$s,%', $replace).'$s'; |
|
| 456 | 455 | $replace = explode(',', $replace); |
| 457 | 456 | break; |
| 458 | 457 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 22 | 22 | |
@@ -42,118 +42,118 @@ discard block |
||
| 42 | 42 | **/ |
| 43 | 43 | function spip_connect($serveur = '', $version = '') { |
| 44 | 44 | |
| 45 | - $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | - $index = $serveur ? $serveur : 0; |
|
| 47 | - if (!$version) { |
|
| 48 | - $version = $GLOBALS['spip_sql_version']; |
|
| 49 | - } |
|
| 50 | - if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | - return $GLOBALS['connexions'][$index]; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - include_spip('base/abstract_sql'); |
|
| 55 | - $install = (_request('exec') == 'install'); |
|
| 56 | - |
|
| 57 | - // Premiere connexion ? |
|
| 58 | - if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | - $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | - ? '' // nom de serveur mal ecrit |
|
| 61 | - : ($serveur ? |
|
| 62 | - (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | - : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
|
| 64 | - : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 65 | - : ''))); // installation pas faite |
|
| 66 | - |
|
| 67 | - unset($GLOBALS['db_ok']); |
|
| 68 | - unset($GLOBALS['spip_connect_version']); |
|
| 69 | - if ($f) { |
|
| 70 | - if (is_readable($f)) { |
|
| 71 | - include($f); |
|
| 72 | - } elseif ($serveur and !$install) { |
|
| 73 | - // chercher une declaration de serveur dans le path |
|
| 74 | - // qui pourra un jour servir a declarer des bases sqlite |
|
| 75 | - // par des plugins. Et sert aussi aux boucles POUR. |
|
| 76 | - find_in_path("$serveur.php", 'connect/', true); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 80 | - // fera mieux la prochaine fois |
|
| 81 | - if ($install) { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 84 | - if ($f and is_readable($f)) { |
|
| 85 | - spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 86 | - } else { |
|
| 87 | - spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 88 | - } |
|
| 89 | - spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 90 | - |
|
| 91 | - // ne plus reessayer si ce n'est pas l'install |
|
| 92 | - return $GLOBALS['connexions'][$index] = false; |
|
| 93 | - } |
|
| 94 | - $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 95 | - } |
|
| 96 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 97 | - if (!$GLOBALS['connexions'][$index]) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // la connexion a reussi ou etait deja faite. |
|
| 102 | - // chargement de la version du jeu de fonctions |
|
| 103 | - // si pas dans le fichier par defaut |
|
| 104 | - $type = $GLOBALS['db_ok']['type']; |
|
| 105 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 106 | - if (!isset($GLOBALS[$jeu])) { |
|
| 107 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 108 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 109 | - |
|
| 110 | - // ne plus reessayer |
|
| 111 | - return $GLOBALS['connexions'][$index][$version] = array(); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 115 | - if ($old) { |
|
| 116 | - return $GLOBALS['connexions'][$index]; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
|
| 120 | - |
|
| 121 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 122 | - // si l'installation l'a determine. |
|
| 123 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 124 | - // s'ils le connaissent |
|
| 125 | - |
|
| 126 | - if (!$serveur) { |
|
| 127 | - $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 128 | - if (!$charset) { |
|
| 129 | - unset($GLOBALS['connexions'][$index]); |
|
| 130 | - spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT); |
|
| 131 | - |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - } else { |
|
| 135 | - if ($GLOBALS['db_ok']['charset']) { |
|
| 136 | - $charset = $GLOBALS['db_ok']['charset']; |
|
| 137 | - } |
|
| 138 | - // spip_meta n'existe pas toujours dans la base |
|
| 139 | - // C'est le cas d'un dump sqlite par exemple |
|
| 140 | - elseif ($GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | - and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | - and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | - ) { |
|
| 144 | - $charset = $r; |
|
| 145 | - } else { |
|
| 146 | - $charset = -1; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - if ($charset != -1) { |
|
| 150 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | - if (function_exists($f)) { |
|
| 152 | - $f($charset, $serveur); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $GLOBALS['connexions'][$index]; |
|
| 45 | + $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | + $index = $serveur ? $serveur : 0; |
|
| 47 | + if (!$version) { |
|
| 48 | + $version = $GLOBALS['spip_sql_version']; |
|
| 49 | + } |
|
| 50 | + if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | + return $GLOBALS['connexions'][$index]; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + include_spip('base/abstract_sql'); |
|
| 55 | + $install = (_request('exec') == 'install'); |
|
| 56 | + |
|
| 57 | + // Premiere connexion ? |
|
| 58 | + if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | + $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | + ? '' // nom de serveur mal ecrit |
|
| 61 | + : ($serveur ? |
|
| 62 | + (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | + : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
|
| 64 | + : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 65 | + : ''))); // installation pas faite |
|
| 66 | + |
|
| 67 | + unset($GLOBALS['db_ok']); |
|
| 68 | + unset($GLOBALS['spip_connect_version']); |
|
| 69 | + if ($f) { |
|
| 70 | + if (is_readable($f)) { |
|
| 71 | + include($f); |
|
| 72 | + } elseif ($serveur and !$install) { |
|
| 73 | + // chercher une declaration de serveur dans le path |
|
| 74 | + // qui pourra un jour servir a declarer des bases sqlite |
|
| 75 | + // par des plugins. Et sert aussi aux boucles POUR. |
|
| 76 | + find_in_path("$serveur.php", 'connect/', true); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 80 | + // fera mieux la prochaine fois |
|
| 81 | + if ($install) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | + if ($f and is_readable($f)) { |
|
| 85 | + spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 86 | + } else { |
|
| 87 | + spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 88 | + } |
|
| 89 | + spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 90 | + |
|
| 91 | + // ne plus reessayer si ce n'est pas l'install |
|
| 92 | + return $GLOBALS['connexions'][$index] = false; |
|
| 93 | + } |
|
| 94 | + $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 95 | + } |
|
| 96 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 97 | + if (!$GLOBALS['connexions'][$index]) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // la connexion a reussi ou etait deja faite. |
|
| 102 | + // chargement de la version du jeu de fonctions |
|
| 103 | + // si pas dans le fichier par defaut |
|
| 104 | + $type = $GLOBALS['db_ok']['type']; |
|
| 105 | + $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 106 | + if (!isset($GLOBALS[$jeu])) { |
|
| 107 | + if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 108 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 109 | + |
|
| 110 | + // ne plus reessayer |
|
| 111 | + return $GLOBALS['connexions'][$index][$version] = array(); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 115 | + if ($old) { |
|
| 116 | + return $GLOBALS['connexions'][$index]; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
|
| 120 | + |
|
| 121 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 122 | + // si l'installation l'a determine. |
|
| 123 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 124 | + // s'ils le connaissent |
|
| 125 | + |
|
| 126 | + if (!$serveur) { |
|
| 127 | + $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 128 | + if (!$charset) { |
|
| 129 | + unset($GLOBALS['connexions'][$index]); |
|
| 130 | + spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT); |
|
| 131 | + |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + } else { |
|
| 135 | + if ($GLOBALS['db_ok']['charset']) { |
|
| 136 | + $charset = $GLOBALS['db_ok']['charset']; |
|
| 137 | + } |
|
| 138 | + // spip_meta n'existe pas toujours dans la base |
|
| 139 | + // C'est le cas d'un dump sqlite par exemple |
|
| 140 | + elseif ($GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | + and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | + and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | + ) { |
|
| 144 | + $charset = $r; |
|
| 145 | + } else { |
|
| 146 | + $charset = -1; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + if ($charset != -1) { |
|
| 150 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | + if (function_exists($f)) { |
|
| 152 | + $f($charset, $serveur); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $GLOBALS['connexions'][$index]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | * @param string $serveur Nom du connecteur de bdd utilisé |
| 163 | 163 | **/ |
| 164 | 164 | function spip_sql_erreur($serveur = '') { |
| 165 | - $connexion = spip_connect($serveur); |
|
| 166 | - $e = sql_errno($serveur); |
|
| 167 | - $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
|
| 168 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | - $f = $t . $serveur; |
|
| 170 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 165 | + $connexion = spip_connect($serveur); |
|
| 166 | + $e = sql_errno($serveur); |
|
| 167 | + $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
|
| 168 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | + $f = $t . $serveur; |
|
| 170 | + spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -189,19 +189,19 @@ discard block |
||
| 189 | 189 | * - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion |
| 190 | 190 | **/ |
| 191 | 191 | function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) { |
| 192 | - $desc = spip_connect($serveur, $version); |
|
| 193 | - if (function_exists($f = @$desc[$version][$ins])) { |
|
| 194 | - return $f; |
|
| 195 | - } |
|
| 196 | - if ($continue) { |
|
| 197 | - return $desc; |
|
| 198 | - } |
|
| 199 | - if ($ins) { |
|
| 200 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 201 | - } |
|
| 202 | - include_spip('inc/minipres'); |
|
| 203 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503)); |
|
| 204 | - exit; |
|
| 192 | + $desc = spip_connect($serveur, $version); |
|
| 193 | + if (function_exists($f = @$desc[$version][$ins])) { |
|
| 194 | + return $f; |
|
| 195 | + } |
|
| 196 | + if ($continue) { |
|
| 197 | + return $desc; |
|
| 198 | + } |
|
| 199 | + if ($ins) { |
|
| 200 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 201 | + } |
|
| 202 | + include_spip('inc/minipres'); |
|
| 203 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503)); |
|
| 204 | + exit; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -227,70 +227,70 @@ discard block |
||
| 227 | 227 | * @return array Description de la connexion |
| 228 | 228 | */ |
| 229 | 229 | function spip_connect_db( |
| 230 | - $host, |
|
| 231 | - $port, |
|
| 232 | - $login, |
|
| 233 | - $pass, |
|
| 234 | - $db = '', |
|
| 235 | - $type = 'mysql', |
|
| 236 | - $prefixe = '', |
|
| 237 | - $auth = '', |
|
| 238 | - $charset = '' |
|
| 230 | + $host, |
|
| 231 | + $port, |
|
| 232 | + $login, |
|
| 233 | + $pass, |
|
| 234 | + $db = '', |
|
| 235 | + $type = 'mysql', |
|
| 236 | + $prefixe = '', |
|
| 237 | + $auth = '', |
|
| 238 | + $charset = '' |
|
| 239 | 239 | ) { |
| 240 | - // temps avant nouvelle tentative de connexion |
|
| 241 | - // suite a une connection echouee |
|
| 242 | - if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 243 | - define('_CONNECT_RETRY_DELAY', 30); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $f = ""; |
|
| 247 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 248 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 249 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 250 | - // car c'est un test de connexion |
|
| 251 | - if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") { |
|
| 252 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 253 | - } elseif ($db == '@test@') { |
|
| 254 | - $db = ''; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ($f |
|
| 258 | - and @file_exists($f) |
|
| 259 | - and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 260 | - ) { |
|
| 261 | - spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 262 | - |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - if (!$prefixe) { |
|
| 267 | - $prefixe = isset($GLOBALS['table_prefix']) |
|
| 268 | - ? $GLOBALS['table_prefix'] : $db; |
|
| 269 | - } |
|
| 270 | - $h = charger_fonction($type, 'req', true); |
|
| 271 | - if (!$h) { |
|
| 272 | - spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 273 | - |
|
| 274 | - return; |
|
| 275 | - } |
|
| 276 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 277 | - |
|
| 278 | - if (!is_array($auth)) { |
|
| 279 | - // compatibilite version 0.7 initiale |
|
| 280 | - $g['ldap'] = $auth; |
|
| 281 | - $auth = array('ldap' => $auth); |
|
| 282 | - } |
|
| 283 | - $g['authentification'] = $auth; |
|
| 284 | - $g['type'] = $type; |
|
| 285 | - $g['charset'] = $charset; |
|
| 286 | - |
|
| 287 | - return $GLOBALS['db_ok'] = $g; |
|
| 288 | - } |
|
| 289 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 290 | - if ($f) { |
|
| 291 | - @touch($f); |
|
| 292 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 293 | - } |
|
| 240 | + // temps avant nouvelle tentative de connexion |
|
| 241 | + // suite a une connection echouee |
|
| 242 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 243 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $f = ""; |
|
| 247 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 248 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 249 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 250 | + // car c'est un test de connexion |
|
| 251 | + if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") { |
|
| 252 | + $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 253 | + } elseif ($db == '@test@') { |
|
| 254 | + $db = ''; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ($f |
|
| 258 | + and @file_exists($f) |
|
| 259 | + and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 260 | + ) { |
|
| 261 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 262 | + |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + if (!$prefixe) { |
|
| 267 | + $prefixe = isset($GLOBALS['table_prefix']) |
|
| 268 | + ? $GLOBALS['table_prefix'] : $db; |
|
| 269 | + } |
|
| 270 | + $h = charger_fonction($type, 'req', true); |
|
| 271 | + if (!$h) { |
|
| 272 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 273 | + |
|
| 274 | + return; |
|
| 275 | + } |
|
| 276 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 277 | + |
|
| 278 | + if (!is_array($auth)) { |
|
| 279 | + // compatibilite version 0.7 initiale |
|
| 280 | + $g['ldap'] = $auth; |
|
| 281 | + $auth = array('ldap' => $auth); |
|
| 282 | + } |
|
| 283 | + $g['authentification'] = $auth; |
|
| 284 | + $g['type'] = $type; |
|
| 285 | + $g['charset'] = $charset; |
|
| 286 | + |
|
| 287 | + return $GLOBALS['db_ok'] = $g; |
|
| 288 | + } |
|
| 289 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 290 | + if ($f) { |
|
| 291 | + @touch($f); |
|
| 292 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 293 | + } |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -322,31 +322,31 @@ discard block |
||
| 322 | 322 | * - nom du charset sinon |
| 323 | 323 | **/ |
| 324 | 324 | function spip_connect_main($connexion, $charset_sql_connexion = '') { |
| 325 | - if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 326 | - include_spip('inc/headers'); |
|
| 327 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if (!($f = $connexion['select'])) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - // si le charset est fourni, l'utiliser |
|
| 334 | - if ($charset_sql_connexion) { |
|
| 335 | - return $charset_sql_connexion; |
|
| 336 | - } |
|
| 337 | - // sinon on regarde la table spip_meta |
|
| 338 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 339 | - if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 340 | - or is_string($r) |
|
| 341 | - ) { |
|
| 342 | - return false; |
|
| 343 | - } |
|
| 344 | - if (!($f = $connexion['fetch'])) { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - $r = $f($r); |
|
| 348 | - |
|
| 349 | - return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 325 | + if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 326 | + include_spip('inc/headers'); |
|
| 327 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if (!($f = $connexion['select'])) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + // si le charset est fourni, l'utiliser |
|
| 334 | + if ($charset_sql_connexion) { |
|
| 335 | + return $charset_sql_connexion; |
|
| 336 | + } |
|
| 337 | + // sinon on regarde la table spip_meta |
|
| 338 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 339 | + if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 340 | + or is_string($r) |
|
| 341 | + ) { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 344 | + if (!($f = $connexion['fetch'])) { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + $r = $f($r); |
|
| 348 | + |
|
| 349 | + return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -361,9 +361,9 @@ discard block |
||
| 361 | 361 | * @return array |
| 362 | 362 | */ |
| 363 | 363 | function spip_connect_ldap($serveur = '') { |
| 364 | - include_spip('auth/ldap'); |
|
| 364 | + include_spip('auth/ldap'); |
|
| 365 | 365 | |
| 366 | - return auth_ldap_connect($serveur); |
|
| 366 | + return auth_ldap_connect($serveur); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -379,9 +379,9 @@ discard block |
||
| 379 | 379 | * @return string Valeur échappée. |
| 380 | 380 | **/ |
| 381 | 381 | function _q($a) { |
| 382 | - return (is_numeric($a)) ? strval($a) : |
|
| 383 | - (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 384 | - : join(",", array_map('_q', $a))); |
|
| 382 | + return (is_numeric($a)) ? strval($a) : |
|
| 383 | + (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 384 | + : join(",", array_map('_q', $a))); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | |
@@ -399,19 +399,19 @@ discard block |
||
| 399 | 399 | * - chaîne vide si non trouvé. |
| 400 | 400 | **/ |
| 401 | 401 | function table_jointure($x, $y) { |
| 402 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 403 | - $xdesc = $trouver_table(table_objet($x)); |
|
| 404 | - $ydesc = $trouver_table(table_objet($y)); |
|
| 405 | - $ix = @$xdesc['key']["PRIMARY KEY"]; |
|
| 406 | - $iy = @$ydesc['key']["PRIMARY KEY"]; |
|
| 407 | - if ($table = $ydesc['tables_jointures'][$ix]) { |
|
| 408 | - return $table; |
|
| 409 | - } |
|
| 410 | - if ($table = $xdesc['tables_jointures'][$iy]) { |
|
| 411 | - return $table; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - return ''; |
|
| 402 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 403 | + $xdesc = $trouver_table(table_objet($x)); |
|
| 404 | + $ydesc = $trouver_table(table_objet($y)); |
|
| 405 | + $ix = @$xdesc['key']["PRIMARY KEY"]; |
|
| 406 | + $iy = @$ydesc['key']["PRIMARY KEY"]; |
|
| 407 | + if ($table = $ydesc['tables_jointures'][$ix]) { |
|
| 408 | + return $table; |
|
| 409 | + } |
|
| 410 | + if ($table = $xdesc['tables_jointures'][$iy]) { |
|
| 411 | + return $table; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + return ''; |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -427,41 +427,41 @@ discard block |
||
| 427 | 427 | * @return array |
| 428 | 428 | */ |
| 429 | 429 | function query_echappe_textes($query) { |
| 430 | - static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3"); |
|
| 431 | - $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 432 | - if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) { |
|
| 433 | - $textes = reset($textes); // indice 0 du match |
|
| 434 | - switch (count($textes)) { |
|
| 435 | - case 0: |
|
| 436 | - $replace = array(); |
|
| 437 | - break; |
|
| 438 | - case 1: |
|
| 439 | - $replace = array('%1$s'); |
|
| 440 | - break; |
|
| 441 | - case 2: |
|
| 442 | - $replace = array('%1$s', '%2$s'); |
|
| 443 | - break; |
|
| 444 | - case 3: |
|
| 445 | - $replace = array('%1$s', '%2$s', '%3$s'); |
|
| 446 | - break; |
|
| 447 | - case 4: |
|
| 448 | - $replace = array('%1$s', '%2$s', '%3$s', '%4$s'); |
|
| 449 | - break; |
|
| 450 | - case 5: |
|
| 451 | - $replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s'); |
|
| 452 | - break; |
|
| 453 | - default: |
|
| 454 | - $replace = range(1, count($textes)); |
|
| 455 | - $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 456 | - $replace = explode(',', $replace); |
|
| 457 | - break; |
|
| 458 | - } |
|
| 459 | - $query = str_replace($textes, $replace, $query); |
|
| 460 | - } else { |
|
| 461 | - $textes = array(); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return array($query, $textes); |
|
| 430 | + static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3"); |
|
| 431 | + $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 432 | + if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) { |
|
| 433 | + $textes = reset($textes); // indice 0 du match |
|
| 434 | + switch (count($textes)) { |
|
| 435 | + case 0: |
|
| 436 | + $replace = array(); |
|
| 437 | + break; |
|
| 438 | + case 1: |
|
| 439 | + $replace = array('%1$s'); |
|
| 440 | + break; |
|
| 441 | + case 2: |
|
| 442 | + $replace = array('%1$s', '%2$s'); |
|
| 443 | + break; |
|
| 444 | + case 3: |
|
| 445 | + $replace = array('%1$s', '%2$s', '%3$s'); |
|
| 446 | + break; |
|
| 447 | + case 4: |
|
| 448 | + $replace = array('%1$s', '%2$s', '%3$s', '%4$s'); |
|
| 449 | + break; |
|
| 450 | + case 5: |
|
| 451 | + $replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s'); |
|
| 452 | + break; |
|
| 453 | + default: |
|
| 454 | + $replace = range(1, count($textes)); |
|
| 455 | + $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 456 | + $replace = explode(',', $replace); |
|
| 457 | + break; |
|
| 458 | + } |
|
| 459 | + $query = str_replace($textes, $replace, $query); |
|
| 460 | + } else { |
|
| 461 | + $textes = array(); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return array($query, $textes); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -475,40 +475,40 @@ discard block |
||
| 475 | 475 | * @return string |
| 476 | 476 | */ |
| 477 | 477 | function query_reinjecte_textes($query, $textes) { |
| 478 | - static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3"); |
|
| 479 | - # debug de la substitution |
|
| 480 | - #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){ |
|
| 481 | - # spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR); |
|
| 482 | - # spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR); |
|
| 483 | - # spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR); |
|
| 484 | - #} |
|
| 485 | - switch (count($textes)) { |
|
| 486 | - case 0: |
|
| 487 | - break; |
|
| 488 | - case 1: |
|
| 489 | - $query = sprintf($query, $textes[0]); |
|
| 490 | - break; |
|
| 491 | - case 2: |
|
| 492 | - $query = sprintf($query, $textes[0], $textes[1]); |
|
| 493 | - break; |
|
| 494 | - case 3: |
|
| 495 | - $query = sprintf($query, $textes[0], $textes[1], $textes[2]); |
|
| 496 | - break; |
|
| 497 | - case 4: |
|
| 498 | - $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]); |
|
| 499 | - break; |
|
| 500 | - case 5: |
|
| 501 | - $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]); |
|
| 502 | - break; |
|
| 503 | - default: |
|
| 504 | - array_unshift($textes, $query); |
|
| 505 | - $query = call_user_func_array('sprintf', $textes); |
|
| 506 | - break; |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 510 | - |
|
| 511 | - return $query; |
|
| 478 | + static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3"); |
|
| 479 | + # debug de la substitution |
|
| 480 | + #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){ |
|
| 481 | + # spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR); |
|
| 482 | + # spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR); |
|
| 483 | + # spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR); |
|
| 484 | + #} |
|
| 485 | + switch (count($textes)) { |
|
| 486 | + case 0: |
|
| 487 | + break; |
|
| 488 | + case 1: |
|
| 489 | + $query = sprintf($query, $textes[0]); |
|
| 490 | + break; |
|
| 491 | + case 2: |
|
| 492 | + $query = sprintf($query, $textes[0], $textes[1]); |
|
| 493 | + break; |
|
| 494 | + case 3: |
|
| 495 | + $query = sprintf($query, $textes[0], $textes[1], $textes[2]); |
|
| 496 | + break; |
|
| 497 | + case 4: |
|
| 498 | + $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]); |
|
| 499 | + break; |
|
| 500 | + case 5: |
|
| 501 | + $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]); |
|
| 502 | + break; |
|
| 503 | + default: |
|
| 504 | + array_unshift($textes, $query); |
|
| 505 | + $query = call_user_func_array('sprintf', $textes); |
|
| 506 | + break; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 510 | + |
|
| 511 | + return $query; |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | **/ |
| 528 | 528 | function spip_query($query, $serveur = '') { |
| 529 | 529 | |
| 530 | - $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 530 | + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 531 | 531 | |
| 532 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 532 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 533 | 533 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | * |
| 53 | 53 | * @param int $id |
| 54 | 54 | * @param string $type |
| 55 | - * @param string|int|array $exclus |
|
| 55 | + * @param integer $exclus |
|
| 56 | 56 | * @param string|bool $rac |
| 57 | 57 | * @param string $do |
| 58 | 58 | * @return string |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/actions'); |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | * @uses ajax_retour() |
| 32 | 32 | **/ |
| 33 | 33 | function exec_rechercher_dist() { |
| 34 | - $id = intval(_request('id')); |
|
| 35 | - $exclus = intval(_request('exclus')); |
|
| 36 | - $rac = spip_htmlentities(_request('rac')); |
|
| 37 | - $type = _request('type'); |
|
| 38 | - $do = _request('do'); |
|
| 39 | - if (preg_match('/^\w*$/', $do)) { |
|
| 40 | - $r = exec_rechercher_args($id, $type, $exclus, $rac, $do); |
|
| 41 | - } else { |
|
| 42 | - $r = ''; |
|
| 43 | - } |
|
| 44 | - ajax_retour($r); |
|
| 34 | + $id = intval(_request('id')); |
|
| 35 | + $exclus = intval(_request('exclus')); |
|
| 36 | + $rac = spip_htmlentities(_request('rac')); |
|
| 37 | + $type = _request('type'); |
|
| 38 | + $do = _request('do'); |
|
| 39 | + if (preg_match('/^\w*$/', $do)) { |
|
| 40 | + $r = exec_rechercher_args($id, $type, $exclus, $rac, $do); |
|
| 41 | + } else { |
|
| 42 | + $r = ''; |
|
| 43 | + } |
|
| 44 | + ajax_retour($r); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -58,59 +58,59 @@ discard block |
||
| 58 | 58 | * @return string |
| 59 | 59 | **/ |
| 60 | 60 | function exec_rechercher_args($id, $type, $exclus, $rac, $do) { |
| 61 | - if (!$do) { |
|
| 62 | - $do = 'aff'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $points = $rub = array(); |
|
| 66 | - |
|
| 67 | - $where = preg_split(",\s+,", $type); |
|
| 68 | - if ($where) { |
|
| 69 | - foreach ($where as $k => $v) { |
|
| 70 | - $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'"; |
|
| 71 | - } |
|
| 72 | - $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 73 | - $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 74 | - $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 75 | - |
|
| 76 | - if ($exclus) { |
|
| 77 | - include_spip('inc/rubriques'); |
|
| 78 | - $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 79 | - } else { |
|
| 80 | - $where_exclus = ''; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - foreach (array( |
|
| 84 | - 3 => $where_titre, |
|
| 85 | - 2 => $where_desc, |
|
| 86 | - 1 => $where_id, |
|
| 87 | - ) as $point => $recherche) { |
|
| 88 | - $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus"); |
|
| 89 | - while ($row = sql_fetch($res)) { |
|
| 90 | - $id_rubrique = $row["id_rubrique"]; |
|
| 91 | - if (!isset($rub[$id_rubrique])) { |
|
| 92 | - $rub[$id_rubrique] = array(); |
|
| 93 | - } |
|
| 94 | - $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 95 | - $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 96 | - if (!isset($points[$id_rubrique])) { |
|
| 97 | - $points[$id_rubrique] = 0; |
|
| 98 | - } |
|
| 99 | - $points[$id_rubrique] = $points[$id_rubrique] + $point; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($points) { |
|
| 105 | - arsort($points); |
|
| 106 | - $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 107 | - foreach ($rub as $k => $v) { |
|
| 108 | - $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
|
| 109 | - . " class='petite-rubrique'"; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return (proposer_item($points, $rub, $rac, $type, $do)); |
|
| 61 | + if (!$do) { |
|
| 62 | + $do = 'aff'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $points = $rub = array(); |
|
| 66 | + |
|
| 67 | + $where = preg_split(",\s+,", $type); |
|
| 68 | + if ($where) { |
|
| 69 | + foreach ($where as $k => $v) { |
|
| 70 | + $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'"; |
|
| 71 | + } |
|
| 72 | + $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 73 | + $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 74 | + $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 75 | + |
|
| 76 | + if ($exclus) { |
|
| 77 | + include_spip('inc/rubriques'); |
|
| 78 | + $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 79 | + } else { |
|
| 80 | + $where_exclus = ''; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + foreach (array( |
|
| 84 | + 3 => $where_titre, |
|
| 85 | + 2 => $where_desc, |
|
| 86 | + 1 => $where_id, |
|
| 87 | + ) as $point => $recherche) { |
|
| 88 | + $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus"); |
|
| 89 | + while ($row = sql_fetch($res)) { |
|
| 90 | + $id_rubrique = $row["id_rubrique"]; |
|
| 91 | + if (!isset($rub[$id_rubrique])) { |
|
| 92 | + $rub[$id_rubrique] = array(); |
|
| 93 | + } |
|
| 94 | + $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 95 | + $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 96 | + if (!isset($points[$id_rubrique])) { |
|
| 97 | + $points[$id_rubrique] = 0; |
|
| 98 | + } |
|
| 99 | + $points[$id_rubrique] = $points[$id_rubrique] + $point; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($points) { |
|
| 105 | + arsort($points); |
|
| 106 | + $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 107 | + foreach ($rub as $k => $v) { |
|
| 108 | + $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
|
| 109 | + . " class='petite-rubrique'"; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return (proposer_item($points, $rub, $rac, $type, $do)); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -133,35 +133,35 @@ discard block |
||
| 133 | 133 | **/ |
| 134 | 134 | function proposer_item($ids, $titles, $rac, $type, $do) { |
| 135 | 135 | |
| 136 | - if (!$ids) { |
|
| 137 | - return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
|
| 138 | - . spip_htmlentities($type) |
|
| 139 | - . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 140 | - } |
|
| 136 | + if (!$ids) { |
|
| 137 | + return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
|
| 138 | + . spip_htmlentities($type) |
|
| 139 | + . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - $ret = ''; |
|
| 143 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
|
| 142 | + $ret = ''; |
|
| 143 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
|
| 144 | 144 | |
| 145 | - $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 145 | + $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 146 | 146 | |
| 147 | - $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
|
| 147 | + $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
|
| 148 | 148 | |
| 149 | - foreach ($ids as $id => $bof) { |
|
| 149 | + foreach ($ids as $id => $bof) { |
|
| 150 | 150 | |
| 151 | - $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", |
|
| 152 | - " "); |
|
| 151 | + $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", |
|
| 152 | + " "); |
|
| 153 | 153 | |
| 154 | - $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); " |
|
| 155 | - . $onClick |
|
| 156 | - . "\"\nondblclick=\"" |
|
| 157 | - . $ondbClick |
|
| 158 | - . $onClick |
|
| 159 | - . " \"><div" |
|
| 160 | - . $titles[$id]["atts"] |
|
| 161 | - . " title='$id'> " |
|
| 162 | - . $titre |
|
| 163 | - . "</div></div>"; |
|
| 164 | - } |
|
| 154 | + $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); " |
|
| 155 | + . $onClick |
|
| 156 | + . "\"\nondblclick=\"" |
|
| 157 | + . $ondbClick |
|
| 158 | + . $onClick |
|
| 159 | + . " \"><div" |
|
| 160 | + . $titles[$id]["atts"] |
|
| 161 | + . " title='$id'> " |
|
| 162 | + . $titre |
|
| 163 | + . "</div></div>"; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - return $ret; |
|
| 166 | + return $ret; |
|
| 167 | 167 | } |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | $where = preg_split(",\s+,", $type); |
| 68 | 68 | if ($where) { |
| 69 | 69 | foreach ($where as $k => $v) { |
| 70 | - $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'"; |
|
| 70 | + $where[$k] = "'%".substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1)."%'"; |
|
| 71 | 71 | } |
| 72 | - $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 73 | - $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 74 | - $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 72 | + $where_titre = ("(titre LIKE ".join(" AND titre LIKE ", $where).")"); |
|
| 73 | + $where_desc = ("(descriptif LIKE ".join(" AND descriptif LIKE ", $where).")"); |
|
| 74 | + $where_id = ("(id_rubrique = ".intval($type).")"); |
|
| 75 | 75 | |
| 76 | 76 | if ($exclus) { |
| 77 | 77 | include_spip('inc/rubriques'); |
| 78 | - $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 78 | + $where_exclus = " AND ".sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 79 | 79 | } else { |
| 80 | 80 | $where_exclus = ''; |
| 81 | 81 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | if ($points) { |
| 105 | 105 | arsort($points); |
| 106 | - $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 106 | + $style = " style='background-image: url(".chemin_image('secteur-12.png').")'"; |
|
| 107 | 107 | foreach ($rub as $k => $v) { |
| 108 | 108 | $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
| 109 | 109 | . " class='petite-rubrique'"; |
@@ -136,13 +136,13 @@ discard block |
||
| 136 | 136 | if (!$ids) { |
| 137 | 137 | return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
| 138 | 138 | . spip_htmlentities($type) |
| 139 | - . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 139 | + . "</b> : "._T('avis_aucun_resultat')."</div>"; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | $ret = ''; |
| 143 | 143 | $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
| 144 | 144 | |
| 145 | - $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 145 | + $onClick = "aff_selection(this.firstChild.title,'$rac"."_selection','$info', event)"; |
|
| 146 | 146 | |
| 147 | 147 | $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
| 148 | 148 | |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | * @uses verifier_crash_tables() |
| 32 | 32 | * |
| 33 | 33 | * @param object $t |
| 34 | - * @return bool Toujours à true. |
|
| 34 | + * @return integer Toujours à true. |
|
| 35 | 35 | */ |
| 36 | 36 | function genie_maintenance_dist($t) { |
| 37 | 37 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -35,18 +35,18 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function genie_maintenance_dist($t) { |
| 37 | 37 | |
| 38 | - // (re)mettre .htaccess avec deny from all |
|
| 39 | - // dans les deux repertoires dits inaccessibles par http |
|
| 40 | - include_spip('inc/acces'); |
|
| 41 | - verifier_htaccess(_DIR_ETC); |
|
| 42 | - verifier_htaccess(_DIR_TMP); |
|
| 38 | + // (re)mettre .htaccess avec deny from all |
|
| 39 | + // dans les deux repertoires dits inaccessibles par http |
|
| 40 | + include_spip('inc/acces'); |
|
| 41 | + verifier_htaccess(_DIR_ETC); |
|
| 42 | + verifier_htaccess(_DIR_TMP); |
|
| 43 | 43 | |
| 44 | - // Verifier qu'aucune table n'est crashee |
|
| 45 | - if (!_request('reinstall')) { |
|
| 46 | - verifier_crash_tables(); |
|
| 47 | - } |
|
| 44 | + // Verifier qu'aucune table n'est crashee |
|
| 45 | + if (!_request('reinstall')) { |
|
| 46 | + verifier_crash_tables(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return 1; |
|
| 49 | + return 1; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -63,33 +63,33 @@ discard block |
||
| 63 | 63 | * des tables qui ont crashé. |
| 64 | 64 | */ |
| 65 | 65 | function verifier_crash_tables() { |
| 66 | - if (spip_connect()) { |
|
| 67 | - include_spip('base/serial'); |
|
| 68 | - include_spip('base/auxiliaires'); |
|
| 69 | - $crash = array(); |
|
| 70 | - foreach (array('tables_principales', 'tables_auxiliaires') as $com) { |
|
| 71 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | - if (!sql_select('*', $table, '', '', '', 1) |
|
| 73 | - and !defined('spip_interdire_cache') |
|
| 74 | - ) # cas "LOST CONNECTION" |
|
| 75 | - { |
|
| 76 | - $crash[] = $table; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - #$crash[] = 'test'; |
|
| 81 | - if ($crash) { |
|
| 82 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | - spip_log('crash des tables', 'err'); |
|
| 84 | - spip_log($crash, 'err'); |
|
| 85 | - } else { |
|
| 86 | - effacer_meta('message_crash_tables'); |
|
| 87 | - } |
|
| 66 | + if (spip_connect()) { |
|
| 67 | + include_spip('base/serial'); |
|
| 68 | + include_spip('base/auxiliaires'); |
|
| 69 | + $crash = array(); |
|
| 70 | + foreach (array('tables_principales', 'tables_auxiliaires') as $com) { |
|
| 71 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | + if (!sql_select('*', $table, '', '', '', 1) |
|
| 73 | + and !defined('spip_interdire_cache') |
|
| 74 | + ) # cas "LOST CONNECTION" |
|
| 75 | + { |
|
| 76 | + $crash[] = $table; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + #$crash[] = 'test'; |
|
| 81 | + if ($crash) { |
|
| 82 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | + spip_log('crash des tables', 'err'); |
|
| 84 | + spip_log($crash, 'err'); |
|
| 85 | + } else { |
|
| 86 | + effacer_meta('message_crash_tables'); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return $crash; |
|
| 90 | - } |
|
| 89 | + return $crash; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return false; |
|
| 92 | + return false; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | 107 | function message_crash_tables() { |
| 108 | - if ($crash = verifier_crash_tables()) { |
|
| 109 | - return |
|
| 110 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | - . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 112 | - . generer_form_ecrire('base_repair', |
|
| 113 | - _T('texte_crash_base'), '', |
|
| 114 | - _T('bouton_tenter_recuperation')); |
|
| 115 | - } |
|
| 108 | + if ($crash = verifier_crash_tables()) { |
|
| 109 | + return |
|
| 110 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | + . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 112 | + . generer_form_ecrire('base_repair', |
|
| 113 | + _T('texte_crash_base'), '', |
|
| 114 | + _T('bouton_tenter_recuperation')); |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -107,8 +107,8 @@ |
||
| 107 | 107 | function message_crash_tables() { |
| 108 | 108 | if ($crash = verifier_crash_tables()) { |
| 109 | 109 | return |
| 110 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | - . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 110 | + '<strong>'._T('texte_recuperer_base').'</strong><br />' |
|
| 111 | + . ' <tt>'.join(', ', $crash).'</tt><br />' |
|
| 112 | 112 | . generer_form_ecrire('base_repair', |
| 113 | 113 | _T('texte_crash_base'), '', |
| 114 | 114 | _T('bouton_tenter_recuperation')); |
@@ -71,10 +71,12 @@ |
||
| 71 | 71 | foreach ($GLOBALS[$com] as $table => $desc) { |
| 72 | 72 | if (!sql_select('*', $table, '', '', '', 1) |
| 73 | 73 | and !defined('spip_interdire_cache') |
| 74 | - ) # cas "LOST CONNECTION" |
|
| 74 | + ) { |
|
| 75 | + # cas "LOST CONNECTION" |
|
| 75 | 76 | { |
| 76 | 77 | $crash[] = $table; |
| 77 | 78 | } |
| 79 | + } |
|
| 78 | 80 | } |
| 79 | 81 | } |
| 80 | 82 | #$crash[] = 'test'; |
@@ -261,7 +261,7 @@ |
||
| 261 | 261 | /** |
| 262 | 262 | * Initialiser la globale htsalt si cela n'a pas déjà été fait. |
| 263 | 263 | * |
| 264 | - * @return void|bool |
|
| 264 | + * @return null|string |
|
| 265 | 265 | */ |
| 266 | 266 | function initialiser_sel() { |
| 267 | 267 | if (CRYPT_MD5) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,47 +31,47 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | - |
|
| 36 | - mt_srand($seed); |
|
| 37 | - srand($seed); |
|
| 38 | - $s = ''; |
|
| 39 | - $pass = ''; |
|
| 40 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 41 | - if (!$s) { |
|
| 42 | - $s = mt_rand(); |
|
| 43 | - if (!$s) { |
|
| 44 | - $s = rand(); |
|
| 45 | - } |
|
| 46 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 47 | - } |
|
| 48 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 49 | - $x = $r['r'] & 63; |
|
| 50 | - if ($x < 10) { |
|
| 51 | - $x = chr($x + 48); |
|
| 52 | - } else { |
|
| 53 | - if ($x < 36) { |
|
| 54 | - $x = chr($x + 55); |
|
| 55 | - } else { |
|
| 56 | - if ($x < 62) { |
|
| 57 | - $x = chr($x + 61); |
|
| 58 | - } else { |
|
| 59 | - if ($x == 63) { |
|
| 60 | - $x = '/'; |
|
| 61 | - } else { |
|
| 62 | - $x = '.'; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $pass .= $x; |
|
| 68 | - $s = substr($s, 2); |
|
| 69 | - } |
|
| 70 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 71 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 72 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 73 | - |
|
| 74 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + srand($seed); |
|
| 38 | + $s = ''; |
|
| 39 | + $pass = ''; |
|
| 40 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 41 | + if (!$s) { |
|
| 42 | + $s = mt_rand(); |
|
| 43 | + if (!$s) { |
|
| 44 | + $s = rand(); |
|
| 45 | + } |
|
| 46 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 47 | + } |
|
| 48 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 49 | + $x = $r['r'] & 63; |
|
| 50 | + if ($x < 10) { |
|
| 51 | + $x = chr($x + 48); |
|
| 52 | + } else { |
|
| 53 | + if ($x < 36) { |
|
| 54 | + $x = chr($x + 55); |
|
| 55 | + } else { |
|
| 56 | + if ($x < 62) { |
|
| 57 | + $x = chr($x + 61); |
|
| 58 | + } else { |
|
| 59 | + if ($x == 63) { |
|
| 60 | + $x = '/'; |
|
| 61 | + } else { |
|
| 62 | + $x = '.'; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $pass .= $x; |
|
| 68 | + $s = substr($s, 2); |
|
| 69 | + } |
|
| 70 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 71 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 72 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 73 | + |
|
| 74 | + return $pass; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,21 +80,21 @@ discard block |
||
| 80 | 80 | * @return string Identifiant |
| 81 | 81 | */ |
| 82 | 82 | function creer_uniqid() { |
| 83 | - static $seeded; |
|
| 83 | + static $seeded; |
|
| 84 | 84 | |
| 85 | - if (!$seeded) { |
|
| 86 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 87 | - mt_srand($seed); |
|
| 88 | - srand($seed); |
|
| 89 | - $seeded = true; |
|
| 90 | - } |
|
| 85 | + if (!$seeded) { |
|
| 86 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 87 | + mt_srand($seed); |
|
| 88 | + srand($seed); |
|
| 89 | + $seeded = true; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $s = mt_rand(); |
|
| 93 | - if (!$s) { |
|
| 94 | - $s = rand(); |
|
| 95 | - } |
|
| 92 | + $s = mt_rand(); |
|
| 93 | + if (!$s) { |
|
| 94 | + $s = rand(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return uniqid($s, 1); |
|
| 97 | + return uniqid($s, 1); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -108,38 +108,38 @@ discard block |
||
| 108 | 108 | * @return string Retourne l'alea éphemère actuel au passage |
| 109 | 109 | */ |
| 110 | 110 | function charger_aleas() { |
| 111 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 112 | - include_spip('base/abstract_sql'); |
|
| 113 | - $aleas = sql_allfetsel( |
|
| 114 | - array('nom', 'valeur'), |
|
| 115 | - 'spip_meta', |
|
| 116 | - sql_in("nom", array('alea_ephemere', 'alea_ephemere_ancien')), |
|
| 117 | - '', '', '', '', '', |
|
| 118 | - 'continue' |
|
| 119 | - ); |
|
| 120 | - if ($aleas) { |
|
| 121 | - foreach ($aleas as $a) { |
|
| 122 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 123 | - } |
|
| 124 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 125 | - } else { |
|
| 126 | - spip_log("aleas indisponibles", "session"); |
|
| 127 | - return ""; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 111 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 112 | + include_spip('base/abstract_sql'); |
|
| 113 | + $aleas = sql_allfetsel( |
|
| 114 | + array('nom', 'valeur'), |
|
| 115 | + 'spip_meta', |
|
| 116 | + sql_in("nom", array('alea_ephemere', 'alea_ephemere_ancien')), |
|
| 117 | + '', '', '', '', '', |
|
| 118 | + 'continue' |
|
| 119 | + ); |
|
| 120 | + if ($aleas) { |
|
| 121 | + foreach ($aleas as $a) { |
|
| 122 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 123 | + } |
|
| 124 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 125 | + } else { |
|
| 126 | + spip_log("aleas indisponibles", "session"); |
|
| 127 | + return ""; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 135 | 135 | **/ |
| 136 | 136 | function renouvelle_alea() { |
| 137 | - charger_aleas(); |
|
| 138 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 139 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 140 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 142 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 137 | + charger_aleas(); |
|
| 138 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 139 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 140 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 142 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -159,20 +159,20 @@ discard block |
||
| 159 | 159 | * Clé de sécurité. |
| 160 | 160 | **/ |
| 161 | 161 | function low_sec($id_auteur) { |
| 162 | - // Pas d'id_auteur : low_sec |
|
| 163 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 164 | - if (!$low_sec = $GLOBALS['meta']['low_sec']) { |
|
| 165 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 166 | - } |
|
| 167 | - } else { |
|
| 168 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)); |
|
| 169 | - if (!$low_sec) { |
|
| 170 | - $low_sec = creer_pass_aleatoire(); |
|
| 171 | - sql_updateq('spip_auteurs', array('low_sec' => $low_sec), 'id_auteur = '.intval($id_auteur)); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $low_sec; |
|
| 162 | + // Pas d'id_auteur : low_sec |
|
| 163 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 164 | + if (!$low_sec = $GLOBALS['meta']['low_sec']) { |
|
| 165 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 166 | + } |
|
| 167 | + } else { |
|
| 168 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)); |
|
| 169 | + if (!$low_sec) { |
|
| 170 | + $low_sec = creer_pass_aleatoire(); |
|
| 171 | + sql_updateq('spip_auteurs', array('low_sec' => $low_sec), 'id_auteur = '.intval($id_auteur)); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $low_sec; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -188,27 +188,27 @@ discard block |
||
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | 190 | function param_low_sec($op, $args = array(), $lang = '', $mime = 'rss') { |
| 191 | - $a = $b = ''; |
|
| 192 | - foreach ($args as $val => $var) { |
|
| 193 | - if ($var) { |
|
| 194 | - if ($val <> 'statut') { |
|
| 195 | - $a .= ':' . $val . '-' . $var; |
|
| 196 | - } |
|
| 197 | - $b .= $val . '=' . $var . '&'; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - $a = substr($a, 1); |
|
| 201 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 202 | - |
|
| 203 | - return $b |
|
| 204 | - . 'op=' |
|
| 205 | - . $op |
|
| 206 | - . '&id=' |
|
| 207 | - . $id |
|
| 208 | - . '&cle=' |
|
| 209 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 210 | - . (!$a ? '' : "&args=$a") |
|
| 211 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 191 | + $a = $b = ''; |
|
| 192 | + foreach ($args as $val => $var) { |
|
| 193 | + if ($var) { |
|
| 194 | + if ($val <> 'statut') { |
|
| 195 | + $a .= ':' . $val . '-' . $var; |
|
| 196 | + } |
|
| 197 | + $b .= $val . '=' . $var . '&'; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + $a = substr($a, 1); |
|
| 201 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 202 | + |
|
| 203 | + return $b |
|
| 204 | + . 'op=' |
|
| 205 | + . $op |
|
| 206 | + . '&id=' |
|
| 207 | + . $id |
|
| 208 | + . '&cle=' |
|
| 209 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 210 | + . (!$a ? '' : "&args=$a") |
|
| 211 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * Clé |
| 225 | 225 | **/ |
| 226 | 226 | function afficher_low_sec($id_auteur, $action = '') { |
| 227 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 227 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * true si les clés corresponde, false sinon |
| 243 | 243 | **/ |
| 244 | 244 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 245 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 245 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -252,10 +252,10 @@ discard block |
||
| 252 | 252 | * Identifiant de l'auteur |
| 253 | 253 | **/ |
| 254 | 254 | function effacer_low_sec($id_auteur) { |
| 255 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 256 | - return; |
|
| 257 | - } // jamais trop prudent ;) |
|
| 258 | - sql_updateq('spip_auteurs', array('low_sec' => ''), 'id_auteur = '.intval($id_auteur)); |
|
| 255 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 256 | + return; |
|
| 257 | + } // jamais trop prudent ;) |
|
| 258 | + sql_updateq('spip_auteurs', array('low_sec' => ''), 'id_auteur = '.intval($id_auteur)); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -264,11 +264,11 @@ discard block |
||
| 264 | 264 | * @return void|bool |
| 265 | 265 | */ |
| 266 | 266 | function initialiser_sel() { |
| 267 | - if (CRYPT_MD5) { |
|
| 268 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 269 | - } else { |
|
| 270 | - return ''; |
|
| 271 | - } |
|
| 267 | + if (CRYPT_MD5) { |
|
| 268 | + $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 269 | + } else { |
|
| 270 | + return ''; |
|
| 271 | + } |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -285,45 +285,45 @@ discard block |
||
| 285 | 285 | * - void sinon. |
| 286 | 286 | **/ |
| 287 | 287 | function ecrire_acces() { |
| 288 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 289 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 290 | - |
|
| 291 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 292 | - // par exemple acces_restreint ; |
|
| 293 | - // si .htaccess existe, outrepasser spip_meta |
|
| 294 | - if ((!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 295 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 296 | - and !@file_exists($htaccess) |
|
| 297 | - ) { |
|
| 298 | - spip_unlink($htpasswd); |
|
| 299 | - spip_unlink($htpasswd . '-admin'); |
|
| 300 | - return; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 304 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 305 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 306 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 307 | - |
|
| 308 | - if (spip_connect_ldap()) { |
|
| 309 | - return; |
|
| 310 | - } |
|
| 311 | - $p1 = ''; // login:htpass pour tous |
|
| 312 | - $p2 = ''; // login:htpass pour les admins |
|
| 313 | - $s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau'))); |
|
| 314 | - while ($t = sql_fetch($s)) { |
|
| 315 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 316 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 317 | - if ($t['statut'] == '0minirezo') { |
|
| 318 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - if ($p1) { |
|
| 323 | - ecrire_fichier($htpasswd, $p1); |
|
| 324 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 325 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 326 | - } |
|
| 288 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 289 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 290 | + |
|
| 291 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 292 | + // par exemple acces_restreint ; |
|
| 293 | + // si .htaccess existe, outrepasser spip_meta |
|
| 294 | + if ((!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 295 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 296 | + and !@file_exists($htaccess) |
|
| 297 | + ) { |
|
| 298 | + spip_unlink($htpasswd); |
|
| 299 | + spip_unlink($htpasswd . '-admin'); |
|
| 300 | + return; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 304 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 305 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 306 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 307 | + |
|
| 308 | + if (spip_connect_ldap()) { |
|
| 309 | + return; |
|
| 310 | + } |
|
| 311 | + $p1 = ''; // login:htpass pour tous |
|
| 312 | + $p2 = ''; // login:htpass pour les admins |
|
| 313 | + $s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau'))); |
|
| 314 | + while ($t = sql_fetch($s)) { |
|
| 315 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 316 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 317 | + if ($t['statut'] == '0minirezo') { |
|
| 318 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + if ($p1) { |
|
| 323 | + ecrire_fichier($htpasswd, $p1); |
|
| 324 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 325 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 326 | + } |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -339,9 +339,9 @@ discard block |
||
| 339 | 339 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 340 | 340 | */ |
| 341 | 341 | function generer_htpass($pass) { |
| 342 | - if (function_exists('crypt')) { |
|
| 343 | - return crypt($pass, $GLOBALS['htsalt']); |
|
| 344 | - } |
|
| 342 | + if (function_exists('crypt')) { |
|
| 343 | + return crypt($pass, $GLOBALS['htsalt']); |
|
| 344 | + } |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -354,14 +354,14 @@ discard block |
||
| 354 | 354 | * @return boolean |
| 355 | 355 | */ |
| 356 | 356 | function verifier_htaccess($rep, $force = false) { |
| 357 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 358 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 359 | - return true; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - // directive deny compatible Apache 2.0+ |
|
| 363 | - $deny = |
|
| 364 | - '# Deny all requests from Apache 2.4+. |
|
| 357 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 358 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 359 | + return true; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + // directive deny compatible Apache 2.0+ |
|
| 363 | + $deny = |
|
| 364 | + '# Deny all requests from Apache 2.4+. |
|
| 365 | 365 | <IfModule mod_authz_core.c> |
| 366 | 366 | Require all denied |
| 367 | 367 | </IfModule> |
@@ -370,32 +370,32 @@ discard block |
||
| 370 | 370 | Deny from all |
| 371 | 371 | </IfModule> |
| 372 | 372 | '; |
| 373 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 374 | - if (function_exists('apache_get_version') |
|
| 375 | - and $v = apache_get_version() |
|
| 376 | - and strncmp($v, 'Apache/1.', 9) == 0) { |
|
| 377 | - $deny = "deny from all\n"; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 381 | - fputs($ht, $deny); |
|
| 382 | - fclose($ht); |
|
| 383 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 384 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 385 | - if ($ht = @fopen($t, 'w')) { |
|
| 386 | - @fclose($ht); |
|
| 387 | - include_spip('inc/distant'); |
|
| 388 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 389 | - $t = url_de_base() . $t; |
|
| 390 | - $ht = recuperer_lapage($t, false, 'HEAD', 0); |
|
| 391 | - // htaccess inoperant si on a recupere des entetes HTTP |
|
| 392 | - // (ignorer la reussite si connexion par fopen) |
|
| 393 | - $ht = !(isset($ht[0]) and $ht[0]); |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 397 | - |
|
| 398 | - return $ht; |
|
| 373 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 374 | + if (function_exists('apache_get_version') |
|
| 375 | + and $v = apache_get_version() |
|
| 376 | + and strncmp($v, 'Apache/1.', 9) == 0) { |
|
| 377 | + $deny = "deny from all\n"; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 381 | + fputs($ht, $deny); |
|
| 382 | + fclose($ht); |
|
| 383 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 384 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 385 | + if ($ht = @fopen($t, 'w')) { |
|
| 386 | + @fclose($ht); |
|
| 387 | + include_spip('inc/distant'); |
|
| 388 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 389 | + $t = url_de_base() . $t; |
|
| 390 | + $ht = recuperer_lapage($t, false, 'HEAD', 0); |
|
| 391 | + // htaccess inoperant si on a recupere des entetes HTTP |
|
| 392 | + // (ignorer la reussite si connexion par fopen) |
|
| 393 | + $ht = !(isset($ht[0]) and $ht[0]); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 397 | + |
|
| 398 | + return $ht; |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
@@ -413,22 +413,22 @@ discard block |
||
| 413 | 413 | * Valeur de la configuration `creer_htaccess` |
| 414 | 414 | */ |
| 415 | 415 | function gerer_htaccess() { |
| 416 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 417 | - // par exemple acces_restreint |
|
| 418 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 419 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 420 | - $dirs[] = array('extension' => 'distant'); |
|
| 421 | - foreach ($dirs as $e) { |
|
| 422 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 423 | - if ($f) { |
|
| 424 | - verifier_htaccess($dir); |
|
| 425 | - } else { |
|
| 426 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : ''; |
|
| 416 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 417 | + // par exemple acces_restreint |
|
| 418 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 419 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 420 | + $dirs[] = array('extension' => 'distant'); |
|
| 421 | + foreach ($dirs as $e) { |
|
| 422 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 423 | + if ($f) { |
|
| 424 | + verifier_htaccess($dir); |
|
| 425 | + } else { |
|
| 426 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : ''; |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | initialiser_sel(); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 35 | 35 | |
| 36 | 36 | mt_srand($seed); |
| 37 | 37 | srand($seed); |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | if (!$s) { |
| 44 | 44 | $s = rand(); |
| 45 | 45 | } |
| 46 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | + $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 47 | 47 | } |
| 48 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | + $r = unpack('Cr', pack('H2', $s.$s)); |
|
| 49 | 49 | $x = $r['r'] & 63; |
| 50 | 50 | if ($x < 10) { |
| 51 | 51 | $x = chr($x + 48); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | static $seeded; |
| 84 | 84 | |
| 85 | 85 | if (!$seeded) { |
| 86 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 87 | 87 | mt_srand($seed); |
| 88 | 88 | srand($seed); |
| 89 | 89 | $seeded = true; |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | foreach ($args as $val => $var) { |
| 193 | 193 | if ($var) { |
| 194 | 194 | if ($val <> 'statut') { |
| 195 | - $a .= ':' . $val . '-' . $var; |
|
| 195 | + $a .= ':'.$val.'-'.$var; |
|
| 196 | 196 | } |
| 197 | - $b .= $val . '=' . $var . '&'; |
|
| 197 | + $b .= $val.'='.$var.'&'; |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | $a = substr($a, 1); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * Clé |
| 225 | 225 | **/ |
| 226 | 226 | function afficher_low_sec($id_auteur, $action = '') { |
| 227 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 227 | + return substr(md5($action.low_sec($id_auteur)), 0, 8); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | function initialiser_sel() { |
| 267 | 267 | if (CRYPT_MD5) { |
| 268 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 268 | + $GLOBALS['htsalt'] = '$1$'.creer_pass_aleatoire(); |
|
| 269 | 269 | } else { |
| 270 | 270 | return ''; |
| 271 | 271 | } |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | * - void sinon. |
| 286 | 286 | **/ |
| 287 | 287 | function ecrire_acces() { |
| 288 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 289 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 288 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 289 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 290 | 290 | |
| 291 | 291 | // Cette variable de configuration peut etre posee par un plugin |
| 292 | 292 | // par exemple acces_restreint ; |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | and !@file_exists($htaccess) |
| 297 | 297 | ) { |
| 298 | 298 | spip_unlink($htpasswd); |
| 299 | - spip_unlink($htpasswd . '-admin'); |
|
| 299 | + spip_unlink($htpasswd.'-admin'); |
|
| 300 | 300 | return; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -313,15 +313,15 @@ discard block |
||
| 313 | 313 | $s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau'))); |
| 314 | 314 | while ($t = sql_fetch($s)) { |
| 315 | 315 | if (strlen($t['login']) and strlen($t['htpass'])) { |
| 316 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 316 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 317 | 317 | if ($t['statut'] == '0minirezo') { |
| 318 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 318 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | if ($p1) { |
| 323 | 323 | ecrire_fichier($htpasswd, $p1); |
| 324 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 324 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 325 | 325 | spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
| 326 | 326 | } |
| 327 | 327 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * @return boolean |
| 355 | 355 | */ |
| 356 | 356 | function verifier_htaccess($rep, $force = false) { |
| 357 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 357 | + $htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME; |
|
| 358 | 358 | if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
| 359 | 359 | return true; |
| 360 | 360 | } |
@@ -381,19 +381,19 @@ discard block |
||
| 381 | 381 | fputs($ht, $deny); |
| 382 | 382 | fclose($ht); |
| 383 | 383 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 384 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 384 | + $t = rtrim($rep, '/').'/.ok'; |
|
| 385 | 385 | if ($ht = @fopen($t, 'w')) { |
| 386 | 386 | @fclose($ht); |
| 387 | 387 | include_spip('inc/distant'); |
| 388 | 388 | $t = substr($t, strlen(_DIR_RACINE)); |
| 389 | - $t = url_de_base() . $t; |
|
| 389 | + $t = url_de_base().$t; |
|
| 390 | 390 | $ht = recuperer_lapage($t, false, 'HEAD', 0); |
| 391 | 391 | // htaccess inoperant si on a recupere des entetes HTTP |
| 392 | 392 | // (ignorer la reussite si connexion par fopen) |
| 393 | 393 | $ht = !(isset($ht[0]) and $ht[0]); |
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 396 | + spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee')); |
|
| 397 | 397 | |
| 398 | 398 | return $ht; |
| 399 | 399 | } |
@@ -419,11 +419,11 @@ discard block |
||
| 419 | 419 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 420 | 420 | $dirs[] = array('extension' => 'distant'); |
| 421 | 421 | foreach ($dirs as $e) { |
| 422 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 422 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 423 | 423 | if ($f) { |
| 424 | 424 | verifier_htaccess($dir); |
| 425 | 425 | } else { |
| 426 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 426 | + spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | } |
@@ -1654,7 +1654,7 @@ |
||
| 1654 | 1654 | * |
| 1655 | 1655 | * @param string $objet |
| 1656 | 1656 | * @param int $id_objet |
| 1657 | - * @param string|array $cond |
|
| 1657 | + * @param string $cond |
|
| 1658 | 1658 | * Condition(s) supplémentaire(s) pour le where de la requête |
| 1659 | 1659 | * @return int[] |
| 1660 | 1660 | * Identifiants d'auteurs |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Autorisations |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('base/abstract_sql'); |
@@ -38,83 +38,83 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | if (!function_exists('autoriser')) { |
| 41 | - /** |
|
| 42 | - * Autoriser une action |
|
| 43 | - * |
|
| 44 | - * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 45 | - * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 46 | - * les autorisations. |
|
| 47 | - * |
|
| 48 | - * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 49 | - * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 50 | - * dans cet ordre : |
|
| 51 | - * |
|
| 52 | - * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 53 | - * - autoriser_{type}, sinon avec _dist |
|
| 54 | - * - autoriser_{faire}, sinon avec _dist |
|
| 55 | - * - autoriser_{defaut}, sinon avec _dist |
|
| 56 | - * |
|
| 57 | - * Seul le premier argument est obligatoire. |
|
| 58 | - * |
|
| 59 | - * @note |
|
| 60 | - * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 61 | - * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 62 | - * cette valeur. |
|
| 63 | - * |
|
| 64 | - * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 65 | - * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 66 | - * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 67 | - * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 68 | - * |
|
| 69 | - * @note |
|
| 70 | - * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 71 | - * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 72 | - * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 73 | - * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 74 | - * quel serait le type, quel serait l'action ? |
|
| 75 | - * |
|
| 76 | - * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 77 | - * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 78 | - * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 79 | - * |
|
| 80 | - * @api |
|
| 81 | - * @see autoriser_dist() |
|
| 82 | - * |
|
| 83 | - * @param string $faire |
|
| 84 | - * une action ('modifier', 'publier'...) |
|
| 85 | - * @param string $type |
|
| 86 | - * type d'objet ou nom de table ('article') |
|
| 87 | - * @param int $id |
|
| 88 | - * id de l'objet sur lequel on veut agir |
|
| 89 | - * @param null|int|array $qui |
|
| 90 | - * - si null on prend alors visiteur_session |
|
| 91 | - * - un id_auteur (on regarde dans la base) |
|
| 92 | - * - un tableau auteur complet, y compris [restreint] |
|
| 93 | - * @param null|array $opt |
|
| 94 | - * options sous forme de tableau associatif |
|
| 95 | - * @return bool |
|
| 96 | - * true si la personne peut effectuer l'action |
|
| 97 | - */ |
|
| 98 | - function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) { |
|
| 99 | - // Charger les fonctions d'autorisation supplementaires |
|
| 100 | - static $pipe; |
|
| 101 | - if (!isset($pipe)) { |
|
| 102 | - $pipe = 1; |
|
| 103 | - pipeline('autoriser'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $args = func_get_args(); |
|
| 107 | - |
|
| 108 | - return call_user_func_array('autoriser_dist', $args); |
|
| 109 | - } |
|
| 41 | + /** |
|
| 42 | + * Autoriser une action |
|
| 43 | + * |
|
| 44 | + * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 45 | + * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 46 | + * les autorisations. |
|
| 47 | + * |
|
| 48 | + * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 49 | + * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 50 | + * dans cet ordre : |
|
| 51 | + * |
|
| 52 | + * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 53 | + * - autoriser_{type}, sinon avec _dist |
|
| 54 | + * - autoriser_{faire}, sinon avec _dist |
|
| 55 | + * - autoriser_{defaut}, sinon avec _dist |
|
| 56 | + * |
|
| 57 | + * Seul le premier argument est obligatoire. |
|
| 58 | + * |
|
| 59 | + * @note |
|
| 60 | + * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 61 | + * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 62 | + * cette valeur. |
|
| 63 | + * |
|
| 64 | + * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 65 | + * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 66 | + * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 67 | + * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 68 | + * |
|
| 69 | + * @note |
|
| 70 | + * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 71 | + * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 72 | + * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 73 | + * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 74 | + * quel serait le type, quel serait l'action ? |
|
| 75 | + * |
|
| 76 | + * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 77 | + * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 78 | + * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 79 | + * |
|
| 80 | + * @api |
|
| 81 | + * @see autoriser_dist() |
|
| 82 | + * |
|
| 83 | + * @param string $faire |
|
| 84 | + * une action ('modifier', 'publier'...) |
|
| 85 | + * @param string $type |
|
| 86 | + * type d'objet ou nom de table ('article') |
|
| 87 | + * @param int $id |
|
| 88 | + * id de l'objet sur lequel on veut agir |
|
| 89 | + * @param null|int|array $qui |
|
| 90 | + * - si null on prend alors visiteur_session |
|
| 91 | + * - un id_auteur (on regarde dans la base) |
|
| 92 | + * - un tableau auteur complet, y compris [restreint] |
|
| 93 | + * @param null|array $opt |
|
| 94 | + * options sous forme de tableau associatif |
|
| 95 | + * @return bool |
|
| 96 | + * true si la personne peut effectuer l'action |
|
| 97 | + */ |
|
| 98 | + function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) { |
|
| 99 | + // Charger les fonctions d'autorisation supplementaires |
|
| 100 | + static $pipe; |
|
| 101 | + if (!isset($pipe)) { |
|
| 102 | + $pipe = 1; |
|
| 103 | + pipeline('autoriser'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $args = func_get_args(); |
|
| 107 | + |
|
| 108 | + return call_user_func_array('autoriser_dist', $args); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
| 113 | 113 | // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger |
| 114 | 114 | // mais apres la fonction autoriser() |
| 115 | 115 | if ($f = find_in_path('mes_fonctions.php')) { |
| 116 | - global $dossier_squelettes; |
|
| 117 | - include_once(_ROOT_CWD . $f); |
|
| 116 | + global $dossier_squelettes; |
|
| 117 | + include_once(_ROOT_CWD . $f); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -142,72 +142,72 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | function autoriser_dist($faire, $type = '', $id = 0, $qui = null, $opt = null) { |
| 144 | 144 | |
| 145 | - // Qui ? visiteur_session ? |
|
| 146 | - // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 147 | - if ($qui === null or $qui === '') { |
|
| 148 | - $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array(); |
|
| 149 | - $qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui); |
|
| 150 | - } elseif (is_numeric($qui)) { |
|
| 151 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // Admins restreints, on construit ici (pas generique mais...) |
|
| 155 | - // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 156 | - if (_ADMINS_RESTREINTS and is_array($qui)) { |
|
| 157 | - $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - spip_log( |
|
| 161 | - "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?', |
|
| 162 | - 'autoriser' . _LOG_DEBUG |
|
| 163 | - ); |
|
| 164 | - |
|
| 165 | - // passer par objet_type pour avoir les alias |
|
| 166 | - // et supprimer les _ |
|
| 167 | - $type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false)); |
|
| 168 | - |
|
| 169 | - // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 170 | - if ((isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier')) |
|
| 171 | - or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
|
| 172 | - ) { |
|
| 173 | - spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 174 | - return true; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // Chercher une fonction d'autorisation |
|
| 178 | - // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 179 | - // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 180 | - $fonctions = $type |
|
| 181 | - ? array( |
|
| 182 | - 'autoriser_' . $type . '_' . $faire, |
|
| 183 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 184 | - 'autoriser_' . $type, |
|
| 185 | - 'autoriser_' . $type . '_dist', |
|
| 186 | - 'autoriser_' . $faire, |
|
| 187 | - 'autoriser_' . $faire . '_dist', |
|
| 188 | - 'autoriser_defaut', |
|
| 189 | - 'autoriser_defaut_dist' |
|
| 190 | - ) |
|
| 191 | - : array( |
|
| 192 | - 'autoriser_' . $faire, |
|
| 193 | - 'autoriser_' . $faire . '_dist', |
|
| 194 | - 'autoriser_defaut', |
|
| 195 | - 'autoriser_defaut_dist' |
|
| 196 | - ); |
|
| 197 | - |
|
| 198 | - foreach ($fonctions as $f) { |
|
| 199 | - if (function_exists($f)) { |
|
| 200 | - $a = $f($faire, $type, $id, $qui, $opt); |
|
| 201 | - break; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - spip_log( |
|
| 206 | - "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 207 | - 'autoriser' . _LOG_DEBUG |
|
| 208 | - ); |
|
| 209 | - |
|
| 210 | - return $a; |
|
| 145 | + // Qui ? visiteur_session ? |
|
| 146 | + // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 147 | + if ($qui === null or $qui === '') { |
|
| 148 | + $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array(); |
|
| 149 | + $qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui); |
|
| 150 | + } elseif (is_numeric($qui)) { |
|
| 151 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // Admins restreints, on construit ici (pas generique mais...) |
|
| 155 | + // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 156 | + if (_ADMINS_RESTREINTS and is_array($qui)) { |
|
| 157 | + $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + spip_log( |
|
| 161 | + "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?', |
|
| 162 | + 'autoriser' . _LOG_DEBUG |
|
| 163 | + ); |
|
| 164 | + |
|
| 165 | + // passer par objet_type pour avoir les alias |
|
| 166 | + // et supprimer les _ |
|
| 167 | + $type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false)); |
|
| 168 | + |
|
| 169 | + // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 170 | + if ((isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier')) |
|
| 171 | + or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
|
| 172 | + ) { |
|
| 173 | + spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 174 | + return true; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // Chercher une fonction d'autorisation |
|
| 178 | + // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 179 | + // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 180 | + $fonctions = $type |
|
| 181 | + ? array( |
|
| 182 | + 'autoriser_' . $type . '_' . $faire, |
|
| 183 | + 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 184 | + 'autoriser_' . $type, |
|
| 185 | + 'autoriser_' . $type . '_dist', |
|
| 186 | + 'autoriser_' . $faire, |
|
| 187 | + 'autoriser_' . $faire . '_dist', |
|
| 188 | + 'autoriser_defaut', |
|
| 189 | + 'autoriser_defaut_dist' |
|
| 190 | + ) |
|
| 191 | + : array( |
|
| 192 | + 'autoriser_' . $faire, |
|
| 193 | + 'autoriser_' . $faire . '_dist', |
|
| 194 | + 'autoriser_defaut', |
|
| 195 | + 'autoriser_defaut_dist' |
|
| 196 | + ); |
|
| 197 | + |
|
| 198 | + foreach ($fonctions as $f) { |
|
| 199 | + if (function_exists($f)) { |
|
| 200 | + $a = $f($faire, $type, $id, $qui, $opt); |
|
| 201 | + break; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + spip_log( |
|
| 206 | + "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 207 | + 'autoriser' . _LOG_DEBUG |
|
| 208 | + ); |
|
| 209 | + |
|
| 210 | + return $a; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // une globale pour aller au plus vite dans la fonction generique ci dessus |
@@ -225,26 +225,26 @@ discard block |
||
| 225 | 225 | * @return bool |
| 226 | 226 | */ |
| 227 | 227 | function autoriser_exception($faire, $type, $id, $autoriser = true) { |
| 228 | - // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 229 | - static $autorisation; |
|
| 230 | - if ($autoriser === 'verifier') { |
|
| 231 | - return isset($autorisation[$faire][$type][$id]); |
|
| 232 | - } |
|
| 233 | - if ($autoriser === true) { |
|
| 234 | - $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 235 | - } |
|
| 236 | - if ($autoriser === false) { |
|
| 237 | - if ($id === '*') { |
|
| 238 | - unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 239 | - unset($autorisation[$faire][$type]); |
|
| 240 | - } |
|
| 241 | - else { |
|
| 242 | - unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 243 | - unset($autorisation[$faire][$type][$id]); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return false; |
|
| 228 | + // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 229 | + static $autorisation; |
|
| 230 | + if ($autoriser === 'verifier') { |
|
| 231 | + return isset($autorisation[$faire][$type][$id]); |
|
| 232 | + } |
|
| 233 | + if ($autoriser === true) { |
|
| 234 | + $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 235 | + } |
|
| 236 | + if ($autoriser === false) { |
|
| 237 | + if ($id === '*') { |
|
| 238 | + unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 239 | + unset($autorisation[$faire][$type]); |
|
| 240 | + } |
|
| 241 | + else { |
|
| 242 | + unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 243 | + unset($autorisation[$faire][$type][$id]); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return false; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -261,9 +261,9 @@ discard block |
||
| 261 | 261 | * @return bool true s'il a le droit, false sinon |
| 262 | 262 | **/ |
| 263 | 263 | function autoriser_defaut_dist($faire, $type, $id, $qui, $opt) { |
| 264 | - return |
|
| 265 | - $qui['statut'] == '0minirezo' |
|
| 266 | - and !$qui['restreint']; |
|
| 264 | + return |
|
| 265 | + $qui['statut'] == '0minirezo' |
|
| 266 | + and !$qui['restreint']; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -279,10 +279,10 @@ discard block |
||
| 279 | 279 | * @return bool |
| 280 | 280 | */ |
| 281 | 281 | function autoriser_loger_dist($faire, $type, $id, $qui, $opt) { |
| 282 | - if ($qui['statut'] == '5poubelle') { |
|
| 283 | - return false; |
|
| 284 | - } |
|
| 285 | - return true; |
|
| 282 | + if ($qui['statut'] == '5poubelle') { |
|
| 283 | + return false; |
|
| 284 | + } |
|
| 285 | + return true; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * @return bool true s'il a le droit, false sinon |
| 297 | 297 | **/ |
| 298 | 298 | function autoriser_ecrire_dist($faire, $type, $id, $qui, $opt) { |
| 299 | - return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite')); |
|
| 299 | + return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite')); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | * @return bool true s'il a le droit, false sinon |
| 314 | 314 | **/ |
| 315 | 315 | function autoriser_creer_dist($faire, $type, $id, $qui, $opt) { |
| 316 | - return in_array($qui['statut'], array('0minirezo', '1comite')); |
|
| 316 | + return in_array($qui['statut'], array('0minirezo', '1comite')); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -331,18 +331,18 @@ discard block |
||
| 331 | 331 | **/ |
| 332 | 332 | function autoriser_previsualiser_dist($faire, $type, $id, $qui, $opt) { |
| 333 | 333 | |
| 334 | - // Le visiteur a-t-il un statut prevu par la config ? |
|
| 335 | - if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 336 | - return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 337 | - } |
|
| 334 | + // Le visiteur a-t-il un statut prevu par la config ? |
|
| 335 | + if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 336 | + return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - // A-t-on un token de prévisualisation valable ? |
|
| 340 | - include_spip('inc/securiser_action'); |
|
| 341 | - if (decrire_token_previsu()) { |
|
| 342 | - return true; |
|
| 343 | - } |
|
| 339 | + // A-t-on un token de prévisualisation valable ? |
|
| 340 | + include_spip('inc/securiser_action'); |
|
| 341 | + if (decrire_token_previsu()) { |
|
| 342 | + return true; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - return false; |
|
| 345 | + return false; |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -370,57 +370,57 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | function test_previsualiser_objet_champ($type = null, $id = 0, $qui = array(), $opt = array()) { |
| 372 | 372 | |
| 373 | - // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 374 | - if (!$type) { |
|
| 375 | - return true; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - include_spip('base/objets'); |
|
| 379 | - $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 380 | - if (isset($infos['statut'])) { |
|
| 381 | - foreach ($infos['statut'] as $c) { |
|
| 382 | - if (isset($c['publie'])) { |
|
| 383 | - if (!isset($c['previsu'])) { |
|
| 384 | - return false; |
|
| 385 | - } // pas de previsu definie => NIET |
|
| 386 | - $champ = $c['champ']; |
|
| 387 | - if (!isset($opt[$champ])) { |
|
| 388 | - return false; |
|
| 389 | - } // pas de champ passe a la demande => NIET |
|
| 390 | - $previsu = explode(',', $c['previsu']); |
|
| 391 | - // regarder si ce statut est autorise pour l'auteur |
|
| 392 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 393 | - |
|
| 394 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 395 | - // sinon l’auteur en session |
|
| 396 | - include_spip('inc/securiser_action'); |
|
| 397 | - if ($desc = decrire_token_previsu()) { |
|
| 398 | - $id_auteur = $desc['id_auteur']; |
|
| 399 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 400 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 401 | - } else { |
|
| 402 | - $id_auteur = null; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - if (!$id_auteur) { |
|
| 406 | - return false; |
|
| 407 | - } elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) { |
|
| 408 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 409 | - } elseif (!sql_countsel( |
|
| 410 | - 'spip_auteurs_liens', |
|
| 411 | - 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 412 | - )) { |
|
| 413 | - return false; |
|
| 414 | - } // pas auteur de cet objet => NIET |
|
| 415 | - } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 416 | - // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 417 | - return false; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return true; |
|
| 373 | + // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 374 | + if (!$type) { |
|
| 375 | + return true; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + include_spip('base/objets'); |
|
| 379 | + $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 380 | + if (isset($infos['statut'])) { |
|
| 381 | + foreach ($infos['statut'] as $c) { |
|
| 382 | + if (isset($c['publie'])) { |
|
| 383 | + if (!isset($c['previsu'])) { |
|
| 384 | + return false; |
|
| 385 | + } // pas de previsu definie => NIET |
|
| 386 | + $champ = $c['champ']; |
|
| 387 | + if (!isset($opt[$champ])) { |
|
| 388 | + return false; |
|
| 389 | + } // pas de champ passe a la demande => NIET |
|
| 390 | + $previsu = explode(',', $c['previsu']); |
|
| 391 | + // regarder si ce statut est autorise pour l'auteur |
|
| 392 | + if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 393 | + |
|
| 394 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 395 | + // sinon l’auteur en session |
|
| 396 | + include_spip('inc/securiser_action'); |
|
| 397 | + if ($desc = decrire_token_previsu()) { |
|
| 398 | + $id_auteur = $desc['id_auteur']; |
|
| 399 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 400 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 401 | + } else { |
|
| 402 | + $id_auteur = null; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + if (!$id_auteur) { |
|
| 406 | + return false; |
|
| 407 | + } elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) { |
|
| 408 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 409 | + } elseif (!sql_countsel( |
|
| 410 | + 'spip_auteurs_liens', |
|
| 411 | + 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 412 | + )) { |
|
| 413 | + return false; |
|
| 414 | + } // pas auteur de cet objet => NIET |
|
| 415 | + } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 416 | + // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 417 | + return false; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return true; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -434,47 +434,47 @@ discard block |
||
| 434 | 434 | * @return bool true s'il a le droit, false sinon |
| 435 | 435 | **/ |
| 436 | 436 | function autoriser_changerlangue_dist($faire, $type, $id, $qui, $opt) { |
| 437 | - $multi_objets = explode(',', lire_config('multi_objets')); |
|
| 438 | - $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets')); |
|
| 439 | - $table = table_objet_sql($type); |
|
| 440 | - if (in_array($table, $multi_objets) |
|
| 441 | - or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte |
|
| 442 | - $multi_secteurs = lire_config('multi_secteurs'); |
|
| 443 | - $champs = objet_info($type, 'field'); |
|
| 444 | - if ($multi_secteurs == 'oui' |
|
| 445 | - and array_key_exists('id_rubrique', $champs)) { |
|
| 446 | - // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 447 | - $primary = id_table_objet($type); |
|
| 448 | - if ($table != 'spip_rubriques') { |
|
| 449 | - $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 450 | - } else { |
|
| 451 | - $id_rubrique = $id; |
|
| 452 | - } |
|
| 453 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 454 | - if (!$id_secteur > 0) { |
|
| 455 | - $id_secteur = $id_rubrique; |
|
| 456 | - } |
|
| 457 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 458 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 459 | - if ($langue_secteur != $langue_objet) { |
|
| 460 | - // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 461 | - return true; |
|
| 462 | - } |
|
| 463 | - if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 464 | - return false; |
|
| 465 | - } else { |
|
| 466 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 467 | - if ($id_parent != 0) { |
|
| 468 | - // sous-rubriques : pas de choix de langue |
|
| 469 | - return false; |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } else { |
|
| 474 | - return false; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 437 | + $multi_objets = explode(',', lire_config('multi_objets')); |
|
| 438 | + $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets')); |
|
| 439 | + $table = table_objet_sql($type); |
|
| 440 | + if (in_array($table, $multi_objets) |
|
| 441 | + or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte |
|
| 442 | + $multi_secteurs = lire_config('multi_secteurs'); |
|
| 443 | + $champs = objet_info($type, 'field'); |
|
| 444 | + if ($multi_secteurs == 'oui' |
|
| 445 | + and array_key_exists('id_rubrique', $champs)) { |
|
| 446 | + // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 447 | + $primary = id_table_objet($type); |
|
| 448 | + if ($table != 'spip_rubriques') { |
|
| 449 | + $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 450 | + } else { |
|
| 451 | + $id_rubrique = $id; |
|
| 452 | + } |
|
| 453 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 454 | + if (!$id_secteur > 0) { |
|
| 455 | + $id_secteur = $id_rubrique; |
|
| 456 | + } |
|
| 457 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 458 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 459 | + if ($langue_secteur != $langue_objet) { |
|
| 460 | + // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 461 | + return true; |
|
| 462 | + } |
|
| 463 | + if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 464 | + return false; |
|
| 465 | + } else { |
|
| 466 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 467 | + if ($id_parent != 0) { |
|
| 468 | + // sous-rubriques : pas de choix de langue |
|
| 469 | + return false; |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } else { |
|
| 474 | + return false; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | * @return bool true s'il a le droit, false sinon |
| 489 | 489 | **/ |
| 490 | 490 | function autoriser_changertraduction_dist($faire, $type, $id, $qui, $opt) { |
| 491 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 491 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | /** |
@@ -502,41 +502,41 @@ discard block |
||
| 502 | 502 | * @return bool true s'il a le droit, false sinon |
| 503 | 503 | **/ |
| 504 | 504 | function autoriser_dater_dist($faire, $type, $id, $qui, $opt) { |
| 505 | - $table = table_objet($type); |
|
| 506 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | - $desc = $trouver_table($table); |
|
| 508 | - if (!$desc) { |
|
| 509 | - return false; |
|
| 510 | - } |
|
| 505 | + $table = table_objet($type); |
|
| 506 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | + $desc = $trouver_table($table); |
|
| 508 | + if (!$desc) { |
|
| 509 | + return false; |
|
| 510 | + } |
|
| 511 | 511 | |
| 512 | - if (!isset($opt['statut'])) { |
|
| 513 | - if (isset($desc['field']['statut'])) { |
|
| 514 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 515 | - } else { |
|
| 516 | - $statut = 'publie'; |
|
| 517 | - } // pas de statut => publie |
|
| 518 | - } else { |
|
| 519 | - $statut = $opt['statut']; |
|
| 520 | - } |
|
| 512 | + if (!isset($opt['statut'])) { |
|
| 513 | + if (isset($desc['field']['statut'])) { |
|
| 514 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 515 | + } else { |
|
| 516 | + $statut = 'publie'; |
|
| 517 | + } // pas de statut => publie |
|
| 518 | + } else { |
|
| 519 | + $statut = $opt['statut']; |
|
| 520 | + } |
|
| 521 | 521 | |
| 522 | - // Liste des statuts publiés pour cet objet |
|
| 523 | - if (isset($desc['statut'][0]['publie'])) { |
|
| 524 | - $statuts_publies = explode(',', $desc['statut'][0]['publie']); |
|
| 525 | - } |
|
| 526 | - // Sinon en dur le statut "publie" |
|
| 527 | - else { |
|
| 528 | - $statuts_publies = array('publie'); |
|
| 529 | - } |
|
| 522 | + // Liste des statuts publiés pour cet objet |
|
| 523 | + if (isset($desc['statut'][0]['publie'])) { |
|
| 524 | + $statuts_publies = explode(',', $desc['statut'][0]['publie']); |
|
| 525 | + } |
|
| 526 | + // Sinon en dur le statut "publie" |
|
| 527 | + else { |
|
| 528 | + $statuts_publies = array('publie'); |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | - if ( |
|
| 532 | - in_array($statut, $statuts_publies) |
|
| 533 | - // Ou cas particulier géré en dur ici pour les articles |
|
| 534 | - or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non') |
|
| 535 | - ) { |
|
| 536 | - return autoriser('modifier', $type, $id); |
|
| 537 | - } |
|
| 531 | + if ( |
|
| 532 | + in_array($statut, $statuts_publies) |
|
| 533 | + // Ou cas particulier géré en dur ici pour les articles |
|
| 534 | + or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non') |
|
| 535 | + ) { |
|
| 536 | + return autoriser('modifier', $type, $id); |
|
| 537 | + } |
|
| 538 | 538 | |
| 539 | - return false; |
|
| 539 | + return false; |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | /** |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | * @return bool true s'il a le droit, false sinon |
| 554 | 554 | **/ |
| 555 | 555 | function autoriser_instituer_dist($faire, $type, $id, $qui, $opt) { |
| 556 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 556 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -569,12 +569,12 @@ discard block |
||
| 569 | 569 | * @return bool true s'il a le droit, false sinon |
| 570 | 570 | **/ |
| 571 | 571 | function autoriser_rubrique_publierdans_dist($faire, $type, $id, $qui, $opt) { |
| 572 | - return |
|
| 573 | - ($qui['statut'] == '0minirezo') |
|
| 574 | - and ( |
|
| 575 | - !$qui['restreint'] or !$id |
|
| 576 | - or in_array($id, $qui['restreint']) |
|
| 577 | - ); |
|
| 572 | + return |
|
| 573 | + ($qui['statut'] == '0minirezo') |
|
| 574 | + and ( |
|
| 575 | + !$qui['restreint'] or !$id |
|
| 576 | + or in_array($id, $qui['restreint']) |
|
| 577 | + ); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -590,10 +590,10 @@ discard block |
||
| 590 | 590 | * @return bool true s'il a le droit, false sinon |
| 591 | 591 | **/ |
| 592 | 592 | function autoriser_rubrique_creer_dist($faire, $type, $id, $qui, $opt) { |
| 593 | - return |
|
| 594 | - ((!$id and autoriser('defaut', null, null, $qui, $opt)) |
|
| 595 | - or $id and autoriser('creerrubriquedans', 'rubrique', $id, $qui, $opt) |
|
| 596 | - ); |
|
| 593 | + return |
|
| 594 | + ((!$id and autoriser('defaut', null, null, $qui, $opt)) |
|
| 595 | + or $id and autoriser('creerrubriquedans', 'rubrique', $id, $qui, $opt) |
|
| 596 | + ); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -609,10 +609,10 @@ discard block |
||
| 609 | 609 | * @return bool true s'il a le droit, false sinon |
| 610 | 610 | **/ |
| 611 | 611 | function autoriser_rubrique_creerrubriquedans_dist($faire, $type, $id, $qui, $opt) { |
| 612 | - return |
|
| 613 | - ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint'])) |
|
| 614 | - and autoriser('voir', 'rubrique', $id) |
|
| 615 | - and autoriser('publierdans', 'rubrique', $id); |
|
| 612 | + return |
|
| 613 | + ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint'])) |
|
| 614 | + and autoriser('voir', 'rubrique', $id) |
|
| 615 | + and autoriser('publierdans', 'rubrique', $id); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -628,10 +628,10 @@ discard block |
||
| 628 | 628 | * @return bool true s'il a le droit, false sinon |
| 629 | 629 | **/ |
| 630 | 630 | function autoriser_rubrique_creerarticledans_dist($faire, $type, $id, $qui, $opt) { |
| 631 | - return |
|
| 632 | - $id |
|
| 633 | - and autoriser('voir', 'rubrique', $id) |
|
| 634 | - and autoriser('creer', 'article'); |
|
| 631 | + return |
|
| 632 | + $id |
|
| 633 | + and autoriser('voir', 'rubrique', $id) |
|
| 634 | + and autoriser('creer', 'article'); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | |
@@ -648,8 +648,8 @@ discard block |
||
| 648 | 648 | * @return bool true s'il a le droit, false sinon |
| 649 | 649 | **/ |
| 650 | 650 | function autoriser_rubrique_modifier_dist($faire, $type, $id, $qui, $opt) { |
| 651 | - return |
|
| 652 | - autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 651 | + return |
|
| 652 | + autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -665,29 +665,29 @@ discard block |
||
| 665 | 665 | * @return bool true s'il a le droit, false sinon |
| 666 | 666 | **/ |
| 667 | 667 | function autoriser_rubrique_supprimer_dist($faire, $type, $id, $qui, $opt) { |
| 668 | - if (!$id = intval($id)) { |
|
| 669 | - return false; |
|
| 670 | - } |
|
| 668 | + if (!$id = intval($id)) { |
|
| 669 | + return false; |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | - if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 673 | - return false; |
|
| 674 | - } |
|
| 672 | + if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 673 | + return false; |
|
| 674 | + } |
|
| 675 | 675 | |
| 676 | - if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 677 | - return false; |
|
| 678 | - } |
|
| 676 | + if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 677 | + return false; |
|
| 678 | + } |
|
| 679 | 679 | |
| 680 | - $compte = pipeline( |
|
| 681 | - 'objet_compte_enfants', |
|
| 682 | - array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array()) |
|
| 683 | - ); |
|
| 684 | - foreach ($compte as $objet => $n) { |
|
| 685 | - if ($n) { |
|
| 686 | - return false; |
|
| 687 | - } |
|
| 688 | - } |
|
| 680 | + $compte = pipeline( |
|
| 681 | + 'objet_compte_enfants', |
|
| 682 | + array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array()) |
|
| 683 | + ); |
|
| 684 | + foreach ($compte as $objet => $n) { |
|
| 685 | + if ($n) { |
|
| 686 | + return false; |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | 689 | |
| 690 | - return autoriser('modifier', 'rubrique', $id); |
|
| 690 | + return autoriser('modifier', 'rubrique', $id); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | |
@@ -705,20 +705,20 @@ discard block |
||
| 705 | 705 | * @return bool true s'il a le droit, false sinon |
| 706 | 706 | **/ |
| 707 | 707 | function autoriser_article_modifier_dist($faire, $type, $id, $qui, $opt) { |
| 708 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 708 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 709 | 709 | |
| 710 | - return |
|
| 711 | - $r |
|
| 712 | - and |
|
| 713 | - ( |
|
| 714 | - autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 715 | - or ( |
|
| 716 | - (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
|
| 717 | - and in_array($qui['statut'], array('0minirezo', '1comite')) |
|
| 718 | - and in_array($r['statut'], array('prop', 'prepa', 'poubelle')) |
|
| 719 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 720 | - ) |
|
| 721 | - ); |
|
| 710 | + return |
|
| 711 | + $r |
|
| 712 | + and |
|
| 713 | + ( |
|
| 714 | + autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 715 | + or ( |
|
| 716 | + (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
|
| 717 | + and in_array($qui['statut'], array('0minirezo', '1comite')) |
|
| 718 | + and in_array($r['statut'], array('prop', 'prepa', 'poubelle')) |
|
| 719 | + and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 720 | + ) |
|
| 721 | + ); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * @return bool true s'il a le droit, false sinon |
| 735 | 735 | **/ |
| 736 | 736 | function autoriser_article_creer_dist($faire, $type, $id, $qui, $opt) { |
| 737 | - return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite'))); |
|
| 737 | + return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite'))); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | /** |
@@ -754,28 +754,28 @@ discard block |
||
| 754 | 754 | * @return bool true s'il a le droit, false sinon |
| 755 | 755 | */ |
| 756 | 756 | function autoriser_article_voir_dist($faire, $type, $id, $qui, $opt) { |
| 757 | - if ($qui['statut'] == '0minirezo') { |
|
| 758 | - return true; |
|
| 759 | - } |
|
| 760 | - // cas des articles : depend du statut de l'article et de l'auteur |
|
| 761 | - if (isset($opt['statut'])) { |
|
| 762 | - $statut = $opt['statut']; |
|
| 763 | - } else { |
|
| 764 | - if (!$id) { |
|
| 765 | - return false; |
|
| 766 | - } |
|
| 767 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - return |
|
| 771 | - // si on est pas auteur de l'article, |
|
| 772 | - // seuls les propose et publies sont visibles |
|
| 773 | - in_array($statut, array('prop', 'publie')) |
|
| 774 | - // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 775 | - or |
|
| 776 | - ($id |
|
| 777 | - and $qui['id_auteur'] |
|
| 778 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 757 | + if ($qui['statut'] == '0minirezo') { |
|
| 758 | + return true; |
|
| 759 | + } |
|
| 760 | + // cas des articles : depend du statut de l'article et de l'auteur |
|
| 761 | + if (isset($opt['statut'])) { |
|
| 762 | + $statut = $opt['statut']; |
|
| 763 | + } else { |
|
| 764 | + if (!$id) { |
|
| 765 | + return false; |
|
| 766 | + } |
|
| 767 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + return |
|
| 771 | + // si on est pas auteur de l'article, |
|
| 772 | + // seuls les propose et publies sont visibles |
|
| 773 | + in_array($statut, array('prop', 'publie')) |
|
| 774 | + // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 775 | + or |
|
| 776 | + ($id |
|
| 777 | + and $qui['id_auteur'] |
|
| 778 | + and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
@@ -792,22 +792,22 @@ discard block |
||
| 792 | 792 | * @return bool true s'il a le droit, false sinon |
| 793 | 793 | **/ |
| 794 | 794 | function autoriser_voir_dist($faire, $type, $id, $qui, $opt) { |
| 795 | - # securite, mais on aurait pas du arriver ici ! |
|
| 796 | - if (function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 797 | - or function_exists($f = 'autoriser_' . $type . '_voir_dist')) { |
|
| 798 | - return $f($faire, $type, $id, $qui, $opt); |
|
| 799 | - } |
|
| 795 | + # securite, mais on aurait pas du arriver ici ! |
|
| 796 | + if (function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 797 | + or function_exists($f = 'autoriser_' . $type . '_voir_dist')) { |
|
| 798 | + return $f($faire, $type, $id, $qui, $opt); |
|
| 799 | + } |
|
| 800 | 800 | |
| 801 | - if ($qui['statut'] == '0minirezo') { |
|
| 802 | - return true; |
|
| 803 | - } |
|
| 804 | - // admins et redacteurs peuvent voir un auteur |
|
| 805 | - if ($type == 'auteur') { |
|
| 806 | - return in_array($qui['statut'], array('0minirezo', '1comite')); |
|
| 807 | - } |
|
| 808 | - // sinon par defaut tout est visible |
|
| 809 | - // sauf cas particuliers traites separemment (ie article) |
|
| 810 | - return true; |
|
| 801 | + if ($qui['statut'] == '0minirezo') { |
|
| 802 | + return true; |
|
| 803 | + } |
|
| 804 | + // admins et redacteurs peuvent voir un auteur |
|
| 805 | + if ($type == 'auteur') { |
|
| 806 | + return in_array($qui['statut'], array('0minirezo', '1comite')); |
|
| 807 | + } |
|
| 808 | + // sinon par defaut tout est visible |
|
| 809 | + // sauf cas particuliers traites separemment (ie article) |
|
| 810 | + return true; |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | |
@@ -828,12 +828,12 @@ discard block |
||
| 828 | 828 | * @return bool true s'il a le droit, false sinon |
| 829 | 829 | **/ |
| 830 | 830 | function autoriser_webmestre_dist($faire, $type, $id, $qui, $opt) { |
| 831 | - return |
|
| 832 | - (defined('_ID_WEBMESTRES') ? |
|
| 833 | - in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES)) |
|
| 834 | - : $qui['webmestre'] == 'oui') |
|
| 835 | - and $qui['statut'] == '0minirezo' |
|
| 836 | - and !$qui['restreint']; |
|
| 831 | + return |
|
| 832 | + (defined('_ID_WEBMESTRES') ? |
|
| 833 | + in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES)) |
|
| 834 | + : $qui['webmestre'] == 'oui') |
|
| 835 | + and $qui['statut'] == '0minirezo' |
|
| 836 | + and !$qui['restreint']; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -849,9 +849,9 @@ discard block |
||
| 849 | 849 | * @return bool true s'il a le droit, false sinon |
| 850 | 850 | **/ |
| 851 | 851 | function autoriser_configurer_dist($faire, $type, $id, $qui, $opt) { |
| 852 | - return |
|
| 853 | - $qui['statut'] == '0minirezo' |
|
| 854 | - and !$qui['restreint']; |
|
| 852 | + return |
|
| 853 | + $qui['statut'] == '0minirezo' |
|
| 854 | + and !$qui['restreint']; |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -867,8 +867,8 @@ discard block |
||
| 867 | 867 | * @return bool true s'il a le droit, false sinon |
| 868 | 868 | **/ |
| 869 | 869 | function autoriser_sauvegarder_dist($faire, $type, $id, $qui, $opt) { |
| 870 | - return |
|
| 871 | - $qui['statut'] == '0minirezo'; |
|
| 870 | + return |
|
| 871 | + $qui['statut'] == '0minirezo'; |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | /** |
@@ -884,8 +884,8 @@ discard block |
||
| 884 | 884 | * @return bool true s'il a le droit, false sinon |
| 885 | 885 | **/ |
| 886 | 886 | function autoriser_detruire_dist($faire, $type, $id, $qui, $opt) { |
| 887 | - return |
|
| 888 | - autoriser('webmestre', null, null, $qui, $opt); |
|
| 887 | + return |
|
| 888 | + autoriser('webmestre', null, null, $qui, $opt); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | /** |
@@ -902,20 +902,20 @@ discard block |
||
| 902 | 902 | * @return bool true s'il a le droit, false sinon |
| 903 | 903 | **/ |
| 904 | 904 | function autoriser_auteur_previsualiser_dist($faire, $type, $id, $qui, $opt) { |
| 905 | - // les admins peuvent "previsualiser" une page auteur |
|
| 906 | - if ($qui['statut'] == '0minirezo' |
|
| 907 | - and !$qui['restreint'] |
|
| 908 | - ) { |
|
| 909 | - return true; |
|
| 910 | - } |
|
| 911 | - // "Voir en ligne" si l'auteur a un article publie |
|
| 912 | - $n = sql_fetsel( |
|
| 913 | - 'A.id_article', |
|
| 914 | - 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 915 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 916 | - ); |
|
| 905 | + // les admins peuvent "previsualiser" une page auteur |
|
| 906 | + if ($qui['statut'] == '0minirezo' |
|
| 907 | + and !$qui['restreint'] |
|
| 908 | + ) { |
|
| 909 | + return true; |
|
| 910 | + } |
|
| 911 | + // "Voir en ligne" si l'auteur a un article publie |
|
| 912 | + $n = sql_fetsel( |
|
| 913 | + 'A.id_article', |
|
| 914 | + 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 915 | + "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 916 | + ); |
|
| 917 | 917 | |
| 918 | - return $n ? true : false; |
|
| 918 | + return $n ? true : false; |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | |
@@ -943,7 +943,7 @@ discard block |
||
| 943 | 943 | * @return bool true s'il a le droit, false sinon |
| 944 | 944 | **/ |
| 945 | 945 | function autoriser_auteur_creer_dist($faire, $type, $id, $qui, $opt) { |
| 946 | - return ($qui['statut'] == '0minirezo'); |
|
| 946 | + return ($qui['statut'] == '0minirezo'); |
|
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | |
@@ -963,78 +963,78 @@ discard block |
||
| 963 | 963 | **/ |
| 964 | 964 | function autoriser_auteur_modifier_dist($faire, $type, $id, $qui, $opt) { |
| 965 | 965 | |
| 966 | - // Ni admin ni redacteur => non |
|
| 967 | - if (!in_array($qui['statut'], array('0minirezo', '1comite'))) { |
|
| 968 | - return false; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - // Un redacteur peut modifier ses propres donnees mais ni son login/email |
|
| 972 | - // ni son statut (qui sont le cas echeant passes comme option) |
|
| 973 | - if ($qui['statut'] == '1comite') { |
|
| 974 | - if (!empty($opt['webmestre'])) { |
|
| 975 | - return false; |
|
| 976 | - } elseif ( |
|
| 977 | - !empty($opt['statut']) |
|
| 978 | - or !empty($opt['restreintes']) |
|
| 979 | - or !empty($opt['email']) |
|
| 980 | - ) { |
|
| 981 | - return false; |
|
| 982 | - } elseif ($id == $qui['id_auteur']) { |
|
| 983 | - return true; |
|
| 984 | - } else { |
|
| 985 | - return false; |
|
| 986 | - } |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 990 | - // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 991 | - if ($qui['restreint']) { |
|
| 992 | - if (isset($opt['webmestre']) and $opt['webmestre']) { |
|
| 993 | - return false; |
|
| 994 | - } elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo')) |
|
| 995 | - or (isset($opt['restreintes']) and $opt['restreintes']) |
|
| 996 | - ) { |
|
| 997 | - return false; |
|
| 998 | - } else { |
|
| 999 | - if ($id == $qui['id_auteur']) { |
|
| 1000 | - if (isset($opt['statut']) and $opt['statut']) { |
|
| 1001 | - return false; |
|
| 1002 | - } else { |
|
| 1003 | - return true; |
|
| 1004 | - } |
|
| 1005 | - } else { |
|
| 1006 | - if ($id_auteur = intval($id)) { |
|
| 1007 | - $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1008 | - if ($t and $t['statut'] != '0minirezo') { |
|
| 1009 | - return true; |
|
| 1010 | - } else { |
|
| 1011 | - return false; |
|
| 1012 | - } |
|
| 1013 | - } // id = 0 => creation |
|
| 1014 | - else { |
|
| 1015 | - return true; |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - // Un admin complet fait ce qu'il veut |
|
| 1022 | - // sauf se degrader |
|
| 1023 | - if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) { |
|
| 1024 | - return false; |
|
| 1025 | - } elseif (isset($opt['webmestre']) |
|
| 1026 | - and $opt['webmestre'] |
|
| 1027 | - and (defined('_ID_WEBMESTRES') |
|
| 1028 | - or !autoriser('webmestre'))) { |
|
| 1029 | - // et toucher au statut webmestre si il ne l'est pas lui meme |
|
| 1030 | - // ou si les webmestres sont fixes par constante (securite) |
|
| 1031 | - return false; |
|
| 1032 | - } // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1033 | - elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) { |
|
| 1034 | - return false; |
|
| 1035 | - } else { |
|
| 1036 | - return true; |
|
| 1037 | - } |
|
| 966 | + // Ni admin ni redacteur => non |
|
| 967 | + if (!in_array($qui['statut'], array('0minirezo', '1comite'))) { |
|
| 968 | + return false; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + // Un redacteur peut modifier ses propres donnees mais ni son login/email |
|
| 972 | + // ni son statut (qui sont le cas echeant passes comme option) |
|
| 973 | + if ($qui['statut'] == '1comite') { |
|
| 974 | + if (!empty($opt['webmestre'])) { |
|
| 975 | + return false; |
|
| 976 | + } elseif ( |
|
| 977 | + !empty($opt['statut']) |
|
| 978 | + or !empty($opt['restreintes']) |
|
| 979 | + or !empty($opt['email']) |
|
| 980 | + ) { |
|
| 981 | + return false; |
|
| 982 | + } elseif ($id == $qui['id_auteur']) { |
|
| 983 | + return true; |
|
| 984 | + } else { |
|
| 985 | + return false; |
|
| 986 | + } |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 990 | + // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 991 | + if ($qui['restreint']) { |
|
| 992 | + if (isset($opt['webmestre']) and $opt['webmestre']) { |
|
| 993 | + return false; |
|
| 994 | + } elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo')) |
|
| 995 | + or (isset($opt['restreintes']) and $opt['restreintes']) |
|
| 996 | + ) { |
|
| 997 | + return false; |
|
| 998 | + } else { |
|
| 999 | + if ($id == $qui['id_auteur']) { |
|
| 1000 | + if (isset($opt['statut']) and $opt['statut']) { |
|
| 1001 | + return false; |
|
| 1002 | + } else { |
|
| 1003 | + return true; |
|
| 1004 | + } |
|
| 1005 | + } else { |
|
| 1006 | + if ($id_auteur = intval($id)) { |
|
| 1007 | + $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1008 | + if ($t and $t['statut'] != '0minirezo') { |
|
| 1009 | + return true; |
|
| 1010 | + } else { |
|
| 1011 | + return false; |
|
| 1012 | + } |
|
| 1013 | + } // id = 0 => creation |
|
| 1014 | + else { |
|
| 1015 | + return true; |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + // Un admin complet fait ce qu'il veut |
|
| 1022 | + // sauf se degrader |
|
| 1023 | + if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) { |
|
| 1024 | + return false; |
|
| 1025 | + } elseif (isset($opt['webmestre']) |
|
| 1026 | + and $opt['webmestre'] |
|
| 1027 | + and (defined('_ID_WEBMESTRES') |
|
| 1028 | + or !autoriser('webmestre'))) { |
|
| 1029 | + // et toucher au statut webmestre si il ne l'est pas lui meme |
|
| 1030 | + // ou si les webmestres sont fixes par constante (securite) |
|
| 1031 | + return false; |
|
| 1032 | + } // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1033 | + elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) { |
|
| 1034 | + return false; |
|
| 1035 | + } else { |
|
| 1036 | + return true; |
|
| 1037 | + } |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | * @return bool true s'il a le droit, false sinon |
| 1052 | 1052 | **/ |
| 1053 | 1053 | function autoriser_associerauteurs_dist($faire, $type, $id, $qui, $opt) { |
| 1054 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1054 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | |
@@ -1068,7 +1068,7 @@ discard block |
||
| 1068 | 1068 | * @return bool true s'il a le droit, false sinon |
| 1069 | 1069 | **/ |
| 1070 | 1070 | function autoriser_chargerftp_dist($faire, $type, $id, $qui, $opt) { |
| 1071 | - return $qui['statut'] == '0minirezo'; |
|
| 1071 | + return $qui['statut'] == '0minirezo'; |
|
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 1074 | /** |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | * @return bool true s'il a le droit, false sinon |
| 1085 | 1085 | **/ |
| 1086 | 1086 | function autoriser_debug_dist($faire, $type, $id, $qui, $opt) { |
| 1087 | - return $qui['statut'] == '0minirezo'; |
|
| 1087 | + return $qui['statut'] == '0minirezo'; |
|
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | /** |
@@ -1101,52 +1101,52 @@ discard block |
||
| 1101 | 1101 | * @return array Liste des rubriques |
| 1102 | 1102 | **/ |
| 1103 | 1103 | function liste_rubriques_auteur($id_auteur, $raz = false) { |
| 1104 | - static $restreint = array(); |
|
| 1105 | - |
|
| 1106 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 1107 | - return array(); |
|
| 1108 | - } |
|
| 1109 | - if ($raz) { |
|
| 1110 | - unset($restreint[$id_auteur]); |
|
| 1111 | - } elseif (isset($restreint[$id_auteur])) { |
|
| 1112 | - return $restreint[$id_auteur]; |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - $rubriques = array(); |
|
| 1116 | - if ((!isset($GLOBALS['meta']['version_installee']) |
|
| 1117 | - or $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1118 | - and $r = sql_allfetsel( |
|
| 1119 | - 'id_objet', |
|
| 1120 | - 'spip_auteurs_liens', |
|
| 1121 | - 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1122 | - ) |
|
| 1123 | - and count($r) |
|
| 1124 | - ) { |
|
| 1125 | - $r = array_column($r, 'id_objet'); |
|
| 1126 | - |
|
| 1127 | - // recuperer toute la branche, au format chaine enumeration |
|
| 1128 | - include_spip('inc/rubriques'); |
|
| 1129 | - $r = calcul_branche_in($r); |
|
| 1130 | - $r = explode(',', $r); |
|
| 1131 | - |
|
| 1132 | - // passer les rubriques en index, elimine les doublons |
|
| 1133 | - $r = array_flip($r); |
|
| 1134 | - // recuperer les index seuls |
|
| 1135 | - $r = array_keys($r); |
|
| 1136 | - // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1137 | - // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1138 | - $rubriques = array_combine($r, $r); |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - // Affecter l'auteur session le cas echeant |
|
| 1142 | - if (isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1143 | - and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1144 | - ) { |
|
| 1145 | - $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - return $restreint[$id_auteur] = $rubriques; |
|
| 1104 | + static $restreint = array(); |
|
| 1105 | + |
|
| 1106 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 1107 | + return array(); |
|
| 1108 | + } |
|
| 1109 | + if ($raz) { |
|
| 1110 | + unset($restreint[$id_auteur]); |
|
| 1111 | + } elseif (isset($restreint[$id_auteur])) { |
|
| 1112 | + return $restreint[$id_auteur]; |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + $rubriques = array(); |
|
| 1116 | + if ((!isset($GLOBALS['meta']['version_installee']) |
|
| 1117 | + or $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1118 | + and $r = sql_allfetsel( |
|
| 1119 | + 'id_objet', |
|
| 1120 | + 'spip_auteurs_liens', |
|
| 1121 | + 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1122 | + ) |
|
| 1123 | + and count($r) |
|
| 1124 | + ) { |
|
| 1125 | + $r = array_column($r, 'id_objet'); |
|
| 1126 | + |
|
| 1127 | + // recuperer toute la branche, au format chaine enumeration |
|
| 1128 | + include_spip('inc/rubriques'); |
|
| 1129 | + $r = calcul_branche_in($r); |
|
| 1130 | + $r = explode(',', $r); |
|
| 1131 | + |
|
| 1132 | + // passer les rubriques en index, elimine les doublons |
|
| 1133 | + $r = array_flip($r); |
|
| 1134 | + // recuperer les index seuls |
|
| 1135 | + $r = array_keys($r); |
|
| 1136 | + // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1137 | + // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1138 | + $rubriques = array_combine($r, $r); |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + // Affecter l'auteur session le cas echeant |
|
| 1142 | + if (isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1143 | + and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1144 | + ) { |
|
| 1145 | + $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + return $restreint[$id_auteur] = $rubriques; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | /** |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | * @return bool true s'il a le droit, false sinon |
| 1163 | 1163 | **/ |
| 1164 | 1164 | function autoriser_rubrique_previsualiser_dist($faire, $type, $id, $qui, $opt) { |
| 1165 | - return autoriser('previsualiser'); |
|
| 1165 | + return autoriser('previsualiser'); |
|
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | /** |
@@ -1178,7 +1178,7 @@ discard block |
||
| 1178 | 1178 | * @return bool true s'il a le droit, false sinon |
| 1179 | 1179 | **/ |
| 1180 | 1180 | function autoriser_rubrique_iconifier_dist($faire, $type, $id, $qui, $opt) { |
| 1181 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1181 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1194,8 +1194,8 @@ discard block |
||
| 1194 | 1194 | * @return bool true s'il a le droit, false sinon |
| 1195 | 1195 | **/ |
| 1196 | 1196 | function autoriser_auteur_iconifier_dist($faire, $type, $id, $qui, $opt) { |
| 1197 | - return (($id == $qui['id_auteur']) or |
|
| 1198 | - (($qui['statut'] == '0minirezo') and !$qui['restreint'])); |
|
| 1197 | + return (($id == $qui['id_auteur']) or |
|
| 1198 | + (($qui['statut'] == '0minirezo') and !$qui['restreint'])); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | /** |
@@ -1211,8 +1211,8 @@ discard block |
||
| 1211 | 1211 | * @return bool true s'il a le droit, false sinon |
| 1212 | 1212 | **/ |
| 1213 | 1213 | function autoriser_iconifier_dist($faire, $type, $id, $qui, $opt) { |
| 1214 | - // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1215 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1214 | + // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1215 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | 1218 | |
@@ -1230,7 +1230,7 @@ discard block |
||
| 1230 | 1230 | * @return bool true |
| 1231 | 1231 | **/ |
| 1232 | 1232 | function autoriser_ok_dist($faire, $type, $id, $qui, $opt) { |
| 1233 | - return true; |
|
| 1233 | + return true; |
|
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | 1236 | /** |
@@ -1247,7 +1247,7 @@ discard block |
||
| 1247 | 1247 | * @return bool false |
| 1248 | 1248 | **/ |
| 1249 | 1249 | function autoriser_niet_dist($faire, $type, $id, $qui, $opt) { |
| 1250 | - return false; |
|
| 1250 | + return false; |
|
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | 1253 | /** |
@@ -1263,11 +1263,11 @@ discard block |
||
| 1263 | 1263 | * @return bool false |
| 1264 | 1264 | **/ |
| 1265 | 1265 | function autoriser_base_reparer_dist($faire, $type, $id, $qui, $opt) { |
| 1266 | - if (!autoriser('detruire') or _request('reinstall')) { |
|
| 1267 | - return false; |
|
| 1268 | - } |
|
| 1266 | + if (!autoriser('detruire') or _request('reinstall')) { |
|
| 1267 | + return false; |
|
| 1268 | + } |
|
| 1269 | 1269 | |
| 1270 | - return true; |
|
| 1270 | + return true; |
|
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | /** |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | * @return bool true s'il a le droit, false sinon |
| 1284 | 1284 | **/ |
| 1285 | 1285 | function autoriser_infosperso_dist($faire, $type, $id, $qui, $opt) { |
| 1286 | - return true; |
|
| 1286 | + return true; |
|
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | /** |
@@ -1299,7 +1299,7 @@ discard block |
||
| 1299 | 1299 | * @return bool true s'il a le droit, false sinon |
| 1300 | 1300 | **/ |
| 1301 | 1301 | function autoriser_langage_configurer_dist($faire, $type, $id, $qui, $opt) { |
| 1302 | - return true; |
|
| 1302 | + return true; |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | /** |
@@ -1315,7 +1315,7 @@ discard block |
||
| 1315 | 1315 | * @return bool true s'il a le droit, false sinon |
| 1316 | 1316 | **/ |
| 1317 | 1317 | function autoriser_configurerlangage_dist($faire, $type, $id, $qui, $opt) { |
| 1318 | - return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1318 | + return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | /** |
@@ -1331,7 +1331,7 @@ discard block |
||
| 1331 | 1331 | * @return bool true s'il a le droit, false sinon |
| 1332 | 1332 | **/ |
| 1333 | 1333 | function autoriser_preferences_configurer_dist($faire, $type, $id, $qui, $opt) { |
| 1334 | - return true; |
|
| 1334 | + return true; |
|
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | /** |
@@ -1347,7 +1347,7 @@ discard block |
||
| 1347 | 1347 | * @return bool true s'il a le droit, false sinon |
| 1348 | 1348 | **/ |
| 1349 | 1349 | function autoriser_configurerpreferences_dist($faire, $type, $id, $qui, $opt) { |
| 1350 | - return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1350 | + return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | /** |
@@ -1363,8 +1363,8 @@ discard block |
||
| 1363 | 1363 | * @return bool true s'il a le droit, false sinon |
| 1364 | 1364 | **/ |
| 1365 | 1365 | function autoriser_menudeveloppement_menugrandeentree_dist($faire, $type, $id, $qui, $opt) { |
| 1366 | - return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) |
|
| 1367 | - and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui'); |
|
| 1366 | + return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) |
|
| 1367 | + and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui'); |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | /** |
@@ -1381,7 +1381,7 @@ discard block |
||
| 1381 | 1381 | * @return bool true s'il a le droit, false sinon |
| 1382 | 1382 | **/ |
| 1383 | 1383 | function autoriser_menugrandeentree_dist($faire, $type, $id, $qui, $opt) { |
| 1384 | - return true; |
|
| 1384 | + return true; |
|
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | 1387 | /** |
@@ -1397,7 +1397,7 @@ discard block |
||
| 1397 | 1397 | * @return bool true s'il a le droit, false sinon |
| 1398 | 1398 | **/ |
| 1399 | 1399 | function autoriser_auteurs_voir_dist($faire, $type, $id, $qui, $opt) { |
| 1400 | - return true; |
|
| 1400 | + return true; |
|
| 1401 | 1401 | } |
| 1402 | 1402 | |
| 1403 | 1403 | /** |
@@ -1413,7 +1413,7 @@ discard block |
||
| 1413 | 1413 | * @return bool true s'il a le droit, false sinon |
| 1414 | 1414 | **/ |
| 1415 | 1415 | function autoriser_auteurs_menu_dist($faire, $type, $id, $qui, $opt) { |
| 1416 | - return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1416 | + return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | /** |
@@ -1429,7 +1429,7 @@ discard block |
||
| 1429 | 1429 | * @return bool true s'il a le droit, false sinon |
| 1430 | 1430 | **/ |
| 1431 | 1431 | function autoriser_articles_voir_dist($faire, $type, $id, $qui, $opt) { |
| 1432 | - return true; |
|
| 1432 | + return true; |
|
| 1433 | 1433 | } |
| 1434 | 1434 | |
| 1435 | 1435 | /** |
@@ -1445,7 +1445,7 @@ discard block |
||
| 1445 | 1445 | * @return bool true s'il a le droit, false sinon |
| 1446 | 1446 | **/ |
| 1447 | 1447 | function autoriser_articles_menu_dist($faire, $type, $id, $qui, $opt) { |
| 1448 | - return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1448 | + return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | 1451 | /** |
@@ -1461,7 +1461,7 @@ discard block |
||
| 1461 | 1461 | * @return bool true s'il a le droit, false sinon |
| 1462 | 1462 | **/ |
| 1463 | 1463 | function autoriser_rubriques_voir_dist($faire, $type, $id, $qui, $opt) { |
| 1464 | - return true; |
|
| 1464 | + return true; |
|
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | /** |
@@ -1477,7 +1477,7 @@ discard block |
||
| 1477 | 1477 | * @return bool true s'il a le droit, false sinon |
| 1478 | 1478 | **/ |
| 1479 | 1479 | function autoriser_rubriques_menu_dist($faire, $type, $id, $qui, $opt) { |
| 1480 | - return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1480 | + return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1481 | 1481 | } |
| 1482 | 1482 | |
| 1483 | 1483 | /** |
@@ -1493,7 +1493,7 @@ discard block |
||
| 1493 | 1493 | * @return bool true s'il a le droit, false sinon |
| 1494 | 1494 | **/ |
| 1495 | 1495 | function autoriser_articlecreer_menu_dist($faire, $type, $id, $qui, $opt) { |
| 1496 | - return verifier_table_non_vide(); |
|
| 1496 | + return verifier_table_non_vide(); |
|
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | 1499 | |
@@ -1512,7 +1512,7 @@ discard block |
||
| 1512 | 1512 | * @return bool true s'il a le droit, false sinon |
| 1513 | 1513 | **/ |
| 1514 | 1514 | function autoriser_auteurcreer_menu_dist($faire, $type, $id, $qui, $opt) { |
| 1515 | - return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1515 | + return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1516 | 1516 | } |
| 1517 | 1517 | |
| 1518 | 1518 | /** |
@@ -1528,13 +1528,13 @@ discard block |
||
| 1528 | 1528 | * @return bool true s'il a le droit, false sinon |
| 1529 | 1529 | **/ |
| 1530 | 1530 | function autoriser_visiteurs_menu_dist($faire, $type, $id, $qui, $opt) { |
| 1531 | - include_spip('base/abstract_sql'); |
|
| 1532 | - return |
|
| 1533 | - $qui['statut'] == '0minirezo' and !$qui['restreint'] |
|
| 1534 | - and ( |
|
| 1535 | - $GLOBALS['meta']["accepter_visiteurs"] != 'non' |
|
| 1536 | - or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0 |
|
| 1537 | - ); |
|
| 1531 | + include_spip('base/abstract_sql'); |
|
| 1532 | + return |
|
| 1533 | + $qui['statut'] == '0minirezo' and !$qui['restreint'] |
|
| 1534 | + and ( |
|
| 1535 | + $GLOBALS['meta']["accepter_visiteurs"] != 'non' |
|
| 1536 | + or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0 |
|
| 1537 | + ); |
|
| 1538 | 1538 | } |
| 1539 | 1539 | |
| 1540 | 1540 | /** |
@@ -1550,7 +1550,7 @@ discard block |
||
| 1550 | 1550 | * @return bool true s'il a le droit, false sinon |
| 1551 | 1551 | **/ |
| 1552 | 1552 | function autoriser_suiviedito_menu_dist($faire, $type, $id, $qui, $opt) { |
| 1553 | - return $qui['statut'] == '0minirezo'; |
|
| 1553 | + return $qui['statut'] == '0minirezo'; |
|
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | 1556 | /** |
@@ -1566,7 +1566,7 @@ discard block |
||
| 1566 | 1566 | * @return bool true s'il a le droit, false sinon |
| 1567 | 1567 | **/ |
| 1568 | 1568 | function autoriser_synchro_menu_dist($faire, $type, $id, $qui, $opt) { |
| 1569 | - return $qui['statut'] == '0minirezo'; |
|
| 1569 | + return $qui['statut'] == '0minirezo'; |
|
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | /** |
@@ -1694,7 +1694,7 @@ discard block |
||
| 1694 | 1694 | * @return bool true s'il a le droit, false sinon |
| 1695 | 1695 | **/ |
| 1696 | 1696 | function autoriser_queue_purger_dist($faire, $type, $id, $qui, $opt) { |
| 1697 | - return autoriser('webmestre'); |
|
| 1697 | + return autoriser('webmestre'); |
|
| 1698 | 1698 | } |
| 1699 | 1699 | |
| 1700 | 1700 | |
@@ -1712,11 +1712,11 @@ discard block |
||
| 1712 | 1712 | * @return bool true s'il a le droit, false sinon |
| 1713 | 1713 | **/ |
| 1714 | 1714 | function autoriser_echafauder_dist($faire, $type, $id, $qui, $opt) { |
| 1715 | - if (test_espace_prive()) { |
|
| 1716 | - return intval($qui['id_auteur']) ? true : false; |
|
| 1717 | - } else { |
|
| 1718 | - return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1719 | - } |
|
| 1715 | + if (test_espace_prive()) { |
|
| 1716 | + return intval($qui['id_auteur']) ? true : false; |
|
| 1717 | + } else { |
|
| 1718 | + return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1719 | + } |
|
| 1720 | 1720 | } |
| 1721 | 1721 | |
| 1722 | 1722 | |
@@ -1731,27 +1731,27 @@ discard block |
||
| 1731 | 1731 | * Identifiants d'auteurs |
| 1732 | 1732 | */ |
| 1733 | 1733 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1734 | - $objet = objet_type($objet); |
|
| 1735 | - $where = array( |
|
| 1736 | - 'objet=' . sql_quote($objet), |
|
| 1737 | - 'id_objet=' . intval($id_objet) |
|
| 1738 | - ); |
|
| 1739 | - if (!empty($cond)) { |
|
| 1740 | - if (is_array($cond)) { |
|
| 1741 | - $where = array_merge($where, $cond); |
|
| 1742 | - } else { |
|
| 1743 | - $where[] = $cond; |
|
| 1744 | - } |
|
| 1745 | - } |
|
| 1746 | - $auteurs = sql_allfetsel( |
|
| 1747 | - 'id_auteur', |
|
| 1748 | - 'spip_auteurs_liens', |
|
| 1749 | - $where |
|
| 1750 | - ); |
|
| 1751 | - if (is_array($auteurs)) { |
|
| 1752 | - return array_column($auteurs, 'id_auteur'); |
|
| 1753 | - } |
|
| 1754 | - return array(); |
|
| 1734 | + $objet = objet_type($objet); |
|
| 1735 | + $where = array( |
|
| 1736 | + 'objet=' . sql_quote($objet), |
|
| 1737 | + 'id_objet=' . intval($id_objet) |
|
| 1738 | + ); |
|
| 1739 | + if (!empty($cond)) { |
|
| 1740 | + if (is_array($cond)) { |
|
| 1741 | + $where = array_merge($where, $cond); |
|
| 1742 | + } else { |
|
| 1743 | + $where[] = $cond; |
|
| 1744 | + } |
|
| 1745 | + } |
|
| 1746 | + $auteurs = sql_allfetsel( |
|
| 1747 | + 'id_auteur', |
|
| 1748 | + 'spip_auteurs_liens', |
|
| 1749 | + $where |
|
| 1750 | + ); |
|
| 1751 | + if (is_array($auteurs)) { |
|
| 1752 | + return array_column($auteurs, 'id_auteur'); |
|
| 1753 | + } |
|
| 1754 | + return array(); |
|
| 1755 | 1755 | } |
| 1756 | 1756 | |
| 1757 | 1757 | /** |
@@ -1765,11 +1765,11 @@ discard block |
||
| 1765 | 1765 | * - false : serveur SQL indisponible |
| 1766 | 1766 | */ |
| 1767 | 1767 | function auteurs_article($id_article, $cond = '') { |
| 1768 | - return sql_allfetsel( |
|
| 1769 | - 'id_auteur', |
|
| 1770 | - 'spip_auteurs_liens', |
|
| 1771 | - "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1772 | - ); |
|
| 1768 | + return sql_allfetsel( |
|
| 1769 | + 'id_auteur', |
|
| 1770 | + 'spip_auteurs_liens', |
|
| 1771 | + "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1772 | + ); |
|
| 1773 | 1773 | } |
| 1774 | 1774 | |
| 1775 | 1775 | |
@@ -1783,7 +1783,7 @@ discard block |
||
| 1783 | 1783 | */ |
| 1784 | 1784 | function acces_restreint_rubrique($id_rubrique) { |
| 1785 | 1785 | |
| 1786 | - return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1786 | + return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1787 | 1787 | } |
| 1788 | 1788 | |
| 1789 | 1789 | |
@@ -1796,12 +1796,12 @@ discard block |
||
| 1796 | 1796 | * @return bool true si un parent existe |
| 1797 | 1797 | */ |
| 1798 | 1798 | function verifier_table_non_vide($table = 'spip_rubriques') { |
| 1799 | - static $done = array(); |
|
| 1800 | - if (!isset($done[$table])) { |
|
| 1801 | - $done[$table] = sql_countsel($table) > 0; |
|
| 1802 | - } |
|
| 1799 | + static $done = array(); |
|
| 1800 | + if (!isset($done[$table])) { |
|
| 1801 | + $done[$table] = sql_countsel($table) > 0; |
|
| 1802 | + } |
|
| 1803 | 1803 | |
| 1804 | - return $done[$table]; |
|
| 1804 | + return $done[$table]; |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | 1807 | /** |
@@ -1826,15 +1826,15 @@ discard block |
||
| 1826 | 1826 | */ |
| 1827 | 1827 | function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) { |
| 1828 | 1828 | |
| 1829 | - $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1830 | - switch ($s) { |
|
| 1831 | - case 'info_redacteurs': |
|
| 1832 | - return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui'); |
|
| 1833 | - case 'info_visiteurs': |
|
| 1834 | - return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo'); |
|
| 1835 | - } |
|
| 1829 | + $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1830 | + switch ($s) { |
|
| 1831 | + case 'info_redacteurs': |
|
| 1832 | + return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui'); |
|
| 1833 | + case 'info_visiteurs': |
|
| 1834 | + return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo'); |
|
| 1835 | + } |
|
| 1836 | 1836 | |
| 1837 | - return false; |
|
| 1837 | + return false; |
|
| 1838 | 1838 | } |
| 1839 | 1839 | |
| 1840 | 1840 | /** |
@@ -1850,7 +1850,7 @@ discard block |
||
| 1850 | 1850 | * @return bool false |
| 1851 | 1851 | **/ |
| 1852 | 1852 | function autoriser_inscription_relancer_dist($faire, $type, $id, $qui, $opt) { |
| 1853 | - return $qui['statut'] == '0minirezo' and !$qui['restreint']; |
|
| 1853 | + return $qui['statut'] == '0minirezo' and !$qui['restreint']; |
|
| 1854 | 1854 | } |
| 1855 | 1855 | |
| 1856 | 1856 | /** |
@@ -1866,5 +1866,5 @@ discard block |
||
| 1866 | 1866 | * @return bool true s'il a le droit, false sinon |
| 1867 | 1867 | **/ |
| 1868 | 1868 | function autoriser_phpinfos_dist($faire, $type, $id, $qui, $opt) { |
| 1869 | - return autoriser('webmestre'); |
|
| 1869 | + return autoriser('webmestre'); |
|
| 1870 | 1870 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | // mais apres la fonction autoriser() |
| 115 | 115 | if ($f = find_in_path('mes_fonctions.php')) { |
| 116 | 116 | global $dossier_squelettes; |
| 117 | - include_once(_ROOT_CWD . $f); |
|
| 117 | + include_once(_ROOT_CWD.$f); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array(); |
| 149 | 149 | $qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui); |
| 150 | 150 | } elseif (is_numeric($qui)) { |
| 151 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 151 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // Admins restreints, on construit ici (pas generique mais...) |
@@ -158,8 +158,8 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | spip_log( |
| 161 | - "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?', |
|
| 162 | - 'autoriser' . _LOG_DEBUG |
|
| 161 | + "autoriser $faire $type $id (".(isset($qui['nom']) ? $qui['nom'] : '').') ?', |
|
| 162 | + 'autoriser'._LOG_DEBUG |
|
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | 165 | // passer par objet_type pour avoir les alias |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | if ((isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier')) |
| 171 | 171 | or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
| 172 | 172 | ) { |
| 173 | - spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 173 | + spip_log("autoriser ($faire, $type, $id, ".(isset($qui['nom']) ? $qui['nom'] : '').') : OK Exception', 'autoriser'._LOG_DEBUG); |
|
| 174 | 174 | return true; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -179,18 +179,18 @@ discard block |
||
| 179 | 179 | // autoriser_faire[_dist], autoriser_defaut[_dist] |
| 180 | 180 | $fonctions = $type |
| 181 | 181 | ? array( |
| 182 | - 'autoriser_' . $type . '_' . $faire, |
|
| 183 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 184 | - 'autoriser_' . $type, |
|
| 185 | - 'autoriser_' . $type . '_dist', |
|
| 186 | - 'autoriser_' . $faire, |
|
| 187 | - 'autoriser_' . $faire . '_dist', |
|
| 182 | + 'autoriser_'.$type.'_'.$faire, |
|
| 183 | + 'autoriser_'.$type.'_'.$faire.'_dist', |
|
| 184 | + 'autoriser_'.$type, |
|
| 185 | + 'autoriser_'.$type.'_dist', |
|
| 186 | + 'autoriser_'.$faire, |
|
| 187 | + 'autoriser_'.$faire.'_dist', |
|
| 188 | 188 | 'autoriser_defaut', |
| 189 | 189 | 'autoriser_defaut_dist' |
| 190 | 190 | ) |
| 191 | 191 | : array( |
| 192 | - 'autoriser_' . $faire, |
|
| 193 | - 'autoriser_' . $faire . '_dist', |
|
| 192 | + 'autoriser_'.$faire, |
|
| 193 | + 'autoriser_'.$faire.'_dist', |
|
| 194 | 194 | 'autoriser_defaut', |
| 195 | 195 | 'autoriser_defaut_dist' |
| 196 | 196 | ); |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | spip_log( |
| 206 | - "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 207 | - 'autoriser' . _LOG_DEBUG |
|
| 206 | + "$f($faire, $type, $id, ".(isset($qui['nom']) ? $qui['nom'] : '').') : '.($a ? 'OK' : 'niet'), |
|
| 207 | + 'autoriser'._LOG_DEBUG |
|
| 208 | 208 | ); |
| 209 | 209 | |
| 210 | 210 | return $a; |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | function autoriser_previsualiser_dist($faire, $type, $id, $qui, $opt) { |
| 333 | 333 | |
| 334 | 334 | // Le visiteur a-t-il un statut prevu par la config ? |
| 335 | - if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 335 | + if (strpos($GLOBALS['meta']['preview'], ','.$qui['statut'].',') !== false) { |
|
| 336 | 336 | return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
| 337 | 337 | } |
| 338 | 338 | |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | } // pas de champ passe a la demande => NIET |
| 390 | 390 | $previsu = explode(',', $c['previsu']); |
| 391 | 391 | // regarder si ce statut est autorise pour l'auteur |
| 392 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 392 | + if (in_array($opt[$champ].'/auteur', $previsu)) { |
|
| 393 | 393 | |
| 394 | 394 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 395 | 395 | // sinon l’auteur en session |
@@ -404,11 +404,11 @@ discard block |
||
| 404 | 404 | |
| 405 | 405 | if (!$id_auteur) { |
| 406 | 406 | return false; |
| 407 | - } elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) { |
|
| 407 | + } elseif (autoriser('previsualiser'.$opt[$champ], $type, '', $id_auteur)) { |
|
| 408 | 408 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 409 | 409 | } elseif (!sql_countsel( |
| 410 | 410 | 'spip_auteurs_liens', |
| 411 | - 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 411 | + 'id_auteur='.intval($id_auteur).' AND objet='.sql_quote($type).' AND id_objet='.intval($id) |
|
| 412 | 412 | )) { |
| 413 | 413 | return false; |
| 414 | 414 | } // pas auteur de cet objet => NIET |
@@ -446,16 +446,16 @@ discard block |
||
| 446 | 446 | // multilinguisme par secteur et objet rattaché à une rubrique |
| 447 | 447 | $primary = id_table_objet($type); |
| 448 | 448 | if ($table != 'spip_rubriques') { |
| 449 | - $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 449 | + $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=".intval($id)); |
|
| 450 | 450 | } else { |
| 451 | 451 | $id_rubrique = $id; |
| 452 | 452 | } |
| 453 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 453 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 454 | 454 | if (!$id_secteur > 0) { |
| 455 | 455 | $id_secteur = $id_rubrique; |
| 456 | 456 | } |
| 457 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 458 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 457 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.intval($id_secteur)); |
|
| 458 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=".intval($id)); |
|
| 459 | 459 | if ($langue_secteur != $langue_objet) { |
| 460 | 460 | // configuration incohérente, on laisse l'utilisateur corriger la situation |
| 461 | 461 | return true; |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
| 464 | 464 | return false; |
| 465 | 465 | } else { |
| 466 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 466 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id)); |
|
| 467 | 467 | if ($id_parent != 0) { |
| 468 | 468 | // sous-rubriques : pas de choix de langue |
| 469 | 469 | return false; |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | |
| 512 | 512 | if (!isset($opt['statut'])) { |
| 513 | 513 | if (isset($desc['field']['statut'])) { |
| 514 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 514 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.intval($id)); |
|
| 515 | 515 | } else { |
| 516 | 516 | $statut = 'publie'; |
| 517 | 517 | } // pas de statut => publie |
@@ -669,11 +669,11 @@ discard block |
||
| 669 | 669 | return false; |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 672 | + if (sql_countsel('spip_rubriques', 'id_parent='.intval($id))) { |
|
| 673 | 673 | return false; |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | - if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 676 | + if (sql_countsel('spip_articles', 'id_rubrique='.intval($id)." AND (statut<>'poubelle')")) { |
|
| 677 | 677 | return false; |
| 678 | 678 | } |
| 679 | 679 | |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | * @return bool true s'il a le droit, false sinon |
| 706 | 706 | **/ |
| 707 | 707 | function autoriser_article_modifier_dist($faire, $type, $id, $qui, $opt) { |
| 708 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 708 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id)); |
|
| 709 | 709 | |
| 710 | 710 | return |
| 711 | 711 | $r |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
| 717 | 717 | and in_array($qui['statut'], array('0minirezo', '1comite')) |
| 718 | 718 | and in_array($r['statut'], array('prop', 'prepa', 'poubelle')) |
| 719 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 719 | + and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']) |
|
| 720 | 720 | ) |
| 721 | 721 | ); |
| 722 | 722 | } |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | if (!$id) { |
| 765 | 765 | return false; |
| 766 | 766 | } |
| 767 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 767 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.intval($id)); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | return |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | or |
| 776 | 776 | ($id |
| 777 | 777 | and $qui['id_auteur'] |
| 778 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 778 | + and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur'])); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
@@ -793,8 +793,8 @@ discard block |
||
| 793 | 793 | **/ |
| 794 | 794 | function autoriser_voir_dist($faire, $type, $id, $qui, $opt) { |
| 795 | 795 | # securite, mais on aurait pas du arriver ici ! |
| 796 | - if (function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 797 | - or function_exists($f = 'autoriser_' . $type . '_voir_dist')) { |
|
| 796 | + if (function_exists($f = 'autoriser_'.$type.'_voir') |
|
| 797 | + or function_exists($f = 'autoriser_'.$type.'_voir_dist')) { |
|
| 798 | 798 | return $f($faire, $type, $id, $qui, $opt); |
| 799 | 799 | } |
| 800 | 800 | |
@@ -912,7 +912,7 @@ discard block |
||
| 912 | 912 | $n = sql_fetsel( |
| 913 | 913 | 'A.id_article', |
| 914 | 914 | 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
| 915 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 915 | + "A.statut='publie' AND L.id_auteur=".sql_quote($id) |
|
| 916 | 916 | ); |
| 917 | 917 | |
| 918 | 918 | return $n ? true : false; |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | and $r = sql_allfetsel( |
| 1119 | 1119 | 'id_objet', |
| 1120 | 1120 | 'spip_auteurs_liens', |
| 1121 | - 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1121 | + 'id_auteur='.intval($id_auteur)." AND objet='rubrique' AND id_objet!=0" |
|
| 1122 | 1122 | ) |
| 1123 | 1123 | and count($r) |
| 1124 | 1124 | ) { |
@@ -1733,8 +1733,8 @@ discard block |
||
| 1733 | 1733 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1734 | 1734 | $objet = objet_type($objet); |
| 1735 | 1735 | $where = array( |
| 1736 | - 'objet=' . sql_quote($objet), |
|
| 1737 | - 'id_objet=' . intval($id_objet) |
|
| 1736 | + 'objet='.sql_quote($objet), |
|
| 1737 | + 'id_objet='.intval($id_objet) |
|
| 1738 | 1738 | ); |
| 1739 | 1739 | if (!empty($cond)) { |
| 1740 | 1740 | if (is_array($cond)) { |
@@ -1768,7 +1768,7 @@ discard block |
||
| 1768 | 1768 | return sql_allfetsel( |
| 1769 | 1769 | 'id_auteur', |
| 1770 | 1770 | 'spip_auteurs_liens', |
| 1771 | - "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1771 | + "objet='article' AND id_objet=".intval($id_article).($cond ? " AND $cond" : '') |
|
| 1772 | 1772 | ); |
| 1773 | 1773 | } |
| 1774 | 1774 | |
@@ -237,8 +237,7 @@ |
||
| 237 | 237 | if ($id === '*') { |
| 238 | 238 | unset($GLOBALS['autoriser_exception'][$faire][$type]); |
| 239 | 239 | unset($autorisation[$faire][$type]); |
| 240 | - } |
|
| 241 | - else { |
|
| 240 | + } else { |
|
| 242 | 241 | unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
| 243 | 242 | unset($autorisation[$faire][$type][$id]); |
| 244 | 243 | } |