@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 30 | - return; |
|
| 30 | + return; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -47,55 +47,55 @@ discard block |
||
| 47 | 47 | * array : description des roles applicables dans 3 index : colonne, titres, roles |
| 48 | 48 | **/ |
| 49 | 49 | function roles_presents($objet, $objet_destination = '') { |
| 50 | - $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 51 | - |
|
| 52 | - // pas de liste de roles, on sort |
|
| 53 | - if (!isset($desc['roles_titres']) || !($titres = $desc['roles_titres'])) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // on vérifie que la table de liaison existe |
|
| 58 | - include_spip('action/editer_liens'); |
|
| 59 | - if (!$lien = objet_associable($objet)) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 64 | - $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 65 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 66 | - [, $table_lien] = $lien; |
|
| 67 | - $desc_lien = $trouver_table($table_lien); |
|
| 68 | - if (!isset($desc_lien['field'][$colonne])) { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // sur quoi peuvent s'appliquer nos rôles |
|
| 73 | - if (!$application = $desc['roles_objets']) { |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // destination presente, on restreint si possible |
|
| 78 | - if ($objet_destination) { |
|
| 79 | - $objet_destination = table_objet($objet_destination); |
|
| 80 | - |
|
| 81 | - // pour l'objet |
|
| 82 | - if (isset($application[$objet_destination])) { |
|
| 83 | - $application = $application[$objet_destination]; |
|
| 84 | - // sinon pour tous les objets |
|
| 85 | - } elseif (isset($application['*'])) { |
|
| 86 | - $application = $application['*']; |
|
| 87 | - } // sinon tant pis |
|
| 88 | - else { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // tout est ok |
|
| 94 | - return [ |
|
| 95 | - 'titres' => $titres, |
|
| 96 | - 'roles' => $application, |
|
| 97 | - 'colonne' => $colonne |
|
| 98 | - ]; |
|
| 50 | + $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 51 | + |
|
| 52 | + // pas de liste de roles, on sort |
|
| 53 | + if (!isset($desc['roles_titres']) || !($titres = $desc['roles_titres'])) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // on vérifie que la table de liaison existe |
|
| 58 | + include_spip('action/editer_liens'); |
|
| 59 | + if (!$lien = objet_associable($objet)) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 64 | + $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 65 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 66 | + [, $table_lien] = $lien; |
|
| 67 | + $desc_lien = $trouver_table($table_lien); |
|
| 68 | + if (!isset($desc_lien['field'][$colonne])) { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // sur quoi peuvent s'appliquer nos rôles |
|
| 73 | + if (!$application = $desc['roles_objets']) { |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // destination presente, on restreint si possible |
|
| 78 | + if ($objet_destination) { |
|
| 79 | + $objet_destination = table_objet($objet_destination); |
|
| 80 | + |
|
| 81 | + // pour l'objet |
|
| 82 | + if (isset($application[$objet_destination])) { |
|
| 83 | + $application = $application[$objet_destination]; |
|
| 84 | + // sinon pour tous les objets |
|
| 85 | + } elseif (isset($application['*'])) { |
|
| 86 | + $application = $application['*']; |
|
| 87 | + } // sinon tant pis |
|
| 88 | + else { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // tout est ok |
|
| 94 | + return [ |
|
| 95 | + 'titres' => $titres, |
|
| 96 | + 'roles' => $application, |
|
| 97 | + 'colonne' => $colonne |
|
| 98 | + ]; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | * Nom de la colonne, sinon vide |
| 110 | 110 | **/ |
| 111 | 111 | function roles_colonne($objet, $objet_destination) { |
| 112 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 113 | - return $roles['colonne']; |
|
| 114 | - } |
|
| 112 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 113 | + return $roles['colonne']; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - return ''; |
|
| 116 | + return ''; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
@@ -135,21 +135,21 @@ discard block |
||
| 135 | 135 | * Liste ('', '', array()) sinon. |
| 136 | 136 | **/ |
| 137 | 137 | function roles_trouver_dans_qualif($objet, $objet_destination, $qualif = []) { |
| 138 | - // si des rôles sont possibles, on les utilise |
|
| 139 | - $role = $colonne_role = ''; # role défini |
|
| 140 | - // condition du where par defaut |
|
| 141 | - $cond = []; |
|
| 142 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 143 | - $colonne_role = $roles['colonne']; |
|
| 144 | - // qu'il n'est pas défini |
|
| 145 | - if (!isset($qualif[$colonne_role]) || !($role = $qualif[$colonne_role])) { |
|
| 146 | - $role = $roles['roles']['defaut']; |
|
| 147 | - } |
|
| 148 | - // where |
|
| 149 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return [$role, $colonne_role, $cond]; |
|
| 138 | + // si des rôles sont possibles, on les utilise |
|
| 139 | + $role = $colonne_role = ''; # role défini |
|
| 140 | + // condition du where par defaut |
|
| 141 | + $cond = []; |
|
| 142 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 143 | + $colonne_role = $roles['colonne']; |
|
| 144 | + // qu'il n'est pas défini |
|
| 145 | + if (!isset($qualif[$colonne_role]) || !($role = $qualif[$colonne_role])) { |
|
| 146 | + $role = $roles['roles']['defaut']; |
|
| 147 | + } |
|
| 148 | + // where |
|
| 149 | + $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return [$role, $colonne_role, $cond]; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -171,18 +171,18 @@ discard block |
||
| 171 | 171 | * Liste (Tableau de conditions where complété du role, Colonne du role, role utilisé) |
| 172 | 172 | **/ |
| 173 | 173 | function roles_creer_condition_role($objet_source, $objet, $cond, $tous_si_absent = false) { |
| 174 | - // role par défaut, colonne |
|
| 175 | - [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 176 | - |
|
| 177 | - // chercher d'eventuels rôles transmis |
|
| 178 | - $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 179 | - unset($cond['role']); // cette condition est particuliere... |
|
| 180 | - // on ajoute la condition du role aux autres conditions. |
|
| 181 | - if ($colonne_role && $role != '*') { |
|
| 182 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return [$cond, $colonne_role, $role]; |
|
| 174 | + // role par défaut, colonne |
|
| 175 | + [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 176 | + |
|
| 177 | + // chercher d'eventuels rôles transmis |
|
| 178 | + $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 179 | + unset($cond['role']); // cette condition est particuliere... |
|
| 180 | + // on ajoute la condition du role aux autres conditions. |
|
| 181 | + if ($colonne_role && $role != '*') { |
|
| 182 | + $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return [$cond, $colonne_role, $role]; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -204,28 +204,28 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | function roles_complets($objet_source, $objet, $id_objet, $objet_lien) { |
| 206 | 206 | |
| 207 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 208 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 209 | - if ($presents === false) { |
|
| 210 | - return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - // types de roles possibles |
|
| 214 | - $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 215 | - // couples id / roles |
|
| 216 | - $ids = $presents['ids']; |
|
| 217 | - |
|
| 218 | - // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 219 | - // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 220 | - // n'est pas complet |
|
| 221 | - $complets = []; |
|
| 222 | - foreach ($ids as $id => $roles_presents) { |
|
| 223 | - if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 224 | - $complets[] = $id; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $complets; |
|
| 207 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 208 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 209 | + if ($presents === false) { |
|
| 210 | + return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + // types de roles possibles |
|
| 214 | + $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 215 | + // couples id / roles |
|
| 216 | + $ids = $presents['ids']; |
|
| 217 | + |
|
| 218 | + // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 219 | + // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 220 | + // n'est pas complet |
|
| 221 | + $complets = []; |
|
| 222 | + foreach ($ids as $id => $roles_presents) { |
|
| 223 | + if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 224 | + $complets[] = $id; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $complets; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | |
@@ -242,17 +242,17 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | function roles_presents_sur_id($id_objet_source, $objet_source, $objet, $id_objet, $objet_lien) { |
| 244 | 244 | |
| 245 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 246 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 247 | - if ($presents === false) { |
|
| 248 | - return []; |
|
| 249 | - } |
|
| 245 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 246 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 247 | + if ($presents === false) { |
|
| 248 | + return []; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - if (!isset($presents['ids'][$id_objet_source])) { |
|
| 252 | - return []; |
|
| 253 | - } |
|
| 251 | + if (!isset($presents['ids'][$id_objet_source])) { |
|
| 252 | + return []; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - return $presents['ids'][$id_objet_source]; |
|
| 255 | + return $presents['ids'][$id_objet_source]; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
@@ -280,47 +280,47 @@ discard block |
||
| 280 | 280 | * - False si pas de role déclarés |
| 281 | 281 | */ |
| 282 | 282 | function roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien) { |
| 283 | - static $done = []; |
|
| 284 | - |
|
| 285 | - // stocker le résultat |
|
| 286 | - $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 287 | - if (isset($done[$hash])) { |
|
| 288 | - return $done[$hash]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // pas de roles sur ces objets, on sort |
|
| 292 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 293 | - if (!$roles) { |
|
| 294 | - return $done[$hash] = false; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // inspiré de lister_objets_lies() |
|
| 298 | - if ($objet_lien == $objet) { |
|
| 299 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 300 | - } else { |
|
| 301 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // types de roles possibles |
|
| 305 | - $roles_possibles = $roles['roles']['choix']; |
|
| 306 | - // colonne du role |
|
| 307 | - $colonne = $roles['colonne']; |
|
| 308 | - |
|
| 309 | - // on recupere par id, et role existant |
|
| 310 | - $ids = []; |
|
| 311 | - while ($row = array_shift($res)) { |
|
| 312 | - $id = $row[$objet_source]; |
|
| 313 | - if (!isset($ids[$id])) { |
|
| 314 | - $ids[$id] = []; |
|
| 315 | - } |
|
| 316 | - // tableau des roles présents |
|
| 317 | - $ids[$id][] = $row[$colonne]; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - return $done[$hash] = [ |
|
| 321 | - 'roles' => $roles, |
|
| 322 | - 'ids' => $ids |
|
| 323 | - ]; |
|
| 283 | + static $done = []; |
|
| 284 | + |
|
| 285 | + // stocker le résultat |
|
| 286 | + $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 287 | + if (isset($done[$hash])) { |
|
| 288 | + return $done[$hash]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // pas de roles sur ces objets, on sort |
|
| 292 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 293 | + if (!$roles) { |
|
| 294 | + return $done[$hash] = false; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // inspiré de lister_objets_lies() |
|
| 298 | + if ($objet_lien == $objet) { |
|
| 299 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 300 | + } else { |
|
| 301 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // types de roles possibles |
|
| 305 | + $roles_possibles = $roles['roles']['choix']; |
|
| 306 | + // colonne du role |
|
| 307 | + $colonne = $roles['colonne']; |
|
| 308 | + |
|
| 309 | + // on recupere par id, et role existant |
|
| 310 | + $ids = []; |
|
| 311 | + while ($row = array_shift($res)) { |
|
| 312 | + $id = $row[$objet_source]; |
|
| 313 | + if (!isset($ids[$id])) { |
|
| 314 | + $ids[$id] = []; |
|
| 315 | + } |
|
| 316 | + // tableau des roles présents |
|
| 317 | + $ids[$id][] = $row[$colonne]; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + return $done[$hash] = [ |
|
| 321 | + 'roles' => $roles, |
|
| 322 | + 'ids' => $ids |
|
| 323 | + ]; |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | |
@@ -338,33 +338,33 @@ discard block |
||
| 338 | 338 | * - false si pas de role déclarés |
| 339 | 339 | */ |
| 340 | 340 | function roles_connus_en_base($objet_source, $objet, $objet_lien) { |
| 341 | - static $done = []; |
|
| 342 | - |
|
| 343 | - // stocker le résultat |
|
| 344 | - $hash = "$objet_source-$objet-$objet_lien"; |
|
| 345 | - if (isset($done[$hash])) { |
|
| 346 | - return $done[$hash]; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if (!$lien = objet_associable($objet_lien)) { |
|
| 350 | - return $done[$hash] = false; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // pas de roles sur ces objets, on sort |
|
| 354 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 355 | - if (!$roles) { |
|
| 356 | - return $done[$hash] = false; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - [$primary, $l] = $lien; |
|
| 360 | - $colone_role = $roles['colonne']; |
|
| 361 | - |
|
| 362 | - $all = sql_allfetsel( |
|
| 363 | - "DISTINCT $colone_role", |
|
| 364 | - $l, |
|
| 365 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | - ); |
|
| 367 | - $done[$hash] = array_map('reset', $all); |
|
| 368 | - |
|
| 369 | - return $done[$hash]; |
|
| 341 | + static $done = []; |
|
| 342 | + |
|
| 343 | + // stocker le résultat |
|
| 344 | + $hash = "$objet_source-$objet-$objet_lien"; |
|
| 345 | + if (isset($done[$hash])) { |
|
| 346 | + return $done[$hash]; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if (!$lien = objet_associable($objet_lien)) { |
|
| 350 | + return $done[$hash] = false; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // pas de roles sur ces objets, on sort |
|
| 354 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 355 | + if (!$roles) { |
|
| 356 | + return $done[$hash] = false; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + [$primary, $l] = $lien; |
|
| 360 | + $colone_role = $roles['colonne']; |
|
| 361 | + |
|
| 362 | + $all = sql_allfetsel( |
|
| 363 | + "DISTINCT $colone_role", |
|
| 364 | + $l, |
|
| 365 | + 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | + ); |
|
| 367 | + $done[$hash] = array_map('reset', $all); |
|
| 368 | + |
|
| 369 | + return $done[$hash]; |
|
| 370 | 370 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/charsets'); |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * @return array |
| 42 | 42 | */ |
| 43 | 43 | function importer_csv_importcharset($texte, $definir_charset_source = false) { |
| 44 | - // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 45 | - static $charset_source = 'iso-8859-1'; |
|
| 46 | - if ($definir_charset_source) { |
|
| 47 | - $charset_source = $definir_charset_source === true ? 'iso-8859-1' : $definir_charset_source; |
|
| 48 | - } |
|
| 49 | - // mais open-office sait faire mieux, donc mefiance ! |
|
| 50 | - $charset = is_utf8($texte) ? 'utf-8' : $charset_source; |
|
| 51 | - return importer_charset($texte, $charset); |
|
| 44 | + // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 45 | + static $charset_source = 'iso-8859-1'; |
|
| 46 | + if ($definir_charset_source) { |
|
| 47 | + $charset_source = $definir_charset_source === true ? 'iso-8859-1' : $definir_charset_source; |
|
| 48 | + } |
|
| 49 | + // mais open-office sait faire mieux, donc mefiance ! |
|
| 50 | + $charset = is_utf8($texte) ? 'utf-8' : $charset_source; |
|
| 51 | + return importer_charset($texte, $charset); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function importer_csv_nettoie_key($key) { |
| 62 | - return translitteration($key); |
|
| 62 | + return translitteration($key); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -78,70 +78,70 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | function inc_importer_csv_dist($file, $options = []) { |
| 80 | 80 | |
| 81 | - // support ancienne syntaxe |
|
| 82 | - // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 83 | - if (!is_array($options)) { |
|
| 84 | - $args = func_get_args(); |
|
| 85 | - $options = []; |
|
| 86 | - foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 87 | - if (!empty($args[$k])) { |
|
| 88 | - $options[$option] = $args[$k]; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 81 | + // support ancienne syntaxe |
|
| 82 | + // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 83 | + if (!is_array($options)) { |
|
| 84 | + $args = func_get_args(); |
|
| 85 | + $options = []; |
|
| 86 | + foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 87 | + if (!empty($args[$k])) { |
|
| 88 | + $options[$option] = $args[$k]; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $default_options = [ |
|
| 94 | - 'head' => false, |
|
| 95 | - 'delim' => ',', |
|
| 96 | - 'enclos' => '"', |
|
| 97 | - 'len' => 10000, |
|
| 98 | - 'charset_source' => '', |
|
| 99 | - ]; |
|
| 100 | - $options = array_merge($default_options, $options); |
|
| 93 | + $default_options = [ |
|
| 94 | + 'head' => false, |
|
| 95 | + 'delim' => ',', |
|
| 96 | + 'enclos' => '"', |
|
| 97 | + 'len' => 10000, |
|
| 98 | + 'charset_source' => '', |
|
| 99 | + ]; |
|
| 100 | + $options = array_merge($default_options, $options); |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - $return = []; |
|
| 104 | - if (@file_exists($file) && ($handle = fopen($file, 'r'))) { |
|
| 105 | - if ($options['charset_source']) { |
|
| 106 | - importer_csv_importcharset('', $options['charset_source']); |
|
| 107 | - } |
|
| 108 | - if ($options['head']) { |
|
| 109 | - $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 110 | - if ($header) { |
|
| 111 | - $header = array_map('importer_csv_importcharset', $header); |
|
| 112 | - $header = array_map('importer_csv_nettoie_key', $header); |
|
| 113 | - $header_type = []; |
|
| 114 | - foreach ($header as $heading) { |
|
| 115 | - $header_type[$heading] = isset($header_type[$heading]) ? 'array' : 'scalar'; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 103 | + $return = []; |
|
| 104 | + if (@file_exists($file) && ($handle = fopen($file, 'r'))) { |
|
| 105 | + if ($options['charset_source']) { |
|
| 106 | + importer_csv_importcharset('', $options['charset_source']); |
|
| 107 | + } |
|
| 108 | + if ($options['head']) { |
|
| 109 | + $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 110 | + if ($header) { |
|
| 111 | + $header = array_map('importer_csv_importcharset', $header); |
|
| 112 | + $header = array_map('importer_csv_nettoie_key', $header); |
|
| 113 | + $header_type = []; |
|
| 114 | + foreach ($header as $heading) { |
|
| 115 | + $header_type[$heading] = isset($header_type[$heading]) ? 'array' : 'scalar'; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 121 | - $data = array_map('importer_csv_importcharset', $data); |
|
| 122 | - if ($options['head'] && isset($header)) { |
|
| 123 | - $row = []; |
|
| 124 | - foreach ($header as $key => $heading) { |
|
| 125 | - if ($header_type[$heading] == 'array') { |
|
| 126 | - if (!isset($row[$heading])) { |
|
| 127 | - $row[$heading] = []; |
|
| 128 | - } |
|
| 129 | - if (isset($data[$key]) && strlen($data[$key])) { |
|
| 130 | - $row[$heading][] = $data[$key]; |
|
| 131 | - } |
|
| 132 | - } else { |
|
| 133 | - $row[$heading] = $data[$key] ?? ''; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $return[] = $row; |
|
| 137 | - } else { |
|
| 138 | - $return[] = $data; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - if ($options['charset_source']) { |
|
| 142 | - importer_csv_importcharset('', true); |
|
| 143 | - } |
|
| 144 | - } |
|
| 120 | + while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 121 | + $data = array_map('importer_csv_importcharset', $data); |
|
| 122 | + if ($options['head'] && isset($header)) { |
|
| 123 | + $row = []; |
|
| 124 | + foreach ($header as $key => $heading) { |
|
| 125 | + if ($header_type[$heading] == 'array') { |
|
| 126 | + if (!isset($row[$heading])) { |
|
| 127 | + $row[$heading] = []; |
|
| 128 | + } |
|
| 129 | + if (isset($data[$key]) && strlen($data[$key])) { |
|
| 130 | + $row[$heading][] = $data[$key]; |
|
| 131 | + } |
|
| 132 | + } else { |
|
| 133 | + $row[$heading] = $data[$key] ?? ''; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $return[] = $row; |
|
| 137 | + } else { |
|
| 138 | + $return[] = $data; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + if ($options['charset_source']) { |
|
| 142 | + importer_csv_importcharset('', true); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - return $return ?: false; |
|
| 146 | + return $return ?: false; |
|
| 147 | 147 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/autoriser'); |
@@ -29,74 +29,74 @@ discard block |
||
| 29 | 29 | * Un tableau des sous rubriques |
| 30 | 30 | */ |
| 31 | 31 | function enfant_rub($collection, $debut = 0, $limite = 500) { |
| 32 | - $voir_logo = (isset($GLOBALS['meta']['image_process']) && $GLOBALS['meta']['image_process'] != 'non'); |
|
| 33 | - $logo = ''; |
|
| 34 | - |
|
| 35 | - if ($voir_logo) { |
|
| 36 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 37 | - include_spip('inc/filtres_images_mini'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $res = []; |
|
| 41 | - |
|
| 42 | - $result = sql_select( |
|
| 43 | - 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 44 | - 'spip_rubriques', |
|
| 45 | - 'id_parent=' . (int) $collection, |
|
| 46 | - '', |
|
| 47 | - '0+titre,titre', |
|
| 48 | - $debut == -1 ? '' : "$debut,$limite" |
|
| 49 | - ); |
|
| 50 | - while ($row = sql_fetch($result)) { |
|
| 51 | - $id_rubrique = $row['id_rubrique']; |
|
| 52 | - $id_parent = $row['id_parent']; |
|
| 53 | - // pour etre sur de passer par tous les traitements |
|
| 54 | - $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre'); |
|
| 55 | - if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 56 | - $rang = "<span class='rang'>$rang.</span> "; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 60 | - $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 61 | - |
|
| 62 | - changer_typo($row['lang']); |
|
| 63 | - $lang_dir = lang_dir($row['lang']); |
|
| 64 | - $descriptif = propre($row['descriptif']); |
|
| 65 | - |
|
| 66 | - if ($voir_logo && ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on'))) { |
|
| 67 | - [$fid, $dir, $nom, $format] = $logo; |
|
| 68 | - $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 69 | - if ($logo) { |
|
| 70 | - $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
|
| 75 | - ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique')) |
|
| 76 | - : '') . |
|
| 77 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 78 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 79 | - " href='" . |
|
| 80 | - generer_objet_url($id_rubrique, 'rubrique') . |
|
| 81 | - "'><span class='titre'>" . |
|
| 82 | - $rang . $titre |
|
| 83 | - . '</span>' |
|
| 84 | - . (is_string($logo) ? $logo : '') |
|
| 85 | - . '</a>'; |
|
| 86 | - |
|
| 87 | - $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 88 | - . ($descriptif ? "\n<div class='descriptif'>$descriptif</div>" : '') |
|
| 89 | - ; |
|
| 90 | - |
|
| 91 | - $res[] = |
|
| 92 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | - $les_sous_enfants . |
|
| 94 | - fin_cadre_sous_rub(); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 99 | - return $res; |
|
| 32 | + $voir_logo = (isset($GLOBALS['meta']['image_process']) && $GLOBALS['meta']['image_process'] != 'non'); |
|
| 33 | + $logo = ''; |
|
| 34 | + |
|
| 35 | + if ($voir_logo) { |
|
| 36 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 37 | + include_spip('inc/filtres_images_mini'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $res = []; |
|
| 41 | + |
|
| 42 | + $result = sql_select( |
|
| 43 | + 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 44 | + 'spip_rubriques', |
|
| 45 | + 'id_parent=' . (int) $collection, |
|
| 46 | + '', |
|
| 47 | + '0+titre,titre', |
|
| 48 | + $debut == -1 ? '' : "$debut,$limite" |
|
| 49 | + ); |
|
| 50 | + while ($row = sql_fetch($result)) { |
|
| 51 | + $id_rubrique = $row['id_rubrique']; |
|
| 52 | + $id_parent = $row['id_parent']; |
|
| 53 | + // pour etre sur de passer par tous les traitements |
|
| 54 | + $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre'); |
|
| 55 | + if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 56 | + $rang = "<span class='rang'>$rang.</span> "; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 60 | + $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 61 | + |
|
| 62 | + changer_typo($row['lang']); |
|
| 63 | + $lang_dir = lang_dir($row['lang']); |
|
| 64 | + $descriptif = propre($row['descriptif']); |
|
| 65 | + |
|
| 66 | + if ($voir_logo && ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on'))) { |
|
| 67 | + [$fid, $dir, $nom, $format] = $logo; |
|
| 68 | + $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 69 | + if ($logo) { |
|
| 70 | + $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
|
| 75 | + ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique')) |
|
| 76 | + : '') . |
|
| 77 | + " <a class='titremlien' dir='$lang_dir'" . |
|
| 78 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 79 | + " href='" . |
|
| 80 | + generer_objet_url($id_rubrique, 'rubrique') . |
|
| 81 | + "'><span class='titre'>" . |
|
| 82 | + $rang . $titre |
|
| 83 | + . '</span>' |
|
| 84 | + . (is_string($logo) ? $logo : '') |
|
| 85 | + . '</a>'; |
|
| 86 | + |
|
| 87 | + $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 88 | + . ($descriptif ? "\n<div class='descriptif'>$descriptif</div>" : '') |
|
| 89 | + ; |
|
| 90 | + |
|
| 91 | + $res[] = |
|
| 92 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | + $les_sous_enfants . |
|
| 94 | + fin_cadre_sous_rub(); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 99 | + return $res; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -109,71 +109,71 @@ discard block |
||
| 109 | 109 | * Le contenu du bloc dépliable |
| 110 | 110 | */ |
| 111 | 111 | function sous_enfant_rub($collection2) { |
| 112 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2); |
|
| 113 | - |
|
| 114 | - $retour = ''; |
|
| 115 | - $pagination = ''; |
|
| 116 | - $debut = 0; |
|
| 117 | - $limite = 500; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * On ne va afficher que 500 résultats max |
|
| 121 | - * Si > 500 on affiche une pagination |
|
| 122 | - */ |
|
| 123 | - if ($nb > $limite) { |
|
| 124 | - $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 125 | - $pagination = chercher_filtre('pagination'); |
|
| 126 | - $pagination = '<nav class="pagination">' . $pagination( |
|
| 127 | - $nb, |
|
| 128 | - '_rubrique' . $collection2, |
|
| 129 | - $debut, |
|
| 130 | - $limite, |
|
| 131 | - true, |
|
| 132 | - 'prive' |
|
| 133 | - ) . '</nav>'; |
|
| 134 | - $limite = $debut + $limite; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $result = sql_select( |
|
| 138 | - 'id_rubrique, id_parent, titre, lang', |
|
| 139 | - 'spip_rubriques', |
|
| 140 | - 'id_parent=' . (int) $collection2, |
|
| 141 | - '', |
|
| 142 | - '0+titre,titre', |
|
| 143 | - $debut == -1 ? '' : "$debut,$limite" |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - while ($row = sql_fetch($result)) { |
|
| 147 | - $id_rubrique2 = $row['id_rubrique']; |
|
| 148 | - $titre2 = generer_objet_info( |
|
| 149 | - $id_rubrique2, |
|
| 150 | - 'rubrique', |
|
| 151 | - 'titre' |
|
| 152 | - ); // pour etre sur de passer par tous les traitements |
|
| 153 | - if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 154 | - $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - changer_typo($row['lang']); |
|
| 158 | - $lang_dir = lang_dir($row['lang']); |
|
| 159 | - if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 160 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 161 | - $id_rubrique2, |
|
| 162 | - 'rubrique' |
|
| 163 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $retour = $pagination . $retour . $pagination; |
|
| 168 | - |
|
| 169 | - if (!$retour) { |
|
| 170 | - return ''; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return debut_block_depliable($debut > 0, "enfants$collection2") |
|
| 174 | - . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 175 | - . $retour |
|
| 176 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 112 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2); |
|
| 113 | + |
|
| 114 | + $retour = ''; |
|
| 115 | + $pagination = ''; |
|
| 116 | + $debut = 0; |
|
| 117 | + $limite = 500; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * On ne va afficher que 500 résultats max |
|
| 121 | + * Si > 500 on affiche une pagination |
|
| 122 | + */ |
|
| 123 | + if ($nb > $limite) { |
|
| 124 | + $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 125 | + $pagination = chercher_filtre('pagination'); |
|
| 126 | + $pagination = '<nav class="pagination">' . $pagination( |
|
| 127 | + $nb, |
|
| 128 | + '_rubrique' . $collection2, |
|
| 129 | + $debut, |
|
| 130 | + $limite, |
|
| 131 | + true, |
|
| 132 | + 'prive' |
|
| 133 | + ) . '</nav>'; |
|
| 134 | + $limite = $debut + $limite; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $result = sql_select( |
|
| 138 | + 'id_rubrique, id_parent, titre, lang', |
|
| 139 | + 'spip_rubriques', |
|
| 140 | + 'id_parent=' . (int) $collection2, |
|
| 141 | + '', |
|
| 142 | + '0+titre,titre', |
|
| 143 | + $debut == -1 ? '' : "$debut,$limite" |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + while ($row = sql_fetch($result)) { |
|
| 147 | + $id_rubrique2 = $row['id_rubrique']; |
|
| 148 | + $titre2 = generer_objet_info( |
|
| 149 | + $id_rubrique2, |
|
| 150 | + 'rubrique', |
|
| 151 | + 'titre' |
|
| 152 | + ); // pour etre sur de passer par tous les traitements |
|
| 153 | + if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 154 | + $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + changer_typo($row['lang']); |
|
| 158 | + $lang_dir = lang_dir($row['lang']); |
|
| 159 | + if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 160 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 161 | + $id_rubrique2, |
|
| 162 | + 'rubrique' |
|
| 163 | + ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $retour = $pagination . $retour . $pagination; |
|
| 168 | + |
|
| 169 | + if (!$retour) { |
|
| 170 | + return ''; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return debut_block_depliable($debut > 0, "enfants$collection2") |
|
| 174 | + . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 175 | + . $retour |
|
| 176 | + . "</ul>\n" . fin_block() . "\n\n"; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -188,41 +188,41 @@ discard block |
||
| 188 | 188 | * Le contenu textuel affiché, la liste des sous rubriques |
| 189 | 189 | */ |
| 190 | 190 | function afficher_enfant_rub($id_rubrique = 0) { |
| 191 | - $pagination = ''; |
|
| 192 | - $debut = 0; |
|
| 193 | - $limite = 500; |
|
| 194 | - |
|
| 195 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 196 | - |
|
| 197 | - if ($nb > $limite) { |
|
| 198 | - $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 199 | - $pagination = chercher_filtre('pagination'); |
|
| 200 | - $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 202 | - '</nav>'; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 206 | - |
|
| 207 | - if (!$n = count($les_enfants)) { |
|
| 208 | - return ''; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if ($n == 1) { |
|
| 212 | - $les_enfants = reset($les_enfants); |
|
| 213 | - $les_enfants2 = ''; |
|
| 214 | - } else { |
|
| 215 | - $n = ceil($n / 2); |
|
| 216 | - $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 217 | - $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $pagination |
|
| 221 | - . "<div class='gauche'>" |
|
| 222 | - . $les_enfants |
|
| 223 | - . '</div>' |
|
| 224 | - . "<div class='droite'>" |
|
| 225 | - . $les_enfants2 |
|
| 226 | - . '</div>' |
|
| 227 | - . $pagination; |
|
| 191 | + $pagination = ''; |
|
| 192 | + $debut = 0; |
|
| 193 | + $limite = 500; |
|
| 194 | + |
|
| 195 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 196 | + |
|
| 197 | + if ($nb > $limite) { |
|
| 198 | + $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 199 | + $pagination = chercher_filtre('pagination'); |
|
| 200 | + $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | + $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 202 | + '</nav>'; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 206 | + |
|
| 207 | + if (!$n = count($les_enfants)) { |
|
| 208 | + return ''; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if ($n == 1) { |
|
| 212 | + $les_enfants = reset($les_enfants); |
|
| 213 | + $les_enfants2 = ''; |
|
| 214 | + } else { |
|
| 215 | + $n = ceil($n / 2); |
|
| 216 | + $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 217 | + $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $pagination |
|
| 221 | + . "<div class='gauche'>" |
|
| 222 | + . $les_enfants |
|
| 223 | + . '</div>' |
|
| 224 | + . "<div class='droite'>" |
|
| 225 | + . $les_enfants2 |
|
| 226 | + . '</div>' |
|
| 227 | + . $pagination; |
|
| 228 | 228 | } |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rechercher'); |
| 23 | 23 | if (!defined('_DELAI_CACHE_resultats')) { |
| 24 | - define('_DELAI_CACHE_resultats', 600); |
|
| 24 | + define('_DELAI_CACHE_resultats', 600); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -48,126 +48,126 @@ discard block |
||
| 48 | 48 | * @return array |
| 49 | 49 | */ |
| 50 | 50 | function inc_prepare_recherche_dist( |
| 51 | - $recherche, |
|
| 52 | - $table = 'articles', |
|
| 53 | - $cond = false, |
|
| 54 | - $serveur = '', |
|
| 55 | - $modificateurs = [], |
|
| 56 | - $primary = '' |
|
| 51 | + $recherche, |
|
| 52 | + $table = 'articles', |
|
| 53 | + $cond = false, |
|
| 54 | + $serveur = '', |
|
| 55 | + $modificateurs = [], |
|
| 56 | + $primary = '' |
|
| 57 | 57 | ) { |
| 58 | - $where = null; |
|
| 59 | - $rows = null; |
|
| 60 | - static $cache = []; |
|
| 61 | - $delai_fraicheur = min( |
|
| 62 | - \_DELAI_CACHE_resultats, |
|
| 63 | - time() - ($GLOBALS['meta']['derniere_modif'] ?? 0) |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 67 | - // ca permet de faire des inclure simple. |
|
| 68 | - if (!isset($recherche) && isset($GLOBALS['recherche'])) { |
|
| 69 | - $recherche = $GLOBALS['recherche']; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // traiter le cas {recherche?} |
|
| 73 | - if ($cond && !strlen($recherche)) { |
|
| 74 | - return [ |
|
| 75 | - '0 as points' /* as points */, /* where */ |
|
| 76 | - '' |
|
| 77 | - ]; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - $rechercher = false; |
|
| 82 | - |
|
| 83 | - $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 84 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 85 | - $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 86 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 87 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 88 | - $row = sql_fetsel( |
|
| 89 | - 'recherche', |
|
| 90 | - 'spip_resultats AS resultats', |
|
| 91 | - $where . " AND $where_resultat_recent", |
|
| 92 | - '', |
|
| 93 | - '', |
|
| 94 | - '0,1' |
|
| 95 | - ); |
|
| 96 | - if (!$row || (defined('_VAR_MODE') && _VAR_MODE == 'recalcul')) { |
|
| 97 | - $rechercher = true; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 102 | - if ($rechercher) { |
|
| 103 | - //$tables = liste_des_champs(); |
|
| 104 | - $x = objet_type($table); |
|
| 105 | - $points = recherche_en_base( |
|
| 106 | - $recherche, |
|
| 107 | - $x, |
|
| 108 | - [ |
|
| 109 | - 'score' => true, |
|
| 110 | - 'toutvoir' => true, |
|
| 111 | - 'jointures' => true |
|
| 112 | - ], |
|
| 113 | - $serveur |
|
| 114 | - ); |
|
| 115 | - // pas de résultat, pas de point |
|
| 116 | - $points = $points[$x] ?? []; |
|
| 117 | - |
|
| 118 | - // permettre aux plugins de modifier le resultat |
|
| 119 | - $points = pipeline('prepare_recherche', [ |
|
| 120 | - 'args' => [ |
|
| 121 | - 'type' => $x, |
|
| 122 | - 'recherche' => $recherche, |
|
| 123 | - 'serveur' => $serveur, |
|
| 124 | - 'modificateurs' => $modificateurs |
|
| 125 | - ], |
|
| 126 | - 'data' => $points |
|
| 127 | - ]); |
|
| 128 | - |
|
| 129 | - // supprimer les anciens resultats de cette recherche |
|
| 130 | - // et les resultats trop vieux avec une marge |
|
| 131 | - // pas de AS resultats dans un delete (mysql) |
|
| 132 | - $whered = str_replace( |
|
| 133 | - ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 134 | - ['recherche', 'table_objet', 'serveur'], |
|
| 135 | - $where |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - sql_delete( |
|
| 139 | - 'spip_resultats', |
|
| 140 | - "NOT($where_resultat_recent) OR ($whered)" |
|
| 141 | - ); |
|
| 142 | - |
|
| 143 | - // inserer les resultats dans la table de cache des resultats |
|
| 144 | - if (is_countable($points) ? count($points) : 0) { |
|
| 145 | - $tab_couples = []; |
|
| 146 | - foreach ($points as $id => $p) { |
|
| 147 | - $tab_couples[] = [ |
|
| 148 | - 'recherche' => $hash, |
|
| 149 | - 'id' => $id, |
|
| 150 | - 'points' => $p['score'], |
|
| 151 | - 'table_objet' => $table, |
|
| 152 | - 'serveur' => $hash_serv, |
|
| 153 | - ]; |
|
| 154 | - } |
|
| 155 | - sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 160 | - if (!$serveur) { |
|
| 161 | - $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 162 | - } else { |
|
| 163 | - if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 164 | - $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 165 | - } |
|
| 166 | - $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - return $cache[$serveur][$table][$recherche]; |
|
| 58 | + $where = null; |
|
| 59 | + $rows = null; |
|
| 60 | + static $cache = []; |
|
| 61 | + $delai_fraicheur = min( |
|
| 62 | + \_DELAI_CACHE_resultats, |
|
| 63 | + time() - ($GLOBALS['meta']['derniere_modif'] ?? 0) |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 67 | + // ca permet de faire des inclure simple. |
|
| 68 | + if (!isset($recherche) && isset($GLOBALS['recherche'])) { |
|
| 69 | + $recherche = $GLOBALS['recherche']; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // traiter le cas {recherche?} |
|
| 73 | + if ($cond && !strlen($recherche)) { |
|
| 74 | + return [ |
|
| 75 | + '0 as points' /* as points */, /* where */ |
|
| 76 | + '' |
|
| 77 | + ]; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + $rechercher = false; |
|
| 82 | + |
|
| 83 | + $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 84 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 85 | + $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 86 | + $hash = substr(md5($recherche . $table), 0, 16); |
|
| 87 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 88 | + $row = sql_fetsel( |
|
| 89 | + 'recherche', |
|
| 90 | + 'spip_resultats AS resultats', |
|
| 91 | + $where . " AND $where_resultat_recent", |
|
| 92 | + '', |
|
| 93 | + '', |
|
| 94 | + '0,1' |
|
| 95 | + ); |
|
| 96 | + if (!$row || (defined('_VAR_MODE') && _VAR_MODE == 'recalcul')) { |
|
| 97 | + $rechercher = true; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 102 | + if ($rechercher) { |
|
| 103 | + //$tables = liste_des_champs(); |
|
| 104 | + $x = objet_type($table); |
|
| 105 | + $points = recherche_en_base( |
|
| 106 | + $recherche, |
|
| 107 | + $x, |
|
| 108 | + [ |
|
| 109 | + 'score' => true, |
|
| 110 | + 'toutvoir' => true, |
|
| 111 | + 'jointures' => true |
|
| 112 | + ], |
|
| 113 | + $serveur |
|
| 114 | + ); |
|
| 115 | + // pas de résultat, pas de point |
|
| 116 | + $points = $points[$x] ?? []; |
|
| 117 | + |
|
| 118 | + // permettre aux plugins de modifier le resultat |
|
| 119 | + $points = pipeline('prepare_recherche', [ |
|
| 120 | + 'args' => [ |
|
| 121 | + 'type' => $x, |
|
| 122 | + 'recherche' => $recherche, |
|
| 123 | + 'serveur' => $serveur, |
|
| 124 | + 'modificateurs' => $modificateurs |
|
| 125 | + ], |
|
| 126 | + 'data' => $points |
|
| 127 | + ]); |
|
| 128 | + |
|
| 129 | + // supprimer les anciens resultats de cette recherche |
|
| 130 | + // et les resultats trop vieux avec une marge |
|
| 131 | + // pas de AS resultats dans un delete (mysql) |
|
| 132 | + $whered = str_replace( |
|
| 133 | + ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 134 | + ['recherche', 'table_objet', 'serveur'], |
|
| 135 | + $where |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + sql_delete( |
|
| 139 | + 'spip_resultats', |
|
| 140 | + "NOT($where_resultat_recent) OR ($whered)" |
|
| 141 | + ); |
|
| 142 | + |
|
| 143 | + // inserer les resultats dans la table de cache des resultats |
|
| 144 | + if (is_countable($points) ? count($points) : 0) { |
|
| 145 | + $tab_couples = []; |
|
| 146 | + foreach ($points as $id => $p) { |
|
| 147 | + $tab_couples[] = [ |
|
| 148 | + 'recherche' => $hash, |
|
| 149 | + 'id' => $id, |
|
| 150 | + 'points' => $p['score'], |
|
| 151 | + 'table_objet' => $table, |
|
| 152 | + 'serveur' => $hash_serv, |
|
| 153 | + ]; |
|
| 154 | + } |
|
| 155 | + sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 160 | + if (!$serveur) { |
|
| 161 | + $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 162 | + } else { |
|
| 163 | + if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 164 | + $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 165 | + } |
|
| 166 | + $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + return $cache[$serveur][$table][$recherche]; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -183,22 +183,22 @@ discard block |
||
| 183 | 183 | * @return array |
| 184 | 184 | */ |
| 185 | 185 | function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
| 186 | - # calculer le {id_article IN()} et le {... as points} |
|
| 187 | - if ($rows === []) { |
|
| 188 | - return ["''", '0=1']; |
|
| 189 | - } else { |
|
| 190 | - $listes_ids = []; |
|
| 191 | - $select = '0'; |
|
| 192 | - foreach ($rows as $r) { |
|
| 193 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - foreach ($listes_ids as $p => $ids) { |
|
| 197 | - $select .= "+$p*(" . |
|
| 198 | - sql_in("$table.$primary", $ids, '', $serveur) |
|
| 199 | - . ') '; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 203 | - } |
|
| 186 | + # calculer le {id_article IN()} et le {... as points} |
|
| 187 | + if ($rows === []) { |
|
| 188 | + return ["''", '0=1']; |
|
| 189 | + } else { |
|
| 190 | + $listes_ids = []; |
|
| 191 | + $select = '0'; |
|
| 192 | + foreach ($rows as $r) { |
|
| 193 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + foreach ($listes_ids as $p => $ids) { |
|
| 197 | + $select .= "+$p*(" . |
|
| 198 | + sql_in("$table.$primary", $ids, '', $serveur) |
|
| 199 | + . ') '; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 203 | + } |
|
| 204 | 204 | } |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | if (!defined('_AUTO_SELECTION_RUBRIQUE')) { |
| 16 | - define('_AUTO_SELECTION_RUBRIQUE', false); |
|
| 16 | + define('_AUTO_SELECTION_RUBRIQUE', false); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
@@ -27,39 +27,39 @@ discard block |
||
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | 29 | function inc_preselectionner_parent_nouvel_objet_dist($objet, $row) { |
| 30 | - if (!_AUTO_SELECTION_RUBRIQUE) { |
|
| 31 | - return ''; |
|
| 32 | - } |
|
| 30 | + if (!_AUTO_SELECTION_RUBRIQUE) { |
|
| 31 | + return ''; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - if (!isset($row['id_rubrique'])) { |
|
| 35 | - return ''; |
|
| 36 | - } |
|
| 34 | + if (!isset($row['id_rubrique'])) { |
|
| 35 | + return ''; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $id_rubrique = ''; |
|
| 39 | - if ($GLOBALS['connect_id_rubrique']) { |
|
| 40 | - // si admin restreint : sa rubrique |
|
| 41 | - $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
|
| 42 | - } elseif ( |
|
| 43 | - is_int(_AUTO_SELECTION_RUBRIQUE) |
|
| 44 | - && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | - ) { |
|
| 46 | - $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
|
| 47 | - } else { |
|
| 48 | - // sinon la derniere rubrique cree |
|
| 49 | - $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1'); |
|
| 50 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 51 | - } |
|
| 52 | - // si le choix ne convient pas, on cherche dans un secteur |
|
| 53 | - if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | - $id_rubrique = ''; |
|
| 55 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 56 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 57 | - while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
|
| 58 | - if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 38 | + $id_rubrique = ''; |
|
| 39 | + if ($GLOBALS['connect_id_rubrique']) { |
|
| 40 | + // si admin restreint : sa rubrique |
|
| 41 | + $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
|
| 42 | + } elseif ( |
|
| 43 | + is_int(_AUTO_SELECTION_RUBRIQUE) |
|
| 44 | + && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | + ) { |
|
| 46 | + $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
|
| 47 | + } else { |
|
| 48 | + // sinon la derniere rubrique cree |
|
| 49 | + $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1'); |
|
| 50 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 51 | + } |
|
| 52 | + // si le choix ne convient pas, on cherche dans un secteur |
|
| 53 | + if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | + $id_rubrique = ''; |
|
| 55 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 56 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 57 | + while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
|
| 58 | + if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $id_rubrique; |
|
| 64 | + return $id_rubrique; |
|
| 65 | 65 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | include_spip('inc/acces'); |
@@ -101,93 +101,93 @@ discard block |
||
| 101 | 101 | * @return int|bool Timestamp du verrou, false si erreur |
| 102 | 102 | */ |
| 103 | 103 | function spip_nfslock($fichier, $max_age = 0) { |
| 104 | - $tries = 0; |
|
| 104 | + $tries = 0; |
|
| 105 | 105 | |
| 106 | - if (!$max_age) { |
|
| 107 | - $max_age = _DEFAULT_LOCKTIME; |
|
| 108 | - } |
|
| 109 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 106 | + if (!$max_age) { |
|
| 107 | + $max_age = _DEFAULT_LOCKTIME; |
|
| 108 | + } |
|
| 109 | + $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - /* |
|
| 112 | + /* |
|
| 113 | 113 | * 1. create a tmp file with a psuedo random file name. we also make |
| 114 | 114 | * tpath which is a buffer to store the full pathname of the tmp file. |
| 115 | 115 | */ |
| 116 | 116 | |
| 117 | - $id = creer_uniqid(); |
|
| 118 | - $tpath = _DIR_TMP . "slock.$id"; |
|
| 119 | - $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 120 | - if (!$tmpfd) { /* open failed */ |
|
| 121 | - @fclose($tmpfd); |
|
| 122 | - spip_unlink($tpath); |
|
| 117 | + $id = creer_uniqid(); |
|
| 118 | + $tpath = _DIR_TMP . "slock.$id"; |
|
| 119 | + $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 120 | + if (!$tmpfd) { /* open failed */ |
|
| 121 | + @fclose($tmpfd); |
|
| 122 | + spip_unlink($tpath); |
|
| 123 | 123 | |
| 124 | - return false; //NFSL_SYSF |
|
| 125 | - } |
|
| 124 | + return false; //NFSL_SYSF |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /* |
|
| 127 | + /* |
|
| 128 | 128 | * 2. make fullpath, a buffer for the full pathname of the lock file. |
| 129 | 129 | * then start looping trying to lock it |
| 130 | 130 | */ |
| 131 | 131 | |
| 132 | - while ($tries < 10) { |
|
| 133 | - /* |
|
| 132 | + while ($tries < 10) { |
|
| 133 | + /* |
|
| 134 | 134 | * 3. link tmp file to lock file. if it goes, we win and we clean |
| 135 | 135 | * up and return the st_ctime of the lock file. |
| 136 | 136 | */ |
| 137 | 137 | |
| 138 | - if (link($tpath, $lock_file) == 1) { |
|
| 139 | - spip_unlink($tpath); /* got it! */ |
|
| 140 | - @fclose($tmpfd); |
|
| 141 | - if (($our_tmp = lstat($lock_file)) == false) { /* stat failed... shouldn't happen */ |
|
| 142 | - spip_unlink($lock_file); |
|
| 138 | + if (link($tpath, $lock_file) == 1) { |
|
| 139 | + spip_unlink($tpath); /* got it! */ |
|
| 140 | + @fclose($tmpfd); |
|
| 141 | + if (($our_tmp = lstat($lock_file)) == false) { /* stat failed... shouldn't happen */ |
|
| 142 | + spip_unlink($lock_file); |
|
| 143 | 143 | |
| 144 | - return false; // (NFSL_SYSF); |
|
| 145 | - } |
|
| 144 | + return false; // (NFSL_SYSF); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return ($our_tmp['ctime']); |
|
| 148 | - } |
|
| 147 | + return ($our_tmp['ctime']); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /* |
|
| 150 | + /* |
|
| 151 | 151 | * 4. the lock failed. check for a stale lock file, being mindful |
| 152 | 152 | * of NFS and the fact the time is set from the NFS server. we |
| 153 | 153 | * do a write on the tmp file to update its time to the server's |
| 154 | 154 | * idea of "now." |
| 155 | 155 | */ |
| 156 | 156 | |
| 157 | - $old_stat = lstat($lock_file); |
|
| 158 | - if (@fwrite($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) { |
|
| 159 | - break; |
|
| 160 | - } /* something bogus is going on */ |
|
| 157 | + $old_stat = lstat($lock_file); |
|
| 158 | + if (@fwrite($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) { |
|
| 159 | + break; |
|
| 160 | + } /* something bogus is going on */ |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | - if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 164 | - spip_unlink($lock_file); /* break the stale lock */ |
|
| 165 | - $tries++; |
|
| 166 | - /* It is CRITICAL that we sleep after breaking |
|
| 163 | + if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 164 | + spip_unlink($lock_file); /* break the stale lock */ |
|
| 165 | + $tries++; |
|
| 166 | + /* It is CRITICAL that we sleep after breaking |
|
| 167 | 167 | * the lock. Otherwise, we could race with |
| 168 | 168 | * another process and unlink it's newly- |
| 169 | 169 | * created file. |
| 170 | 170 | */ |
| 171 | - sleep(1 + random_int(0, 4)); |
|
| 172 | - continue; |
|
| 173 | - } |
|
| 171 | + sleep(1 + random_int(0, 4)); |
|
| 172 | + continue; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /* |
|
| 175 | + /* |
|
| 176 | 176 | * 5. try again |
| 177 | 177 | */ |
| 178 | 178 | |
| 179 | - $tries++; |
|
| 180 | - sleep(1 + random_int(0, 4)); |
|
| 181 | - } |
|
| 179 | + $tries++; |
|
| 180 | + sleep(1 + random_int(0, 4)); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /* |
|
| 183 | + /* |
|
| 184 | 184 | * 6. give up, failure. |
| 185 | 185 | */ |
| 186 | 186 | |
| 187 | - spip_unlink($tpath); |
|
| 188 | - @fclose($tmpfd); |
|
| 187 | + spip_unlink($tpath); |
|
| 188 | + @fclose($tmpfd); |
|
| 189 | 189 | |
| 190 | - return false; //(NFSL_LOCKED); |
|
| 190 | + return false; //(NFSL_LOCKED); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -231,71 +231,71 @@ discard block |
||
| 231 | 231 | * return bool true si déverrouillé, false sinon |
| 232 | 232 | */ |
| 233 | 233 | function spip_nfsunlock($fichier, $birth, $max_age = 0, $test = false) { |
| 234 | - $id = creer_uniqid(); |
|
| 235 | - if (!$max_age) { |
|
| 236 | - $max_age = _DEFAULT_LOCKTIME; |
|
| 237 | - } |
|
| 234 | + $id = creer_uniqid(); |
|
| 235 | + if (!$max_age) { |
|
| 236 | + $max_age = _DEFAULT_LOCKTIME; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /* |
|
| 239 | + /* |
|
| 240 | 240 | * 1. Build a temp file and stat that to get an idea of what the server |
| 241 | 241 | * thinks the current time is (our_tmp.st_ctime).. |
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | - $tpath = _DIR_TMP . "stime.$id"; |
|
| 245 | - $tmpfd = @fopen($tpath, 'w'); |
|
| 246 | - if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
|
| 247 | - /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 248 | - @fclose($tmpfd); |
|
| 249 | - spip_unlink($tpath); |
|
| 244 | + $tpath = _DIR_TMP . "stime.$id"; |
|
| 245 | + $tmpfd = @fopen($tpath, 'w'); |
|
| 246 | + if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
|
| 247 | + /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 248 | + @fclose($tmpfd); |
|
| 249 | + spip_unlink($tpath); |
|
| 250 | 250 | |
| 251 | - return false; //(NFSL_SYSF); |
|
| 252 | - } |
|
| 251 | + return false; //(NFSL_SYSF); |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | - spip_unlink($tpath); |
|
| 254 | + @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | + spip_unlink($tpath); |
|
| 256 | 256 | |
| 257 | - /* |
|
| 257 | + /* |
|
| 258 | 258 | * 2. make fullpath, a buffer for the full pathname of the lock file |
| 259 | 259 | */ |
| 260 | 260 | |
| 261 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 261 | + $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 262 | 262 | |
| 263 | - /* |
|
| 263 | + /* |
|
| 264 | 264 | * 3. If the ctime hasn't been modified, unlink the file and return. If the |
| 265 | 265 | * lock has expired, sleep the usual random interval before returning. |
| 266 | 266 | * If we didn't sleep, there could be a race if the caller immediately |
| 267 | 267 | * tries to relock the file. |
| 268 | 268 | */ |
| 269 | 269 | |
| 270 | - if ( |
|
| 271 | - ($old_stat = @lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 272 | - && ($old_stat['ctime'] == $birth) |
|
| 273 | - ) { /* hasn't been modified since birth */ |
|
| 274 | - if (!$test) { |
|
| 275 | - spip_unlink($lock_file); |
|
| 276 | - } /* so the lock is ours to remove */ |
|
| 277 | - if ($our_tmp['ctime'] >= $birth + $max_age) { /* the lock has expired */ |
|
| 278 | - if (!$test) { |
|
| 279 | - return false; |
|
| 280 | - } //(NFSL_LOST); |
|
| 281 | - sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return true;//(NFSL_OK); /* success */ |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /* |
|
| 270 | + if ( |
|
| 271 | + ($old_stat = @lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 272 | + && ($old_stat['ctime'] == $birth) |
|
| 273 | + ) { /* hasn't been modified since birth */ |
|
| 274 | + if (!$test) { |
|
| 275 | + spip_unlink($lock_file); |
|
| 276 | + } /* so the lock is ours to remove */ |
|
| 277 | + if ($our_tmp['ctime'] >= $birth + $max_age) { /* the lock has expired */ |
|
| 278 | + if (!$test) { |
|
| 279 | + return false; |
|
| 280 | + } //(NFSL_LOST); |
|
| 281 | + sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return true;//(NFSL_OK); /* success */ |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /* |
|
| 288 | 288 | * 4. Either ctime has been modified, or the entire lock file is missing. |
| 289 | 289 | * If the lock should still be ours, based on the ctime of the temp |
| 290 | 290 | * file, return with NFSL_STOLEN. If not, then our lock is expired and |
| 291 | 291 | * someone else has grabbed the file, so return NFSL_LOST. |
| 292 | 292 | */ |
| 293 | 293 | |
| 294 | - if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */ |
|
| 295 | - return false; |
|
| 296 | - } //(NFSL_STOLEN); |
|
| 294 | + if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */ |
|
| 295 | + return false; |
|
| 296 | + } //(NFSL_STOLEN); |
|
| 297 | 297 | |
| 298 | - return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 298 | + return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -319,5 +319,5 @@ discard block |
||
| 319 | 319 | * return bool true si déverrouillé, false sinon |
| 320 | 320 | */ |
| 321 | 321 | function spip_nfslock_test($fichier, $birth, $max_age = 0) { |
| 322 | - return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 322 | + return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 323 | 323 | } |
@@ -17,18 +17,18 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ACTIVER_PUCE_RAPIDE')) { |
| 24 | - /** |
|
| 25 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 26 | - * |
|
| 27 | - * Peut ralentir un site sur des listes très longues. |
|
| 28 | - * |
|
| 29 | - * @var bool |
|
| 30 | - **/ |
|
| 31 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 24 | + /** |
|
| 25 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 26 | + * |
|
| 27 | + * Peut ralentir un site sur des listes très longues. |
|
| 28 | + * |
|
| 29 | + * @var bool |
|
| 30 | + **/ |
|
| 31 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -56,31 +56,31 @@ discard block |
||
| 56 | 56 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 57 | 57 | */ |
| 58 | 58 | function inc_puce_statut_dist( |
| 59 | - $id_objet, |
|
| 60 | - $statut, |
|
| 61 | - $id_parent, |
|
| 62 | - $type, |
|
| 63 | - $ajax = false, |
|
| 64 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 59 | + $id_objet, |
|
| 60 | + $statut, |
|
| 61 | + $id_parent, |
|
| 62 | + $type, |
|
| 63 | + $ajax = false, |
|
| 64 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 65 | 65 | ) { |
| 66 | - static $f_puce_statut = []; |
|
| 67 | - $type = objet_type($type); |
|
| 68 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 69 | - if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) { |
|
| 70 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 71 | - } |
|
| 72 | - if ($f_puce_statut[$type]) { |
|
| 73 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 77 | - // composer une puce, avec si possible changement rapide |
|
| 78 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 79 | - return $puce; |
|
| 80 | - } // sinon fausse puce avec le type de l'image |
|
| 81 | - else { |
|
| 82 | - return http_img_pack("$type-16.png", ''); |
|
| 83 | - } |
|
| 66 | + static $f_puce_statut = []; |
|
| 67 | + $type = objet_type($type); |
|
| 68 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 69 | + if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) { |
|
| 70 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 71 | + } |
|
| 72 | + if ($f_puce_statut[$type]) { |
|
| 73 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 77 | + // composer une puce, avec si possible changement rapide |
|
| 78 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 79 | + return $puce; |
|
| 80 | + } // sinon fausse puce avec le type de l'image |
|
| 81 | + else { |
|
| 82 | + return http_img_pack("$type-16.png", ''); |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -109,41 +109,41 @@ discard block |
||
| 109 | 109 | * null si pas capable de déterminer l'image |
| 110 | 110 | */ |
| 111 | 111 | function statut_image($objet, $statut) { |
| 112 | - $src = null; |
|
| 113 | - $table = table_objet_sql($objet); |
|
| 114 | - $desc = lister_tables_objets_sql($table); |
|
| 115 | - if (isset($desc['statut_images'])) { |
|
| 116 | - // si une declaration statut_images |
|
| 117 | - // mais rien pour le statut demande, ne rien afficher |
|
| 118 | - $src = ''; |
|
| 119 | - if (isset($desc['statut_images'][$statut])) { |
|
| 120 | - $src = $desc['statut_images'][$statut]; |
|
| 121 | - } // sinon image par defaut ? |
|
| 122 | - elseif (isset($desc['statut_images'][0])) { |
|
| 123 | - $src = $desc['statut_images'][0]; |
|
| 124 | - } |
|
| 125 | - } else { |
|
| 126 | - switch ($statut) { |
|
| 127 | - case 'prepa': |
|
| 128 | - $src = 'puce-preparer-xx.svg?12px'; |
|
| 129 | - break; |
|
| 130 | - case 'prop': |
|
| 131 | - $src = 'puce-proposer-xx.svg?12px'; |
|
| 132 | - break; |
|
| 133 | - case 'publie': |
|
| 134 | - $src = 'puce-publier-xx.svg?12px'; |
|
| 135 | - break; |
|
| 136 | - case 'refuse': |
|
| 137 | - $src = 'puce-refuser-xx.svg?12px'; |
|
| 138 | - break; |
|
| 139 | - case 'poubelle': |
|
| 140 | - case 'poub': |
|
| 141 | - $src = 'puce-supprimer-xx.svg?12px'; |
|
| 142 | - break; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $src; |
|
| 112 | + $src = null; |
|
| 113 | + $table = table_objet_sql($objet); |
|
| 114 | + $desc = lister_tables_objets_sql($table); |
|
| 115 | + if (isset($desc['statut_images'])) { |
|
| 116 | + // si une declaration statut_images |
|
| 117 | + // mais rien pour le statut demande, ne rien afficher |
|
| 118 | + $src = ''; |
|
| 119 | + if (isset($desc['statut_images'][$statut])) { |
|
| 120 | + $src = $desc['statut_images'][$statut]; |
|
| 121 | + } // sinon image par defaut ? |
|
| 122 | + elseif (isset($desc['statut_images'][0])) { |
|
| 123 | + $src = $desc['statut_images'][0]; |
|
| 124 | + } |
|
| 125 | + } else { |
|
| 126 | + switch ($statut) { |
|
| 127 | + case 'prepa': |
|
| 128 | + $src = 'puce-preparer-xx.svg?12px'; |
|
| 129 | + break; |
|
| 130 | + case 'prop': |
|
| 131 | + $src = 'puce-proposer-xx.svg?12px'; |
|
| 132 | + break; |
|
| 133 | + case 'publie': |
|
| 134 | + $src = 'puce-publier-xx.svg?12px'; |
|
| 135 | + break; |
|
| 136 | + case 'refuse': |
|
| 137 | + $src = 'puce-refuser-xx.svg?12px'; |
|
| 138 | + break; |
|
| 139 | + case 'poubelle': |
|
| 140 | + case 'poub': |
|
| 141 | + $src = 'puce-supprimer-xx.svg?12px'; |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $src; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -171,40 +171,40 @@ discard block |
||
| 171 | 171 | * @return string |
| 172 | 172 | */ |
| 173 | 173 | function statut_titre($objet, $statut) { |
| 174 | - $titre = ''; |
|
| 175 | - $table = table_objet_sql($objet); |
|
| 176 | - $desc = lister_tables_objets_sql($table); |
|
| 177 | - if (isset($desc['statut_titres'])) { |
|
| 178 | - // si une declaration statut_titres |
|
| 179 | - // mais rien pour le statut demande, ne rien afficher |
|
| 180 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 181 | - $titre = $desc['statut_titres'][$statut]; |
|
| 182 | - } // sinon image par defaut ? |
|
| 183 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 184 | - $titre = $desc['statut_titres'][0]; |
|
| 185 | - } |
|
| 186 | - } else { |
|
| 187 | - switch ($statut) { |
|
| 188 | - case 'prepa': |
|
| 189 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 190 | - break; |
|
| 191 | - case 'prop': |
|
| 192 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 193 | - break; |
|
| 194 | - case 'publie': |
|
| 195 | - $titre = 'texte_statut_publie'; |
|
| 196 | - break; |
|
| 197 | - case 'refuse': |
|
| 198 | - $titre = 'texte_statut_refuse'; |
|
| 199 | - break; |
|
| 200 | - case 'poubelle': |
|
| 201 | - case 'poub': |
|
| 202 | - $titre = 'texte_statut_poubelle'; |
|
| 203 | - break; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $titre ? _T($titre) : ''; |
|
| 174 | + $titre = ''; |
|
| 175 | + $table = table_objet_sql($objet); |
|
| 176 | + $desc = lister_tables_objets_sql($table); |
|
| 177 | + if (isset($desc['statut_titres'])) { |
|
| 178 | + // si une declaration statut_titres |
|
| 179 | + // mais rien pour le statut demande, ne rien afficher |
|
| 180 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 181 | + $titre = $desc['statut_titres'][$statut]; |
|
| 182 | + } // sinon image par defaut ? |
|
| 183 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 184 | + $titre = $desc['statut_titres'][0]; |
|
| 185 | + } |
|
| 186 | + } else { |
|
| 187 | + switch ($statut) { |
|
| 188 | + case 'prepa': |
|
| 189 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 190 | + break; |
|
| 191 | + case 'prop': |
|
| 192 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 193 | + break; |
|
| 194 | + case 'publie': |
|
| 195 | + $titre = 'texte_statut_publie'; |
|
| 196 | + break; |
|
| 197 | + case 'refuse': |
|
| 198 | + $titre = 'texte_statut_refuse'; |
|
| 199 | + break; |
|
| 200 | + case 'poubelle': |
|
| 201 | + case 'poub': |
|
| 202 | + $titre = 'texte_statut_poubelle'; |
|
| 203 | + break; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $titre ? _T($titre) : ''; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -224,37 +224,37 @@ discard block |
||
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | 226 | function statut_texte_instituer($objet, $statut) { |
| 227 | - $texte = ''; |
|
| 228 | - $table = table_objet_sql($objet); |
|
| 229 | - $desc = lister_tables_objets_sql($table); |
|
| 230 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 231 | - // si une declaration statut_titres |
|
| 232 | - // mais rien pour le statut demande, ne rien afficher |
|
| 233 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 234 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 235 | - } |
|
| 236 | - } else { |
|
| 237 | - switch ($statut) { |
|
| 238 | - case 'prepa': |
|
| 239 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 240 | - break; |
|
| 241 | - case 'prop': |
|
| 242 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 243 | - break; |
|
| 244 | - case 'publie': |
|
| 245 | - $texte = 'texte_statut_publie'; |
|
| 246 | - break; |
|
| 247 | - case 'refuse': |
|
| 248 | - $texte = 'texte_statut_refuse'; |
|
| 249 | - break; |
|
| 250 | - case 'poubelle': |
|
| 251 | - case 'poub': |
|
| 252 | - $texte = 'texte_statut_poubelle'; |
|
| 253 | - break; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $texte ? _T($texte) : ''; |
|
| 227 | + $texte = ''; |
|
| 228 | + $table = table_objet_sql($objet); |
|
| 229 | + $desc = lister_tables_objets_sql($table); |
|
| 230 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 231 | + // si une declaration statut_titres |
|
| 232 | + // mais rien pour le statut demande, ne rien afficher |
|
| 233 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 234 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 235 | + } |
|
| 236 | + } else { |
|
| 237 | + switch ($statut) { |
|
| 238 | + case 'prepa': |
|
| 239 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 240 | + break; |
|
| 241 | + case 'prop': |
|
| 242 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 243 | + break; |
|
| 244 | + case 'publie': |
|
| 245 | + $texte = 'texte_statut_publie'; |
|
| 246 | + break; |
|
| 247 | + case 'refuse': |
|
| 248 | + $texte = 'texte_statut_refuse'; |
|
| 249 | + break; |
|
| 250 | + case 'poubelle': |
|
| 251 | + case 'poub': |
|
| 252 | + $texte = 'texte_statut_poubelle'; |
|
| 253 | + break; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $texte ? _T($texte) : ''; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -274,16 +274,16 @@ discard block |
||
| 274 | 274 | * @return string |
| 275 | 275 | */ |
| 276 | 276 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 277 | - $img = statut_image('auteur', $statut); |
|
| 278 | - if (!$img) { |
|
| 279 | - return ''; |
|
| 280 | - } |
|
| 281 | - $alt = statut_titre('auteur', $statut); |
|
| 277 | + $img = statut_image('auteur', $statut); |
|
| 278 | + if (!$img) { |
|
| 279 | + return ''; |
|
| 280 | + } |
|
| 281 | + $alt = statut_titre('auteur', $statut); |
|
| 282 | 282 | |
| 283 | - $fond = ''; |
|
| 284 | - $titre = ''; |
|
| 283 | + $fond = ''; |
|
| 284 | + $titre = ''; |
|
| 285 | 285 | |
| 286 | - /* |
|
| 286 | + /* |
|
| 287 | 287 | if ($type != 'auteur') { |
| 288 | 288 | $img2 = chemin_image('del-16.png'); |
| 289 | 289 | $titre = _T('titre_image_redacteur'); |
@@ -293,12 +293,12 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | */ |
| 295 | 295 | |
| 296 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 296 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
| 300 | 300 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 301 | - return http_img_pack('rubrique-16.png', ''); |
|
| 301 | + return http_img_pack('rubrique-16.png', ''); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -322,101 +322,101 @@ discard block |
||
| 322 | 322 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 323 | 323 | **/ |
| 324 | 324 | function puce_statut_changement_rapide( |
| 325 | - $id, |
|
| 326 | - $statut, |
|
| 327 | - $id_rubrique, |
|
| 328 | - $type = 'article', |
|
| 329 | - $ajax = false, |
|
| 330 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 325 | + $id, |
|
| 326 | + $statut, |
|
| 327 | + $id_rubrique, |
|
| 328 | + $type = 'article', |
|
| 329 | + $ajax = false, |
|
| 330 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 331 | 331 | ) { |
| 332 | - $src = statut_image($type, $statut); |
|
| 333 | - if (!$src) { |
|
| 334 | - return $src; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'"; |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - $t = statut_titre($type, $statut); |
|
| 341 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 342 | - |
|
| 343 | - if (!$ajax_node) { |
|
| 344 | - return $inser_puce; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $table = table_objet_sql($type); |
|
| 348 | - $desc = lister_tables_objets_sql($table); |
|
| 349 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 350 | - return $inser_puce; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (!function_exists('autoriser')) { |
|
| 354 | - include_spip('inc/autoriser'); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 358 | - if ($id_rubrique) { |
|
| 359 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 360 | - return $inser_puce; |
|
| 361 | - } |
|
| 362 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 363 | - else { |
|
| 364 | - if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 365 | - return $inser_puce; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 370 | - if (!isset($coord[$statut])) { |
|
| 371 | - return $inser_puce; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 375 | - ; |
|
| 376 | - $margin = 0; /* marge a gauche + droite */ |
|
| 377 | - $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 378 | - ; |
|
| 379 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 380 | - |
|
| 381 | - if ($ajax) { |
|
| 382 | - $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 383 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 384 | - . $inser_puce |
|
| 385 | - . '</span>' |
|
| 386 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 387 | - $i = 0; |
|
| 388 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 389 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $out . '</span>'; |
|
| 393 | - } else { |
|
| 394 | - $nom = 'puce_statut_'; |
|
| 395 | - $action = generer_url_ecrire('puce_statut', '', true); |
|
| 396 | - $lang_dir = lang_dir(lang_typo()); |
|
| 397 | - |
|
| 398 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 399 | - . $inser_puce |
|
| 400 | - . '</span>'; |
|
| 401 | - } |
|
| 332 | + $src = statut_image($type, $statut); |
|
| 333 | + if (!$src) { |
|
| 334 | + return $src; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'"; |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + $t = statut_titre($type, $statut); |
|
| 341 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 342 | + |
|
| 343 | + if (!$ajax_node) { |
|
| 344 | + return $inser_puce; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $table = table_objet_sql($type); |
|
| 348 | + $desc = lister_tables_objets_sql($table); |
|
| 349 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 350 | + return $inser_puce; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (!function_exists('autoriser')) { |
|
| 354 | + include_spip('inc/autoriser'); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 358 | + if ($id_rubrique) { |
|
| 359 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 360 | + return $inser_puce; |
|
| 361 | + } |
|
| 362 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 363 | + else { |
|
| 364 | + if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 365 | + return $inser_puce; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 370 | + if (!isset($coord[$statut])) { |
|
| 371 | + return $inser_puce; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 375 | + ; |
|
| 376 | + $margin = 0; /* marge a gauche + droite */ |
|
| 377 | + $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 378 | + ; |
|
| 379 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 380 | + |
|
| 381 | + if ($ajax) { |
|
| 382 | + $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 383 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 384 | + . $inser_puce |
|
| 385 | + . '</span>' |
|
| 386 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 387 | + $i = 0; |
|
| 388 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 389 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $out . '</span>'; |
|
| 393 | + } else { |
|
| 394 | + $nom = 'puce_statut_'; |
|
| 395 | + $action = generer_url_ecrire('puce_statut', '', true); |
|
| 396 | + $lang_dir = lang_dir(lang_typo()); |
|
| 397 | + |
|
| 398 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 399 | + . $inser_puce |
|
| 400 | + . '</span>'; |
|
| 401 | + } |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | |
| 405 | 405 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 406 | - $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 407 | - $t = supprimer_tags($titre); |
|
| 406 | + $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 407 | + $t = supprimer_tags($titre); |
|
| 408 | 408 | |
| 409 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 409 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | // compat |
| 413 | 413 | // La couleur du statut |
| 414 | 414 | |
| 415 | 415 | function puce_statut($statut, $atts = '') { |
| 416 | - $src = statut_image('article', $statut); |
|
| 417 | - if (!$src) { |
|
| 418 | - return ''; |
|
| 419 | - } |
|
| 416 | + $src = statut_image('article', $statut); |
|
| 417 | + if (!$src) { |
|
| 418 | + return ''; |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 421 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 422 | 422 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | * @return array |
| 23 | 23 | */ |
| 24 | 24 | function inc_simplexml_to_array_dist($u, $utiliser_namespace = false) { |
| 25 | - // decoder la chaine en SimpleXML si pas deja fait |
|
| 26 | - if (is_string($u)) { |
|
| 27 | - $u = simplexml_load_string($u); |
|
| 28 | - } |
|
| 25 | + // decoder la chaine en SimpleXML si pas deja fait |
|
| 26 | + if (is_string($u)) { |
|
| 27 | + $u = simplexml_load_string($u); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - return ['root' => @xmlObjToArr($u, $utiliser_namespace)]; |
|
| 30 | + return ['root' => @xmlObjToArr($u, $utiliser_namespace)]; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -42,67 +42,67 @@ discard block |
||
| 42 | 42 | **/ |
| 43 | 43 | function xmlObjToArr($obj, $utiliser_namespace = false) { |
| 44 | 44 | |
| 45 | - $namespace = []; |
|
| 46 | - $tableau = []; |
|
| 45 | + $namespace = []; |
|
| 46 | + $tableau = []; |
|
| 47 | 47 | |
| 48 | - // Cette fonction getDocNamespaces() est longue sur de gros xml. On permet donc |
|
| 49 | - // de l'activer ou pas suivant le contenu supposé du XML |
|
| 50 | - if (is_object($obj)) { |
|
| 51 | - if (is_array($utiliser_namespace)) { |
|
| 52 | - $namespace = $utiliser_namespace; |
|
| 53 | - } else { |
|
| 54 | - if ($utiliser_namespace) { |
|
| 55 | - $namespace = $obj->getDocNamespaces(true); |
|
| 56 | - } |
|
| 57 | - $namespace[null] = null; |
|
| 58 | - } |
|
| 48 | + // Cette fonction getDocNamespaces() est longue sur de gros xml. On permet donc |
|
| 49 | + // de l'activer ou pas suivant le contenu supposé du XML |
|
| 50 | + if (is_object($obj)) { |
|
| 51 | + if (is_array($utiliser_namespace)) { |
|
| 52 | + $namespace = $utiliser_namespace; |
|
| 53 | + } else { |
|
| 54 | + if ($utiliser_namespace) { |
|
| 55 | + $namespace = $obj->getDocNamespaces(true); |
|
| 56 | + } |
|
| 57 | + $namespace[null] = null; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $name = strtolower((string)$obj->getName()); |
|
| 61 | - $text = trim((string)$obj); |
|
| 62 | - if (strlen($text) <= 0) { |
|
| 63 | - $text = null; |
|
| 64 | - } |
|
| 60 | + $name = strtolower((string)$obj->getName()); |
|
| 61 | + $text = trim((string)$obj); |
|
| 62 | + if (strlen($text) <= 0) { |
|
| 63 | + $text = null; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $children = []; |
|
| 67 | - $attributes = []; |
|
| 66 | + $children = []; |
|
| 67 | + $attributes = []; |
|
| 68 | 68 | |
| 69 | - // get info for all namespaces |
|
| 70 | - foreach (array_keys($namespace) as $ns) { |
|
| 71 | - // attributes |
|
| 72 | - $objAttributes = $obj->attributes($ns, true); |
|
| 73 | - foreach ($objAttributes as $attributeName => $attributeValue) { |
|
| 74 | - $attribName = strtolower(trim((string)$attributeName)); |
|
| 75 | - $attribVal = trim((string)$attributeValue); |
|
| 76 | - if (!empty($ns)) { |
|
| 77 | - $attribName = $ns . ':' . $attribName; |
|
| 78 | - } |
|
| 79 | - $attributes[$attribName] = $attribVal; |
|
| 80 | - } |
|
| 69 | + // get info for all namespaces |
|
| 70 | + foreach (array_keys($namespace) as $ns) { |
|
| 71 | + // attributes |
|
| 72 | + $objAttributes = $obj->attributes($ns, true); |
|
| 73 | + foreach ($objAttributes as $attributeName => $attributeValue) { |
|
| 74 | + $attribName = strtolower(trim((string)$attributeName)); |
|
| 75 | + $attribVal = trim((string)$attributeValue); |
|
| 76 | + if (!empty($ns)) { |
|
| 77 | + $attribName = $ns . ':' . $attribName; |
|
| 78 | + } |
|
| 79 | + $attributes[$attribName] = $attribVal; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // children |
|
| 83 | - $objChildren = $obj->children($ns, true); |
|
| 84 | - foreach ($objChildren as $childName => $child) { |
|
| 85 | - $childName = strtolower((string)$childName); |
|
| 86 | - if (!empty($ns)) { |
|
| 87 | - $childName = $ns . ':' . $childName; |
|
| 88 | - } |
|
| 89 | - $children[$childName][] = xmlObjToArr($child, $namespace); |
|
| 90 | - } |
|
| 91 | - } |
|
| 82 | + // children |
|
| 83 | + $objChildren = $obj->children($ns, true); |
|
| 84 | + foreach ($objChildren as $childName => $child) { |
|
| 85 | + $childName = strtolower((string)$childName); |
|
| 86 | + if (!empty($ns)) { |
|
| 87 | + $childName = $ns . ':' . $childName; |
|
| 88 | + } |
|
| 89 | + $children[$childName][] = xmlObjToArr($child, $namespace); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $tableau = [ |
|
| 94 | - 'name' => $name, |
|
| 95 | - ]; |
|
| 96 | - if ($text) { |
|
| 97 | - $tableau['text'] = $text; |
|
| 98 | - } |
|
| 99 | - if ($attributes) { |
|
| 100 | - $tableau['attributes'] = $attributes; |
|
| 101 | - } |
|
| 102 | - if ($children) { |
|
| 103 | - $tableau['children'] = $children; |
|
| 104 | - } |
|
| 105 | - } |
|
| 93 | + $tableau = [ |
|
| 94 | + 'name' => $name, |
|
| 95 | + ]; |
|
| 96 | + if ($text) { |
|
| 97 | + $tableau['text'] = $text; |
|
| 98 | + } |
|
| 99 | + if ($attributes) { |
|
| 100 | + $tableau['attributes'] = $attributes; |
|
| 101 | + } |
|
| 102 | + if ($children) { |
|
| 103 | + $tableau['children'] = $children; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return $tableau; |
|
| 107 | + return $tableau; |
|
| 108 | 108 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -28,51 +28,51 @@ discard block |
||
| 28 | 28 | * @return string Erreur éventuelle |
| 29 | 29 | */ |
| 30 | 30 | function inc_completer_traduction_dist($objet, $id_objet, $id_trad) { |
| 31 | - // dupliquer tous les liens sauf les auteurs : le nouvel auteur est celui qui traduit |
|
| 32 | - // cf API editer_liens |
|
| 33 | - include_spip('action/editer_liens'); |
|
| 34 | - objet_dupliquer_liens($objet, $id_trad, $id_objet, null, ['auteur']); |
|
| 35 | - $_id_table = id_table_objet($objet); |
|
| 31 | + // dupliquer tous les liens sauf les auteurs : le nouvel auteur est celui qui traduit |
|
| 32 | + // cf API editer_liens |
|
| 33 | + include_spip('action/editer_liens'); |
|
| 34 | + objet_dupliquer_liens($objet, $id_trad, $id_objet, null, ['auteur']); |
|
| 35 | + $_id_table = id_table_objet($objet); |
|
| 36 | 36 | |
| 37 | - // recuperer le logo |
|
| 38 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | - include_spip('action/editer_logo'); |
|
| 40 | - foreach (['on', 'off'] as $etat) { |
|
| 41 | - $logo = $chercher_logo($id_trad, $_id_table, $etat); |
|
| 42 | - if ($logo && ($file = reset($logo))) { |
|
| 43 | - logo_modifier($objet, $id_objet, $etat, $file); |
|
| 44 | - } |
|
| 45 | - } |
|
| 37 | + // recuperer le logo |
|
| 38 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | + include_spip('action/editer_logo'); |
|
| 40 | + foreach (['on', 'off'] as $etat) { |
|
| 41 | + $logo = $chercher_logo($id_trad, $_id_table, $etat); |
|
| 42 | + if ($logo && ($file = reset($logo))) { |
|
| 43 | + logo_modifier($objet, $id_objet, $etat, $file); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // dupliquer certains champs |
|
| 48 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 49 | - $desc = $trouver_table(table_objet_sql($objet)); |
|
| 50 | - $champs = $set = []; |
|
| 47 | + // dupliquer certains champs |
|
| 48 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 49 | + $desc = $trouver_table(table_objet_sql($objet)); |
|
| 50 | + $champs = $set = []; |
|
| 51 | 51 | |
| 52 | - // un éventuel champ 'virtuel' (redirections) |
|
| 53 | - if (!empty($desc['field']['virtuel'])) { |
|
| 54 | - $champs[] = 'virtuel'; |
|
| 55 | - } |
|
| 52 | + // un éventuel champ 'virtuel' (redirections) |
|
| 53 | + if (!empty($desc['field']['virtuel'])) { |
|
| 54 | + $champs[] = 'virtuel'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $data = sql_fetsel('*', $desc['table'], $_id_table . '=' . (int) $id_trad); |
|
| 57 | + $data = sql_fetsel('*', $desc['table'], $_id_table . '=' . (int) $id_trad); |
|
| 58 | 58 | |
| 59 | - foreach ($champs as $c) { |
|
| 60 | - $set[$c] = $data[$c]; |
|
| 61 | - } |
|
| 59 | + foreach ($champs as $c) { |
|
| 60 | + $set[$c] = $data[$c]; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /* |
|
| 63 | + /* |
|
| 64 | 64 | * Le pipeline 'pre_edition' sera appelé avec l'action 'completer_traduction'. |
| 65 | 65 | * Des plugins pourront ainsi compléter les champs d'un objet traduit lors d'une nouvelle traduction. |
| 66 | 66 | */ |
| 67 | - $err = objet_modifier_champs( |
|
| 68 | - $objet, |
|
| 69 | - $id_objet, |
|
| 70 | - [ |
|
| 71 | - 'data' => $data, |
|
| 72 | - 'action' => 'completer_traduction', |
|
| 73 | - ], |
|
| 74 | - $set |
|
| 75 | - ); |
|
| 67 | + $err = objet_modifier_champs( |
|
| 68 | + $objet, |
|
| 69 | + $id_objet, |
|
| 70 | + [ |
|
| 71 | + 'data' => $data, |
|
| 72 | + 'action' => 'completer_traduction', |
|
| 73 | + ], |
|
| 74 | + $set |
|
| 75 | + ); |
|
| 76 | 76 | |
| 77 | - return $err; |
|
| 77 | + return $err; |
|
| 78 | 78 | } |