@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $type = reset($objets); |
| 160 | 160 | $type = objet_type($type); |
| 161 | 161 | $id = (int) $ref; |
| 162 | - $ref = $type . $ref; |
|
| 162 | + $ref = $type.$ref; |
|
| 163 | 163 | } |
| 164 | 164 | else { |
| 165 | 165 | // Si la référence ne correspond à rien, c'est fini |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | return json_export(false); |
| 168 | 168 | } |
| 169 | 169 | // Sinon on récupère les infos utiles |
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 170 | + [$type,, $id,,,,] = array_pad($match, 7, null); |
|
| 171 | 171 | |
| 172 | 172 | // On regarde si le type trouvé fait partie des objets sélectionnables |
| 173 | 173 | if (!in_array(table_objet($type), $objets)) { |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | $types = (is_array($types) ? array_filter($types) : []); |
| 214 | 214 | |
| 215 | 215 | // recuperer tous les freres et soeurs de la rubrique visee |
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent='.(int) $id_parent); |
|
| 218 | 218 | $fratrie = array_column($fratrie, 'id_rubrique'); |
| 219 | 219 | $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
| 220 | 220 | $has = array_column($has, 'id_parent'); |
@@ -160,8 +160,7 @@ |
||
| 160 | 160 | $type = objet_type($type); |
| 161 | 161 | $id = (int) $ref; |
| 162 | 162 | $ref = $type . $ref; |
| 163 | - } |
|
| 164 | - else { |
|
| 163 | + } else { |
|
| 165 | 164 | // Si la référence ne correspond à rien, c'est fini |
| 166 | 165 | if (!($match = typer_raccourci($ref))) { |
| 167 | 166 | return json_export(false); |
@@ -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 | /** |
@@ -28,49 +28,49 @@ discard block |
||
| 28 | 28 | * - afficher : tableau des objets à afficher (mais pas forcément sélectionnables) |
| 29 | 29 | */ |
| 30 | 30 | function selecteur_lister_objets($includelist = [], $excludelist = []) { |
| 31 | - static $liste_selecteurs, $liste_parents; |
|
| 32 | - |
|
| 33 | - if (!$liste_selecteurs) { |
|
| 34 | - $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | - } |
|
| 36 | - $objets_selectionner = []; |
|
| 37 | - foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | - $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | - if (!empty($includelist)) { |
|
| 43 | - $includelist = array_map('table_objet', $includelist); |
|
| 44 | - $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | - } |
|
| 46 | - // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | - $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | - // On enlève toujours la racine |
|
| 49 | - $excludelist[] = 'racine'; |
|
| 50 | - $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | - |
|
| 52 | - // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | - $objets_afficher = $objets_selectionner; |
|
| 54 | - |
|
| 55 | - // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | - // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | - if (!$liste_parents) { |
|
| 58 | - $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | - } |
|
| 60 | - foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | - preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | - $parent = $captures[1]; |
|
| 63 | - $type = $captures[2]; |
|
| 64 | - // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | - if (in_array($type, $objets_afficher)) { |
|
| 66 | - $objets_afficher[] = $parent; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [ |
|
| 71 | - 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | - 'afficher' => array_unique($objets_afficher), |
|
| 73 | - ]; |
|
| 31 | + static $liste_selecteurs, $liste_parents; |
|
| 32 | + |
|
| 33 | + if (!$liste_selecteurs) { |
|
| 34 | + $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | + } |
|
| 36 | + $objets_selectionner = []; |
|
| 37 | + foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | + $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | + if (!empty($includelist)) { |
|
| 43 | + $includelist = array_map('table_objet', $includelist); |
|
| 44 | + $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | + } |
|
| 46 | + // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | + $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | + // On enlève toujours la racine |
|
| 49 | + $excludelist[] = 'racine'; |
|
| 50 | + $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | + |
|
| 52 | + // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | + $objets_afficher = $objets_selectionner; |
|
| 54 | + |
|
| 55 | + // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | + // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | + if (!$liste_parents) { |
|
| 58 | + $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | + } |
|
| 60 | + foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | + preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | + $parent = $captures[1]; |
|
| 63 | + $type = $captures[2]; |
|
| 64 | + // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | + if (in_array($type, $objets_afficher)) { |
|
| 66 | + $objets_afficher[] = $parent; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [ |
|
| 71 | + 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | + 'afficher' => array_unique($objets_afficher), |
|
| 73 | + ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -97,31 +97,31 @@ discard block |
||
| 97 | 97 | * liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet. |
| 98 | 98 | **/ |
| 99 | 99 | function picker_selected($selected, $type = '') { |
| 100 | - $select = []; |
|
| 101 | - $type = preg_replace(',\W,', '', $type); |
|
| 102 | - |
|
| 103 | - if ($selected && !is_array($selected)) { |
|
| 104 | - $selected = explode(',', $selected); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if (is_array($selected)) { |
|
| 108 | - foreach ($selected as $value) { |
|
| 109 | - // Si c'est le bon format déjà |
|
| 110 | - if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | - $objet = $captures[1]; |
|
| 112 | - $id_objet = (int) $captures[2]; |
|
| 113 | - |
|
| 114 | - // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | - if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | - $select[] = $id_objet; |
|
| 117 | - } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | - $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $select; |
|
| 100 | + $select = []; |
|
| 101 | + $type = preg_replace(',\W,', '', $type); |
|
| 102 | + |
|
| 103 | + if ($selected && !is_array($selected)) { |
|
| 104 | + $selected = explode(',', $selected); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if (is_array($selected)) { |
|
| 108 | + foreach ($selected as $value) { |
|
| 109 | + // Si c'est le bon format déjà |
|
| 110 | + if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | + $objet = $captures[1]; |
|
| 112 | + $id_objet = (int) $captures[2]; |
|
| 113 | + |
|
| 114 | + // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | + if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | + $select[] = $id_objet; |
|
| 117 | + } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | + $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $select; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -138,53 +138,53 @@ discard block |
||
| 138 | 138 | * Booléen indiquant si les articles sont sélectionnables |
| 139 | 139 | */ |
| 140 | 140 | function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) { |
| 141 | - include_spip('inc/json'); |
|
| 142 | - include_spip('inc/lien'); |
|
| 143 | - |
|
| 144 | - // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | - $objets = []; |
|
| 146 | - if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | - $objets = $rubriques_ou_objets; |
|
| 148 | - } else { |
|
| 149 | - if ($rubriques_ou_objets) { |
|
| 150 | - $objets[] = 'rubriques'; |
|
| 151 | - } |
|
| 152 | - if ($articles) { |
|
| 153 | - $objets[] = 'articles'; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | - if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | - $type = reset($objets); |
|
| 160 | - $type = objet_type($type); |
|
| 161 | - $id = (int) $ref; |
|
| 162 | - $ref = $type . $ref; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - // Si la référence ne correspond à rien, c'est fini |
|
| 166 | - if (!($match = typer_raccourci($ref))) { |
|
| 167 | - return json_export(false); |
|
| 168 | - } |
|
| 169 | - // Sinon on récupère les infos utiles |
|
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | - |
|
| 172 | - // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | - if (!in_array(table_objet($type), $objets)) { |
|
| 174 | - return json_export(false); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | - return json_export(false); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // On simplifie le texte |
|
| 185 | - $titre = attribut_html($titre); |
|
| 186 | - |
|
| 187 | - return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 141 | + include_spip('inc/json'); |
|
| 142 | + include_spip('inc/lien'); |
|
| 143 | + |
|
| 144 | + // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | + $objets = []; |
|
| 146 | + if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | + $objets = $rubriques_ou_objets; |
|
| 148 | + } else { |
|
| 149 | + if ($rubriques_ou_objets) { |
|
| 150 | + $objets[] = 'rubriques'; |
|
| 151 | + } |
|
| 152 | + if ($articles) { |
|
| 153 | + $objets[] = 'articles'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | + if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | + $type = reset($objets); |
|
| 160 | + $type = objet_type($type); |
|
| 161 | + $id = (int) $ref; |
|
| 162 | + $ref = $type . $ref; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + // Si la référence ne correspond à rien, c'est fini |
|
| 166 | + if (!($match = typer_raccourci($ref))) { |
|
| 167 | + return json_export(false); |
|
| 168 | + } |
|
| 169 | + // Sinon on récupère les infos utiles |
|
| 170 | + [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | + |
|
| 172 | + // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | + if (!in_array(table_objet($type), $objets)) { |
|
| 174 | + return json_export(false); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | + return json_export(false); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // On simplifie le texte |
|
| 185 | + $titre = attribut_html($titre); |
|
| 186 | + |
|
| 187 | + return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -207,34 +207,34 @@ discard block |
||
| 207 | 207 | * Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon. |
| 208 | 208 | */ |
| 209 | 209 | function test_enfants_rubrique($id_rubrique, $types = []) { |
| 210 | - static $has_child = []; |
|
| 211 | - |
|
| 212 | - if (!isset($has_child[$id_rubrique])) { |
|
| 213 | - $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | - |
|
| 215 | - // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | - $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | - $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | - $has = array_column($has, 'id_parent'); |
|
| 221 | - $fratrie = array_diff($fratrie, $has); |
|
| 222 | - |
|
| 223 | - while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | - $type = array_shift($types); |
|
| 225 | - $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | - $h = array_column($h, 'id_rubrique'); |
|
| 227 | - $has = [...$has, ...$h]; |
|
| 228 | - $fratrie = array_diff($fratrie, $h); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if ($has !== []) { |
|
| 232 | - $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | - } |
|
| 234 | - if ($fratrie !== []) { |
|
| 235 | - $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 210 | + static $has_child = []; |
|
| 211 | + |
|
| 212 | + if (!isset($has_child[$id_rubrique])) { |
|
| 213 | + $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | + |
|
| 215 | + // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | + $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | + $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | + $has = array_column($has, 'id_parent'); |
|
| 221 | + $fratrie = array_diff($fratrie, $has); |
|
| 222 | + |
|
| 223 | + while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | + $type = array_shift($types); |
|
| 225 | + $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | + $h = array_column($h, 'id_rubrique'); |
|
| 227 | + $has = [...$has, ...$h]; |
|
| 228 | + $fratrie = array_diff($fratrie, $h); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if ($has !== []) { |
|
| 232 | + $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | + } |
|
| 234 | + if ($fratrie !== []) { |
|
| 235 | + $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 240 | 240 | } |
@@ -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 | /** |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | * @return |
| 75 | 75 | **/ |
| 76 | 76 | function inc_genie_dist($taches = []) { |
| 77 | - include_spip('inc/queue'); |
|
| 78 | - |
|
| 79 | - if (_request('exec') == 'job_queue') { |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $force_jobs = []; |
|
| 84 | - // l'ancienne facon de lancer une tache cron immediatement |
|
| 85 | - // etait de la passer en parametre a ing_genie_dist |
|
| 86 | - // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 87 | - foreach ($taches as $function => $period) { |
|
| 88 | - $force_jobs[] = queue_add_job( |
|
| 89 | - $function, |
|
| 90 | - _T('tache_cron_asap', ['function' => $function]), |
|
| 91 | - [time() - abs($period)], |
|
| 92 | - 'genie/' |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // et on passe la main a la gestion de la queue ! |
|
| 97 | - // en forcant eventuellement les jobs ajoute a l'instant |
|
| 98 | - return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 77 | + include_spip('inc/queue'); |
|
| 78 | + |
|
| 79 | + if (_request('exec') == 'job_queue') { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $force_jobs = []; |
|
| 84 | + // l'ancienne facon de lancer une tache cron immediatement |
|
| 85 | + // etait de la passer en parametre a ing_genie_dist |
|
| 86 | + // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 87 | + foreach ($taches as $function => $period) { |
|
| 88 | + $force_jobs[] = queue_add_job( |
|
| 89 | + $function, |
|
| 90 | + _T('tache_cron_asap', ['function' => $function]), |
|
| 91 | + [time() - abs($period)], |
|
| 92 | + 'genie/' |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // et on passe la main a la gestion de la queue ! |
|
| 97 | + // en forcant eventuellement les jobs ajoute a l'instant |
|
| 98 | + return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // |
@@ -108,34 +108,34 @@ discard block |
||
| 108 | 108 | // |
| 109 | 109 | function taches_generales($taches_generales = []) { |
| 110 | 110 | |
| 111 | - // verifier que toutes les taches cron sont planifiees |
|
| 112 | - // c'est une tache cron ! |
|
| 113 | - $taches_generales['queue_watch'] = 3600 * 24; |
|
| 111 | + // verifier que toutes les taches cron sont planifiees |
|
| 112 | + // c'est une tache cron ! |
|
| 113 | + $taches_generales['queue_watch'] = 3600 * 24; |
|
| 114 | 114 | |
| 115 | - // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 116 | - // est fait au coup par coup a present |
|
| 117 | - // $taches_generales['rubriques'] = 3600; |
|
| 115 | + // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 116 | + // est fait au coup par coup a present |
|
| 117 | + // $taches_generales['rubriques'] = 3600; |
|
| 118 | 118 | |
| 119 | - // Optimisation de la base |
|
| 120 | - $taches_generales['optimiser'] = 3600 * 48; |
|
| 119 | + // Optimisation de la base |
|
| 120 | + $taches_generales['optimiser'] = 3600 * 48; |
|
| 121 | 121 | |
| 122 | - // nouveautes |
|
| 123 | - if ( |
|
| 124 | - isset($GLOBALS['meta']['adresse_neuf']) |
|
| 125 | - && $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | - && $GLOBALS['meta']['jours_neuf'] |
|
| 127 | - && $GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 128 | - ) { |
|
| 129 | - $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | - } |
|
| 122 | + // nouveautes |
|
| 123 | + if ( |
|
| 124 | + isset($GLOBALS['meta']['adresse_neuf']) |
|
| 125 | + && $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | + && $GLOBALS['meta']['jours_neuf'] |
|
| 127 | + && $GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 128 | + ) { |
|
| 129 | + $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // maintenance (ajax, verifications diverses) |
|
| 133 | - $taches_generales['maintenance'] = 3600 * 2; |
|
| 132 | + // maintenance (ajax, verifications diverses) |
|
| 133 | + $taches_generales['maintenance'] = 3600 * 2; |
|
| 134 | 134 | |
| 135 | - // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | - $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 135 | + // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | + $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 137 | 137 | |
| 138 | - return pipeline('taches_generales_cron', $taches_generales); |
|
| 138 | + return pipeline('taches_generales_cron', $taches_generales); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,22 +151,22 @@ discard block |
||
| 151 | 151 | * @return int |
| 152 | 152 | */ |
| 153 | 153 | function genie_queue_watch_dist() { |
| 154 | - static $deja_la = false; |
|
| 155 | - if ($deja_la) { |
|
| 156 | - return; |
|
| 157 | - } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | - $deja_la = true; |
|
| 159 | - $taches = taches_generales(); |
|
| 160 | - $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | - $programmees = array_column($programmees, 'fonction'); |
|
| 162 | - foreach ($taches as $tache => $periode) { |
|
| 163 | - if (!in_array($tache, $programmees)) { |
|
| 164 | - queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - $deja_la = false; |
|
| 168 | - |
|
| 169 | - return 1; |
|
| 154 | + static $deja_la = false; |
|
| 155 | + if ($deja_la) { |
|
| 156 | + return; |
|
| 157 | + } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | + $deja_la = true; |
|
| 159 | + $taches = taches_generales(); |
|
| 160 | + $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | + $programmees = array_column($programmees, 'fonction'); |
|
| 162 | + foreach ($taches as $tache => $periode) { |
|
| 163 | + if (!in_array($tache, $programmees)) { |
|
| 164 | + queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + $deja_la = false; |
|
| 168 | + |
|
| 169 | + return 1; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -187,32 +187,32 @@ discard block |
||
| 187 | 187 | * @return void |
| 188 | 188 | */ |
| 189 | 189 | function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) { |
| 190 | - static $done = []; |
|
| 191 | - if (isset($done[$function])) { |
|
| 192 | - return; |
|
| 193 | - } |
|
| 194 | - $done[$function] = true; |
|
| 195 | - if (is_null($time)) { |
|
| 196 | - $time = time(); |
|
| 197 | - if ($last) { |
|
| 198 | - $time = max($last + $period, $time); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - if (!$last) { |
|
| 202 | - $last = $time - $period; |
|
| 203 | - } |
|
| 204 | - spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | - include_spip('inc/queue'); |
|
| 206 | - // on replanifie un job cron |
|
| 207 | - // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | - // independament de l'argument |
|
| 209 | - queue_add_job( |
|
| 210 | - $function, |
|
| 211 | - _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | - [$last], |
|
| 213 | - 'genie/', |
|
| 214 | - 'function_only', |
|
| 215 | - $time, |
|
| 216 | - $priority |
|
| 217 | - ); |
|
| 190 | + static $done = []; |
|
| 191 | + if (isset($done[$function])) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 194 | + $done[$function] = true; |
|
| 195 | + if (is_null($time)) { |
|
| 196 | + $time = time(); |
|
| 197 | + if ($last) { |
|
| 198 | + $time = max($last + $period, $time); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + if (!$last) { |
|
| 202 | + $last = $time - $period; |
|
| 203 | + } |
|
| 204 | + spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | + include_spip('inc/queue'); |
|
| 206 | + // on replanifie un job cron |
|
| 207 | + // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | + // independament de l'argument |
|
| 209 | + queue_add_job( |
|
| 210 | + $function, |
|
| 211 | + _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | + [$last], |
|
| 213 | + 'genie/', |
|
| 214 | + 'function_only', |
|
| 215 | + $time, |
|
| 216 | + $priority |
|
| 217 | + ); |
|
| 218 | 218 | } |
@@ -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 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $role = $roles['roles']['defaut']; |
| 147 | 147 | } |
| 148 | 148 | // where |
| 149 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 149 | + $cond = ["$colonne_role=".sql_quote($role)]; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return [$role, $colonne_role, $cond]; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | unset($cond['role']); // cette condition est particuliere... |
| 180 | 180 | // on ajoute la condition du role aux autres conditions. |
| 181 | 181 | if ($colonne_role && $role != '*') { |
| 182 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 182 | + $cond[] = "$colonne_role=".sql_quote($role); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return [$cond, $colonne_role, $role]; |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $all = sql_allfetsel( |
| 363 | 363 | "DISTINCT $colone_role", |
| 364 | 364 | $l, |
| 365 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 365 | + 'objet='.sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | 366 | ); |
| 367 | 367 | $done[$hash] = array_map('reset', $all); |
| 368 | 368 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | static $t1 = ['&', '<', '>']; |
| 120 | 120 | static $t2 = ['&', '<', '>']; |
| 121 | 121 | |
| 122 | - return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 122 | + return '<pre>'.str_replace($t1, $t2, (string) $t).'</pre>'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | foreach ($lignes as &$l) { |
| 140 | 140 | $l = implode('|', $l); |
| 141 | 141 | } |
| 142 | - $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | - $corps = $caption . |
|
| 144 | - "\n|{{" . |
|
| 145 | - implode('}}|{{', $entete) . |
|
| 146 | - '}}|' . |
|
| 147 | - "\n|" . |
|
| 142 | + $corps = implode("\n", $lignes)."\n"; |
|
| 143 | + $corps = $caption. |
|
| 144 | + "\n|{{". |
|
| 145 | + implode('}}|{{', $entete). |
|
| 146 | + '}}|'. |
|
| 147 | + "\n|". |
|
| 148 | 148 | str_replace("\n", "|\n|", $corps); |
| 149 | 149 | include_spip('inc/texte'); |
| 150 | 150 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
| 189 | 189 | $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
| 190 | 190 | |
| 191 | - return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 191 | + return ($style ? "\n<style>".$style.'</style>' : '').$t; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | **/ |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | include_spip('inc/filtres'); |
| 27 | 27 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string Rien. |
| 39 | 39 | **/ |
| 40 | 40 | function filtre_image_dist($t) { |
| 41 | - return ''; |
|
| 41 | + return ''; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @return string Rien. |
| 52 | 52 | **/ |
| 53 | 53 | function filtre_audio_dist($t) { |
| 54 | - return ''; |
|
| 54 | + return ''; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return string Rien. |
| 65 | 65 | **/ |
| 66 | 66 | function filtre_video_dist($t) { |
| 67 | - return ''; |
|
| 67 | + return ''; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @return string Rien. |
| 78 | 78 | **/ |
| 79 | 79 | function filtre_application_dist($t) { |
| 80 | - return ''; |
|
| 80 | + return ''; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return string Rien. |
| 91 | 91 | **/ |
| 92 | 92 | function filtre_message_dist($t) { |
| 93 | - return ''; |
|
| 93 | + return ''; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @return string Rien. |
| 104 | 104 | **/ |
| 105 | 105 | function filtre_multipart_dist($t) { |
| 106 | - return ''; |
|
| 106 | + return ''; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -116,10 +116,10 @@ discard block |
||
| 116 | 116 | * @return string Contenu échappé. |
| 117 | 117 | **/ |
| 118 | 118 | function filtre_text_dist($t) { |
| 119 | - static $t1 = ['&', '<', '>']; |
|
| 120 | - static $t2 = ['&', '<', '>']; |
|
| 119 | + static $t1 = ['&', '<', '>']; |
|
| 120 | + static $t2 = ['&', '<', '>']; |
|
| 121 | 121 | |
| 122 | - return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 122 | + return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | * Tableau (formaté en SPIP) |
| 135 | 135 | **/ |
| 136 | 136 | function filtre_text_csv_dist($t) { |
| 137 | - include_spip('inc/csv'); |
|
| 138 | - [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 139 | - foreach ($lignes as &$l) { |
|
| 140 | - $l = implode('|', $l); |
|
| 141 | - } |
|
| 142 | - $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | - $corps = $caption . |
|
| 144 | - "\n|{{" . |
|
| 145 | - implode('}}|{{', $entete) . |
|
| 146 | - '}}|' . |
|
| 147 | - "\n|" . |
|
| 148 | - str_replace("\n", "|\n|", $corps); |
|
| 149 | - include_spip('inc/texte'); |
|
| 150 | - |
|
| 151 | - return propre($corps); |
|
| 137 | + include_spip('inc/csv'); |
|
| 138 | + [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 139 | + foreach ($lignes as &$l) { |
|
| 140 | + $l = implode('|', $l); |
|
| 141 | + } |
|
| 142 | + $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | + $corps = $caption . |
|
| 144 | + "\n|{{" . |
|
| 145 | + implode('}}|{{', $entete) . |
|
| 146 | + '}}|' . |
|
| 147 | + "\n|" . |
|
| 148 | + str_replace("\n", "|\n|", $corps); |
|
| 149 | + include_spip('inc/texte'); |
|
| 150 | + |
|
| 151 | + return propre($corps); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -162,33 +162,33 @@ discard block |
||
| 162 | 162 | * @return string Code html sécurisé ou texte échappé |
| 163 | 163 | **/ |
| 164 | 164 | function filtre_text_html_dist($t) { |
| 165 | - if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 166 | - return appliquer_filtre($t, 'text/plain'); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - [, $h, $t] = $r; |
|
| 170 | - |
|
| 171 | - $style = ''; |
|
| 172 | - // recuperer les styles internes |
|
| 173 | - if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 174 | - $style = implode("\n", $r[1]); |
|
| 175 | - } |
|
| 176 | - // ... et externes |
|
| 177 | - |
|
| 178 | - include_spip('inc/distant'); |
|
| 179 | - if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 180 | - foreach ($r[0] as $l) { |
|
| 181 | - preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 182 | - $page = recuperer_url($m[1]); |
|
| 183 | - $page = $page['page'] ?? ''; |
|
| 184 | - $style .= "\n/* $l */\n" |
|
| 185 | - . str_replace('<', '', (string) $page); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 189 | - $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
|
| 190 | - |
|
| 191 | - return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 165 | + if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 166 | + return appliquer_filtre($t, 'text/plain'); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + [, $h, $t] = $r; |
|
| 170 | + |
|
| 171 | + $style = ''; |
|
| 172 | + // recuperer les styles internes |
|
| 173 | + if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 174 | + $style = implode("\n", $r[1]); |
|
| 175 | + } |
|
| 176 | + // ... et externes |
|
| 177 | + |
|
| 178 | + include_spip('inc/distant'); |
|
| 179 | + if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 180 | + foreach ($r[0] as $l) { |
|
| 181 | + preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 182 | + $page = recuperer_url($m[1]); |
|
| 183 | + $page = $page['page'] ?? ''; |
|
| 184 | + $style .= "\n/* $l */\n" |
|
| 185 | + . str_replace('<', '', (string) $page); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 189 | + $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
|
| 190 | + |
|
| 191 | + return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return string Code HTML des balises `<param>` |
| 202 | 202 | **/ |
| 203 | 203 | function filtre_audio_x_pn_realaudio($id) { |
| 204 | - return " |
|
| 204 | + return " |
|
| 205 | 205 | <param name='controls' value='PositionSlider' /> |
| 206 | 206 | <param name='controls' value='ImageWindow' /> |
| 207 | 207 | <param name='controls' value='PlayButton' /> |
@@ -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 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $_id_table = reset($_id_table); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 69 | + $requete['SELECT'][] = 't.'.$_id_table; |
|
| 70 | 70 | $a = []; |
| 71 | 71 | // Recherche fulltext |
| 72 | 72 | foreach ($champs as $champ => $poids) { |
@@ -77,13 +77,13 @@ discard block |
||
| 77 | 77 | $champ = "t.$champ"; |
| 78 | 78 | } |
| 79 | 79 | $requete['SELECT'][] = $champ; |
| 80 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 80 | + $a[] = $champ.' '.$methode.' '.$q; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | if ($a) { |
| 84 | 84 | $requete['WHERE'][] = implode(' OR ', $a); |
| 85 | 85 | } |
| 86 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 86 | + $requete['FROM'][] = table_objet_sql($table).' AS t'; |
|
| 87 | 87 | |
| 88 | 88 | $results = []; |
| 89 | 89 | |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | ); |
| 245 | 245 | } // cas table de liaison generique spip_xxx_yyy |
| 246 | 246 | elseif ( |
| 247 | - ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | - || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 247 | + ($t = $trouver_table($table_arrivee.'_'.$table_depart, $serveur)) |
|
| 248 | + || ($t = $trouver_table($table_depart.'_'.$table_arrivee, $serveur)) |
|
| 249 | 249 | ) { |
| 250 | 250 | $s = sql_select( |
| 251 | 251 | "$cle_depart,$cle_arrivee", |
@@ -284,12 +284,12 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | if (isset($joint['champs']) && $joint['champs']) { |
| 286 | 286 | foreach ($joint['champs'] as $c => $val) { |
| 287 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 287 | + $results[$id]['champs'][$table_liee.'.'.$c] = $val; |
|
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | if (isset($joint['matches']) && $joint['matches']) { |
| 291 | 291 | foreach ($joint['matches'] as $c => $val) { |
| 292 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 292 | + $results[$id]['matches'][$table_liee.'.'.$c] = $val; |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -10,291 +10,291 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | // methodes sql |
| 18 | 18 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 19 | 19 | |
| 20 | - // options par defaut |
|
| 21 | - $options = array_merge( |
|
| 22 | - [ |
|
| 23 | - 'score' => true, |
|
| 24 | - 'champs' => false, |
|
| 25 | - 'toutvoir' => false, |
|
| 26 | - 'matches' => false, |
|
| 27 | - 'jointures' => false |
|
| 28 | - ], |
|
| 29 | - $options |
|
| 30 | - ); |
|
| 20 | + // options par defaut |
|
| 21 | + $options = array_merge( |
|
| 22 | + [ |
|
| 23 | + 'score' => true, |
|
| 24 | + 'champs' => false, |
|
| 25 | + 'toutvoir' => false, |
|
| 26 | + 'matches' => false, |
|
| 27 | + 'jointures' => false |
|
| 28 | + ], |
|
| 29 | + $options |
|
| 30 | + ); |
|
| 31 | 31 | |
| 32 | - include_spip('inc/rechercher'); |
|
| 33 | - include_spip('inc/autoriser'); |
|
| 32 | + include_spip('inc/rechercher'); |
|
| 33 | + include_spip('inc/autoriser'); |
|
| 34 | 34 | |
| 35 | - $requete = [ |
|
| 36 | - 'SELECT' => [], |
|
| 37 | - 'FROM' => [], |
|
| 38 | - 'WHERE' => [], |
|
| 39 | - 'GROUPBY' => [], |
|
| 40 | - 'ORDERBY' => [], |
|
| 41 | - 'LIMIT' => '', |
|
| 42 | - 'HAVING' => [] |
|
| 43 | - ]; |
|
| 35 | + $requete = [ |
|
| 36 | + 'SELECT' => [], |
|
| 37 | + 'FROM' => [], |
|
| 38 | + 'WHERE' => [], |
|
| 39 | + 'GROUPBY' => [], |
|
| 40 | + 'ORDERBY' => [], |
|
| 41 | + 'LIMIT' => '', |
|
| 42 | + 'HAVING' => [] |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - $table = sinon($options['table'], 'article'); |
|
| 46 | - if ($options['champs']) { |
|
| 47 | - $champs = $options['champs']; |
|
| 48 | - } else { |
|
| 49 | - $l = liste_des_champs(); |
|
| 50 | - $champs = $l['article']; |
|
| 51 | - } |
|
| 52 | - $serveur = $options['serveur']; |
|
| 45 | + $table = sinon($options['table'], 'article'); |
|
| 46 | + if ($options['champs']) { |
|
| 47 | + $champs = $options['champs']; |
|
| 48 | + } else { |
|
| 49 | + $l = liste_des_champs(); |
|
| 50 | + $champs = $l['article']; |
|
| 51 | + } |
|
| 52 | + $serveur = $options['serveur']; |
|
| 53 | 53 | |
| 54 | - [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 54 | + [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 55 | 55 | |
| 56 | - $jointures = $options['jointures'] |
|
| 57 | - ? liste_des_jointures() |
|
| 58 | - : []; |
|
| 56 | + $jointures = $options['jointures'] |
|
| 57 | + ? liste_des_jointures() |
|
| 58 | + : []; |
|
| 59 | 59 | |
| 60 | - $_id_table = id_table_objet($table); |
|
| 60 | + $_id_table = id_table_objet($table); |
|
| 61 | 61 | |
| 62 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 63 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 64 | - if (str_contains((string) $_id_table, ',')) { |
|
| 65 | - $_id_table = explode(',', (string) $_id_table); |
|
| 66 | - $_id_table = reset($_id_table); |
|
| 67 | - } |
|
| 62 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 63 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 64 | + if (str_contains((string) $_id_table, ',')) { |
|
| 65 | + $_id_table = explode(',', (string) $_id_table); |
|
| 66 | + $_id_table = reset($_id_table); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 70 | - $a = []; |
|
| 71 | - // Recherche fulltext |
|
| 72 | - foreach ($champs as $champ => $poids) { |
|
| 73 | - if (is_array($champ)) { |
|
| 74 | - spip_log('requetes imbriquees interdites'); |
|
| 75 | - } else { |
|
| 76 | - if (!str_contains((string) $champ, '.')) { |
|
| 77 | - $champ = "t.$champ"; |
|
| 78 | - } |
|
| 79 | - $requete['SELECT'][] = $champ; |
|
| 80 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - if ($a) { |
|
| 84 | - $requete['WHERE'][] = implode(' OR ', $a); |
|
| 85 | - } |
|
| 86 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 69 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 70 | + $a = []; |
|
| 71 | + // Recherche fulltext |
|
| 72 | + foreach ($champs as $champ => $poids) { |
|
| 73 | + if (is_array($champ)) { |
|
| 74 | + spip_log('requetes imbriquees interdites'); |
|
| 75 | + } else { |
|
| 76 | + if (!str_contains((string) $champ, '.')) { |
|
| 77 | + $champ = "t.$champ"; |
|
| 78 | + } |
|
| 79 | + $requete['SELECT'][] = $champ; |
|
| 80 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + if ($a) { |
|
| 84 | + $requete['WHERE'][] = implode(' OR ', $a); |
|
| 85 | + } |
|
| 86 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 87 | 87 | |
| 88 | - $results = []; |
|
| 88 | + $results = []; |
|
| 89 | 89 | |
| 90 | - $s = sql_select( |
|
| 91 | - $requete['SELECT'], |
|
| 92 | - $requete['FROM'], |
|
| 93 | - $requete['WHERE'], |
|
| 94 | - implode(' ', $requete['GROUPBY']), |
|
| 95 | - $requete['ORDERBY'], |
|
| 96 | - $requete['LIMIT'], |
|
| 97 | - $requete['HAVING'], |
|
| 98 | - $serveur |
|
| 99 | - ); |
|
| 90 | + $s = sql_select( |
|
| 91 | + $requete['SELECT'], |
|
| 92 | + $requete['FROM'], |
|
| 93 | + $requete['WHERE'], |
|
| 94 | + implode(' ', $requete['GROUPBY']), |
|
| 95 | + $requete['ORDERBY'], |
|
| 96 | + $requete['LIMIT'], |
|
| 97 | + $requete['HAVING'], |
|
| 98 | + $serveur |
|
| 99 | + ); |
|
| 100 | 100 | |
| 101 | - while ( |
|
| 102 | - ($t = sql_fetch($s, $serveur)) |
|
| 103 | - && (!isset($t['score']) || $t['score'] > 0) |
|
| 104 | - ) { |
|
| 105 | - $id = (int) $t[$_id_table]; |
|
| 101 | + while ( |
|
| 102 | + ($t = sql_fetch($s, $serveur)) |
|
| 103 | + && (!isset($t['score']) || $t['score'] > 0) |
|
| 104 | + ) { |
|
| 105 | + $id = (int) $t[$_id_table]; |
|
| 106 | 106 | |
| 107 | - if ($options['toutvoir'] || autoriser('voir', $table, $id)) { |
|
| 108 | - // indiquer les champs concernes |
|
| 109 | - $champs_vus = []; |
|
| 110 | - $score = 0; |
|
| 111 | - $matches = []; |
|
| 107 | + if ($options['toutvoir'] || autoriser('voir', $table, $id)) { |
|
| 108 | + // indiquer les champs concernes |
|
| 109 | + $champs_vus = []; |
|
| 110 | + $score = 0; |
|
| 111 | + $matches = []; |
|
| 112 | 112 | |
| 113 | - $vu = false; |
|
| 114 | - foreach ($champs as $champ => $poids) { |
|
| 115 | - $champ = explode('.', (string) $champ); |
|
| 116 | - $champ = end($champ); |
|
| 117 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 118 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 119 | - if ( |
|
| 120 | - $n = |
|
| 121 | - ($options['score'] || $options['matches']) |
|
| 122 | - ? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER) |
|
| 123 | - : preg_match($preg, (string) $value) |
|
| 124 | - ) { |
|
| 125 | - $vu = true; |
|
| 113 | + $vu = false; |
|
| 114 | + foreach ($champs as $champ => $poids) { |
|
| 115 | + $champ = explode('.', (string) $champ); |
|
| 116 | + $champ = end($champ); |
|
| 117 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 118 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 119 | + if ( |
|
| 120 | + $n = |
|
| 121 | + ($options['score'] || $options['matches']) |
|
| 122 | + ? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER) |
|
| 123 | + : preg_match($preg, (string) $value) |
|
| 124 | + ) { |
|
| 125 | + $vu = true; |
|
| 126 | 126 | |
| 127 | - if ($options['champs']) { |
|
| 128 | - $champs_vus[$champ] = $t[$champ]; |
|
| 129 | - } |
|
| 130 | - if ($options['score']) { |
|
| 131 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 132 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 133 | - } |
|
| 127 | + if ($options['champs']) { |
|
| 128 | + $champs_vus[$champ] = $t[$champ]; |
|
| 129 | + } |
|
| 130 | + if ($options['score']) { |
|
| 131 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 132 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - if ($options['matches']) { |
|
| 136 | - $matches[$champ] = $regs; |
|
| 137 | - } |
|
| 135 | + if ($options['matches']) { |
|
| 136 | + $matches[$champ] = $regs; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if (!$options['champs'] && !$options['score'] && !$options['matches']) { |
|
| 140 | - break; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 139 | + if (!$options['champs'] && !$options['score'] && !$options['matches']) { |
|
| 140 | + break; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if ($vu) { |
|
| 146 | - if (!isset($results)) { |
|
| 147 | - $results = []; |
|
| 148 | - } |
|
| 149 | - $results[$id] = []; |
|
| 150 | - if ($champs_vus) { |
|
| 151 | - $results[$id]['champs'] = $champs_vus; |
|
| 152 | - } |
|
| 153 | - if ($score) { |
|
| 154 | - $results[$id]['score'] = $score; |
|
| 155 | - } |
|
| 156 | - if ($matches) { |
|
| 157 | - $results[$id]['matches'] = $matches; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 145 | + if ($vu) { |
|
| 146 | + if (!isset($results)) { |
|
| 147 | + $results = []; |
|
| 148 | + } |
|
| 149 | + $results[$id] = []; |
|
| 150 | + if ($champs_vus) { |
|
| 151 | + $results[$id]['champs'] = $champs_vus; |
|
| 152 | + } |
|
| 153 | + if ($score) { |
|
| 154 | + $results[$id]['score'] = $score; |
|
| 155 | + } |
|
| 156 | + if ($matches) { |
|
| 157 | + $results[$id]['matches'] = $matches; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | |
| 164 | - // Gerer les donnees associees |
|
| 165 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 166 | - // on ne sait passer que par table de laison en 1 coup |
|
| 167 | - if ( |
|
| 168 | - isset($jointures[$table]) |
|
| 169 | - && ($joints = recherche_en_base( |
|
| 170 | - $recherche, |
|
| 171 | - $jointures[$table], |
|
| 172 | - array_merge($options, ['jointures' => false]) |
|
| 173 | - )) |
|
| 174 | - ) { |
|
| 175 | - include_spip('action/editer_liens'); |
|
| 176 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 177 | - $cle_depart = id_table_objet($table); |
|
| 178 | - $table_depart = table_objet($table, $serveur); |
|
| 179 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 180 | - $depart_associable = objet_associable($table); |
|
| 181 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 182 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 183 | - if ( |
|
| 184 | - !( |
|
| 185 | - ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true)) |
|
| 186 | - || ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true)) |
|
| 187 | - || ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true)) |
|
| 188 | - ) |
|
| 189 | - ) { |
|
| 190 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 191 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 192 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 193 | - // cas simple : $cle_depart dans la table_liee |
|
| 194 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 195 | - $s = sql_select( |
|
| 196 | - "$cle_depart, $cle_arrivee", |
|
| 197 | - $desc_arrivee['table_sql'], |
|
| 198 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 199 | - '', |
|
| 200 | - '', |
|
| 201 | - '', |
|
| 202 | - '', |
|
| 203 | - $serveur |
|
| 204 | - ); |
|
| 205 | - } // cas simple : $cle_arrivee dans la table |
|
| 206 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 207 | - $s = sql_select( |
|
| 208 | - "$cle_depart, $cle_arrivee", |
|
| 209 | - $desc_depart['table_sql'], |
|
| 210 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 211 | - '', |
|
| 212 | - '', |
|
| 213 | - '', |
|
| 214 | - '', |
|
| 215 | - $serveur |
|
| 216 | - ); |
|
| 217 | - } |
|
| 218 | - // sinon cherchons une table de liaison |
|
| 219 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 220 | - elseif ($l = objet_associable($table_liee)) { |
|
| 221 | - [$primary, $table_liens] = $l; |
|
| 222 | - $s = sql_select( |
|
| 223 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 224 | - $table_liens, |
|
| 225 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 226 | - '', |
|
| 227 | - '', |
|
| 228 | - '', |
|
| 229 | - '', |
|
| 230 | - $serveur |
|
| 231 | - ); |
|
| 232 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 233 | - elseif ($l = $depart_associable) { |
|
| 234 | - [$primary, $table_liens] = $l; |
|
| 235 | - $s = sql_select( |
|
| 236 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 237 | - $table_liens, |
|
| 238 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 239 | - '', |
|
| 240 | - '', |
|
| 241 | - '', |
|
| 242 | - '', |
|
| 243 | - $serveur |
|
| 244 | - ); |
|
| 245 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 246 | - elseif ( |
|
| 247 | - ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | - || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 249 | - ) { |
|
| 250 | - $s = sql_select( |
|
| 251 | - "$cle_depart,$cle_arrivee", |
|
| 252 | - $t['table_sql'], |
|
| 253 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 254 | - '', |
|
| 255 | - '', |
|
| 256 | - '', |
|
| 257 | - '', |
|
| 258 | - $serveur |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - } else { |
|
| 262 | - [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 263 | - $table, |
|
| 264 | - $table_liee, |
|
| 265 | - array_keys($ids_trouves), |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 164 | + // Gerer les donnees associees |
|
| 165 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 166 | + // on ne sait passer que par table de laison en 1 coup |
|
| 167 | + if ( |
|
| 168 | + isset($jointures[$table]) |
|
| 169 | + && ($joints = recherche_en_base( |
|
| 170 | + $recherche, |
|
| 171 | + $jointures[$table], |
|
| 172 | + array_merge($options, ['jointures' => false]) |
|
| 173 | + )) |
|
| 174 | + ) { |
|
| 175 | + include_spip('action/editer_liens'); |
|
| 176 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 177 | + $cle_depart = id_table_objet($table); |
|
| 178 | + $table_depart = table_objet($table, $serveur); |
|
| 179 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 180 | + $depart_associable = objet_associable($table); |
|
| 181 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 182 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 183 | + if ( |
|
| 184 | + !( |
|
| 185 | + ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true)) |
|
| 186 | + || ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true)) |
|
| 187 | + || ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true)) |
|
| 188 | + ) |
|
| 189 | + ) { |
|
| 190 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 191 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 192 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 193 | + // cas simple : $cle_depart dans la table_liee |
|
| 194 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 195 | + $s = sql_select( |
|
| 196 | + "$cle_depart, $cle_arrivee", |
|
| 197 | + $desc_arrivee['table_sql'], |
|
| 198 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 199 | + '', |
|
| 200 | + '', |
|
| 201 | + '', |
|
| 202 | + '', |
|
| 203 | + $serveur |
|
| 204 | + ); |
|
| 205 | + } // cas simple : $cle_arrivee dans la table |
|
| 206 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 207 | + $s = sql_select( |
|
| 208 | + "$cle_depart, $cle_arrivee", |
|
| 209 | + $desc_depart['table_sql'], |
|
| 210 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 211 | + '', |
|
| 212 | + '', |
|
| 213 | + '', |
|
| 214 | + '', |
|
| 215 | + $serveur |
|
| 216 | + ); |
|
| 217 | + } |
|
| 218 | + // sinon cherchons une table de liaison |
|
| 219 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 220 | + elseif ($l = objet_associable($table_liee)) { |
|
| 221 | + [$primary, $table_liens] = $l; |
|
| 222 | + $s = sql_select( |
|
| 223 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 224 | + $table_liens, |
|
| 225 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 226 | + '', |
|
| 227 | + '', |
|
| 228 | + '', |
|
| 229 | + '', |
|
| 230 | + $serveur |
|
| 231 | + ); |
|
| 232 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 233 | + elseif ($l = $depart_associable) { |
|
| 234 | + [$primary, $table_liens] = $l; |
|
| 235 | + $s = sql_select( |
|
| 236 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 237 | + $table_liens, |
|
| 238 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 239 | + '', |
|
| 240 | + '', |
|
| 241 | + '', |
|
| 242 | + '', |
|
| 243 | + $serveur |
|
| 244 | + ); |
|
| 245 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 246 | + elseif ( |
|
| 247 | + ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | + || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 249 | + ) { |
|
| 250 | + $s = sql_select( |
|
| 251 | + "$cle_depart,$cle_arrivee", |
|
| 252 | + $t['table_sql'], |
|
| 253 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 254 | + '', |
|
| 255 | + '', |
|
| 256 | + '', |
|
| 257 | + '', |
|
| 258 | + $serveur |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + } else { |
|
| 262 | + [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 263 | + $table, |
|
| 264 | + $table_liee, |
|
| 265 | + array_keys($ids_trouves), |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 271 | - $id = $t[$cle_depart]; |
|
| 272 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 273 | - if (!isset($results)) { |
|
| 274 | - $results = []; |
|
| 275 | - } |
|
| 276 | - if (!isset($results[$id])) { |
|
| 277 | - $results[$id] = []; |
|
| 278 | - } |
|
| 279 | - if (isset($joint['score']) && $joint['score']) { |
|
| 280 | - if (!isset($results[$id]['score'])) { |
|
| 281 | - $results[$id]['score'] = 0; |
|
| 282 | - } |
|
| 283 | - $results[$id]['score'] += $joint['score']; |
|
| 284 | - } |
|
| 285 | - if (isset($joint['champs']) && $joint['champs']) { |
|
| 286 | - foreach ($joint['champs'] as $c => $val) { |
|
| 287 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - if (isset($joint['matches']) && $joint['matches']) { |
|
| 291 | - foreach ($joint['matches'] as $c => $val) { |
|
| 292 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 270 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 271 | + $id = $t[$cle_depart]; |
|
| 272 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 273 | + if (!isset($results)) { |
|
| 274 | + $results = []; |
|
| 275 | + } |
|
| 276 | + if (!isset($results[$id])) { |
|
| 277 | + $results[$id] = []; |
|
| 278 | + } |
|
| 279 | + if (isset($joint['score']) && $joint['score']) { |
|
| 280 | + if (!isset($results[$id]['score'])) { |
|
| 281 | + $results[$id]['score'] = 0; |
|
| 282 | + } |
|
| 283 | + $results[$id]['score'] += $joint['score']; |
|
| 284 | + } |
|
| 285 | + if (isset($joint['champs']) && $joint['champs']) { |
|
| 286 | + foreach ($joint['champs'] as $c => $val) { |
|
| 287 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + if (isset($joint['matches']) && $joint['matches']) { |
|
| 291 | + foreach ($joint['matches'] as $c => $val) { |
|
| 292 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - return $results; |
|
| 299 | + return $results; |
|
| 300 | 300 | } |
@@ -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 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $result = sql_select( |
| 43 | 43 | 'id_rubrique, id_parent, titre, descriptif, lang', |
| 44 | 44 | 'spip_rubriques', |
| 45 | - 'id_parent=' . (int) $collection, |
|
| 45 | + 'id_parent='.(int) $collection, |
|
| 46 | 46 | '', |
| 47 | 47 | '0+titre,titre', |
| 48 | 48 | $debut == -1 ? '' : "$debut,$limite" |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
| 75 | 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 |
|
| 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 | 83 | . '</span>' |
| 84 | 84 | . (is_string($logo) ? $logo : '') |
| 85 | 85 | . '</a>'; |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | ; |
| 90 | 90 | |
| 91 | 91 | $res[] = |
| 92 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | - $les_sous_enfants . |
|
| 92 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre). |
|
| 93 | + $les_sous_enfants. |
|
| 94 | 94 | fin_cadre_sous_rub(); |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -109,7 +109,7 @@ 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); |
|
| 112 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.(int) $collection2); |
|
| 113 | 113 | |
| 114 | 114 | $retour = ''; |
| 115 | 115 | $pagination = ''; |
@@ -121,23 +121,23 @@ discard block |
||
| 121 | 121 | * Si > 500 on affiche une pagination |
| 122 | 122 | */ |
| 123 | 123 | if ($nb > $limite) { |
| 124 | - $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 124 | + $debut = _request('debut_rubrique'.$collection2) ?: $debut; |
|
| 125 | 125 | $pagination = chercher_filtre('pagination'); |
| 126 | - $pagination = '<nav class="pagination">' . $pagination( |
|
| 126 | + $pagination = '<nav class="pagination">'.$pagination( |
|
| 127 | 127 | $nb, |
| 128 | - '_rubrique' . $collection2, |
|
| 128 | + '_rubrique'.$collection2, |
|
| 129 | 129 | $debut, |
| 130 | 130 | $limite, |
| 131 | 131 | true, |
| 132 | 132 | 'prive' |
| 133 | - ) . '</nav>'; |
|
| 133 | + ).'</nav>'; |
|
| 134 | 134 | $limite = $debut + $limite; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $result = sql_select( |
| 138 | 138 | 'id_rubrique, id_parent, titre, lang', |
| 139 | 139 | 'spip_rubriques', |
| 140 | - 'id_parent=' . (int) $collection2, |
|
| 140 | + 'id_parent='.(int) $collection2, |
|
| 141 | 141 | '', |
| 142 | 142 | '0+titre,titre', |
| 143 | 143 | $debut == -1 ? '' : "$debut,$limite" |
@@ -157,14 +157,14 @@ discard block |
||
| 157 | 157 | changer_typo($row['lang']); |
| 158 | 158 | $lang_dir = lang_dir($row['lang']); |
| 159 | 159 | if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
| 160 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 160 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='".generer_objet_url( |
|
| 161 | 161 | $id_rubrique2, |
| 162 | 162 | 'rubrique' |
| 163 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 163 | + )."'>".$rang2.$titre2."</a></li>\n"; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $retour = $pagination . $retour . $pagination; |
|
| 167 | + $retour = $pagination.$retour.$pagination; |
|
| 168 | 168 | |
| 169 | 169 | if (!$retour) { |
| 170 | 170 | return ''; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | return debut_block_depliable($debut > 0, "enfants$collection2") |
| 174 | 174 | . "\n<ul class='liste-items sous-sous-rub'>\n" |
| 175 | 175 | . $retour |
| 176 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 176 | + . "</ul>\n".fin_block()."\n\n"; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | $debut = 0; |
| 193 | 193 | $limite = 500; |
| 194 | 194 | |
| 195 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 195 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.(int) $id_rubrique); |
|
| 196 | 196 | |
| 197 | 197 | if ($nb > $limite) { |
| 198 | - $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 198 | + $debut = _request('debut_rubrique'.$id_rubrique) ?: $debut; |
|
| 199 | 199 | $pagination = chercher_filtre('pagination'); |
| 200 | - $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 200 | + $pagination = '<br class="nettoyeur"><nav class="pagination">'. |
|
| 201 | + $pagination($nb, '_rubrique'.$id_rubrique, $debut, $limite, true, 'prive'). |
|
| 202 | 202 | '</nav>'; |
| 203 | 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 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
| 42 | 42 | } elseif ( |
| 43 | 43 | is_int(_AUTO_SELECTION_RUBRIQUE) |
| 44 | - && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 44 | + && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique='.(int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | 45 | ) { |
| 46 | 46 | $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
| 47 | 47 | } else { |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | $id_rubrique = $row_rub['id_rubrique']; |
| 51 | 51 | } |
| 52 | 52 | // si le choix ne convient pas, on cherche dans un secteur |
| 53 | - if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 53 | + if (!autoriser('creer'.$objet.'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | 54 | $id_rubrique = ''; |
| 55 | 55 | // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
| 56 | 56 | $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
| 57 | 57 | while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
| 58 | - if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 58 | + if (autoriser('creer'.$objet.'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | 59 | $id_rubrique = $row_rub['id_rubrique']; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -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 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | if (!$max_age) { |
| 107 | 107 | $max_age = _DEFAULT_LOCKTIME; |
| 108 | 108 | } |
| 109 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 109 | + $lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | /* |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | |
| 117 | 117 | $id = creer_uniqid(); |
| 118 | - $tpath = _DIR_TMP . "slock.$id"; |
|
| 118 | + $tpath = _DIR_TMP."slock.$id"; |
|
| 119 | 119 | $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
| 120 | 120 | if (!$tmpfd) { /* open failed */ |
| 121 | 121 | @fclose($tmpfd); |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * thinks the current time is (our_tmp.st_ctime).. |
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | - $tpath = _DIR_TMP . "stime.$id"; |
|
| 244 | + $tpath = _DIR_TMP."stime.$id"; |
|
| 245 | 245 | $tmpfd = @fopen($tpath, 'w'); |
| 246 | 246 | if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
| 247 | 247 | /* The open failed, or we can't write the file, or we can't stat it */ |
@@ -251,14 +251,14 @@ discard block |
||
| 251 | 251 | return false; //(NFSL_SYSF); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 254 | + @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | 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 |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | if (!$test) { |
| 279 | 279 | return false; |
| 280 | 280 | } //(NFSL_LOST); |
| 281 | - sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 281 | + sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - return true;//(NFSL_OK); /* success */ |
|
| 284 | + return true; //(NFSL_OK); /* success */ |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /* |