Refactoring : sécurité (XSS), découpage en modules inc/* et js/admin/*, IDs résolus par slug, perf (caches, cron Gravatar, assets auto-hébergés), tests
This commit is contained in:
100
taxonomy.php
100
taxonomy.php
@@ -10,15 +10,16 @@ $context['parent_slug'] = '';
|
||||
$tax_object = get_taxonomy($taxonomy);
|
||||
$context['taxonomy_label'] = $tax_object ? $tax_object->labels->singular_name : $taxonomy;
|
||||
|
||||
$excluded_ids = [12, 31]; // Séance de séminaire, Non classé
|
||||
if ( ! is_user_logged_in() ) $excluded_ids[] = 9; // Vie du labo
|
||||
// Séance de séminaire, Non classé (+ Vie du labo pour les non-connectés)
|
||||
$excluded_ids = thalim_archive_excluded_cat_ids();
|
||||
|
||||
// Read filter query params
|
||||
$active_axe = isset($_GET['axe']) ? intval($_GET['axe']) : 0;
|
||||
$active_date_from = isset($_GET['date_from']) ? sanitize_text_field($_GET['date_from']) : '';
|
||||
$active_date_to = isset($_GET['date_to']) ? sanitize_text_field($_GET['date_to']) : '';
|
||||
$active_cat_id = isset($_GET['filter_cat']) ? intval($_GET['filter_cat']) : 0;
|
||||
$filter_autres = isset($_GET['filter_autres']) ? 1 : 0;
|
||||
$f = thalim_archive_read_filters();
|
||||
$active_axe = $f['axe'];
|
||||
$active_date_from = $f['date_from'];
|
||||
$active_date_to = $f['date_to'];
|
||||
$active_cat_id = $f['cat_id'];
|
||||
$filter_autres = $f['filter_autres'];
|
||||
|
||||
$context['active_axe'] = $active_axe;
|
||||
$context['active_date_from'] = $active_date_from;
|
||||
@@ -28,13 +29,7 @@ $context['active_cat_id'] = $active_cat_id;
|
||||
$context['filter_autres'] = $filter_autres;
|
||||
|
||||
// Determine active rubrique from active category (parent if subcategory, itself if top-level)
|
||||
$active_rubrique_id = 0;
|
||||
if ($active_cat_id) {
|
||||
$active_cat_obj = get_category($active_cat_id);
|
||||
$active_rubrique_id = ($active_cat_obj && $active_cat_obj->parent)
|
||||
? $active_cat_obj->parent
|
||||
: $active_cat_id;
|
||||
}
|
||||
$active_rubrique_id = thalim_archive_active_rubrique($active_cat_id);
|
||||
$context['active_rubrique'] = $active_rubrique_id;
|
||||
|
||||
// Base params shared across all filter links (preserves active filters when navigating)
|
||||
@@ -53,11 +48,11 @@ $tax_query = [
|
||||
'field' => 'term_id',
|
||||
'terms' => [$term->term_id],
|
||||
],
|
||||
// Exclure les séances de séminaire (catégorie 12)
|
||||
// Exclure les séances de séminaire
|
||||
[
|
||||
'taxonomy' => 'category',
|
||||
'field' => 'term_id',
|
||||
'terms' => [12],
|
||||
'terms' => [ thalim_cat_id('seance') ],
|
||||
'operator' => 'NOT IN',
|
||||
],
|
||||
];
|
||||
@@ -101,66 +96,28 @@ $context['axe_stay_on_page'] = !$axe_taxonomy_mode;
|
||||
$current_term_url = get_term_link($term);
|
||||
$all_cats = get_categories(['taxonomy' => 'category', 'hide_empty' => false, 'exclude' => $excluded_ids]);
|
||||
|
||||
$filter_parents = [];
|
||||
foreach ($all_cats as $cat) {
|
||||
if ($cat->parent == 0) {
|
||||
$params = array_filter(array_merge($base_filter_params, ['filter_cat' => $cat->term_id]));
|
||||
$filter_parents[] = [
|
||||
'id' => $cat->term_id,
|
||||
'name' => thalim_cat_name($cat),
|
||||
'slug' => $cat->slug,
|
||||
'link' => add_query_arg($params, $current_term_url),
|
||||
];
|
||||
}
|
||||
}
|
||||
$context['filter_parents'] = $filter_parents;
|
||||
// Liens de filtre : on reste sur l'URL du terme courant avec un paramètre filter_cat
|
||||
$make_filter_link = function ($cat) use ($base_filter_params, $current_term_url) {
|
||||
$params = array_filter(array_merge($base_filter_params, ['filter_cat' => $cat->term_id]));
|
||||
return add_query_arg($params, $current_term_url);
|
||||
};
|
||||
$context['filter_parents'] = thalim_archive_filter_parents($all_cats, $make_filter_link);
|
||||
|
||||
$filter_categories = thalim_archive_filter_children($all_cats, $active_rubrique_id, $make_filter_link);
|
||||
|
||||
$filter_categories = [];
|
||||
if ($active_rubrique_id) {
|
||||
foreach ($all_cats as $cat) {
|
||||
if ($cat->parent == $active_rubrique_id) {
|
||||
$params = array_filter(array_merge($base_filter_params, ['filter_cat' => $cat->term_id]));
|
||||
$filter_categories[] = [
|
||||
'id' => $cat->term_id,
|
||||
'name' => thalim_cat_name($cat),
|
||||
'slug' => $cat->slug,
|
||||
'link' => add_query_arg($params, $current_term_url),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add "Autres" entry if active rubrique has posts directly assigned to it
|
||||
// (contraints au terme de taxonomie courant)
|
||||
if ($active_rubrique_id && !empty($filter_categories)) {
|
||||
$lang = thalim_current_language();
|
||||
$direct_check = new WP_Query([
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
'no_found_rows' => true,
|
||||
'lang' => '',
|
||||
'tax_query' => [
|
||||
'relation' => 'AND',
|
||||
[
|
||||
'taxonomy' => $taxonomy,
|
||||
'field' => 'term_id',
|
||||
'terms' => [$term->term_id],
|
||||
],
|
||||
[
|
||||
'taxonomy' => 'category',
|
||||
'field' => 'term_id',
|
||||
'terms' => [$active_rubrique_id],
|
||||
'include_children' => false,
|
||||
],
|
||||
$has_direct = thalim_rubrique_has_direct_posts($active_rubrique_id, [
|
||||
[
|
||||
'taxonomy' => $taxonomy,
|
||||
'field' => 'term_id',
|
||||
'terms' => [$term->term_id],
|
||||
],
|
||||
]);
|
||||
if ($direct_check->have_posts()) {
|
||||
if ($has_direct) {
|
||||
$params = array_filter(array_merge($base_filter_params, ['filter_cat' => $active_rubrique_id, 'filter_autres' => 1]));
|
||||
$filter_categories[] = [
|
||||
'id' => 'autres',
|
||||
'name' => $lang === 'en' ? 'Other' : 'Autres',
|
||||
'slug' => 'autres',
|
||||
'link' => add_query_arg($params, $current_term_url),
|
||||
];
|
||||
$filter_categories[] = thalim_archive_autres_entry(add_query_arg($params, $current_term_url));
|
||||
}
|
||||
}
|
||||
$context['filter_categories'] = $filter_categories;
|
||||
@@ -171,7 +128,6 @@ $posts = Timber::get_posts(array_merge([
|
||||
'posts_per_page' => 12,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'lang' => '',
|
||||
'thalim_event_date_order' => true,
|
||||
], $extra_query_args));
|
||||
$context['cards'] = thalim_get_cards_data($posts);
|
||||
@@ -181,6 +137,6 @@ $context['posts'] = $posts;
|
||||
$tax_lang = thalim_current_language();
|
||||
$pres_fr = get_term_meta($term->term_id, 'presentation', true) ?: '';
|
||||
$pres_en = get_term_meta($term->term_id, 'presentation_en', true) ?: '';
|
||||
$context['term_presentation'] = wpautop( ( $tax_lang === 'en' && $pres_en ) ? $pres_en : $pres_fr );
|
||||
$context['term_presentation'] = wpautop( wp_kses_post( ( $tax_lang === 'en' && $pres_en ) ? $pres_en : $pres_fr ) );
|
||||
|
||||
Timber::render('taxonomy.twig', $context);
|
||||
|
||||
Reference in New Issue
Block a user