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:
2026-06-10 21:30:25 +02:00
parent e6b73df516
commit 9280c3b9ce
44 changed files with 3209 additions and 2907 deletions

View File

@@ -1,18 +1,18 @@
<?php
$context = Timber::context();
// Séances de séminaire (cat 12) are included: post-card-helpers rewrites their
// link to the parent séminaire + #seance-{ID} hash.
$excluded_cat_ids = [31]; // Non classé
if ( ! is_user_logged_in() ) $excluded_cat_ids[] = 9; // Vie du labo
// Les séances de séminaire sont incluses : post-card-helpers réécrit leur
// lien vers le séminaire parent + ancre #seance-{ID}.
$excluded_cat_ids = thalim_archive_excluded_cat_ids( false ); // Non classé (+ Vie du labo non connectés)
$search_query = get_search_query();
// 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['search_query'] = $search_query;
$context['active_axe'] = $active_axe;
@@ -23,13 +23,7 @@ $context['active_cat_id'] = $active_cat_id;
$context['filter_autres'] = $filter_autres;
// Determine active rubrique
$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 URL for search filter links (language-aware)
@@ -72,7 +66,6 @@ $query_args = [
'posts_per_page' => 12,
'orderby' => 'relevance',
'order' => 'DESC',
'lang' => '',
'tax_query' => $tax_query,
];
if ($active_axe) {
@@ -98,59 +91,19 @@ $context['axe_stay_on_page'] = true;
// Rubrique/catégorie filter links (all preserve search term)
$all_cats = get_categories(['taxonomy' => 'category', 'hide_empty' => false, 'exclude' => $excluded_cat_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, $search_base),
];
}
}
$context['filter_parents'] = $filter_parents;
// Liens de filtre : on reste sur la recherche avec un paramètre filter_cat
$make_filter_link = function ($cat) use ($base_filter_params, $search_base) {
$params = array_filter(array_merge($base_filter_params, ['filter_cat' => $cat->term_id]));
return add_query_arg($params, $search_base);
};
$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, $search_base),
];
}
}
}
// Add "Autres" entry if active rubrique has posts directly assigned to it
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' => [[
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => [$active_rubrique_id],
'include_children' => false,
]],
]);
if ($direct_check->have_posts()) {
$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, $search_base),
];
}
if ($active_rubrique_id && !empty($filter_categories) && thalim_rubrique_has_direct_posts($active_rubrique_id)) {
$params = array_filter(array_merge($base_filter_params, ['filter_cat' => $active_rubrique_id, 'filter_autres' => 1]));
$filter_categories[] = thalim_archive_autres_entry(add_query_arg($params, $search_base));
}
$context['filter_categories'] = $filter_categories;
@@ -161,21 +114,24 @@ $context['posts'] = $posts;
// Search users (members) by display_name
$author_cards = [];
if ( $search_query ) {
$excluded_role_ids = [ 600, 598 ]; // "À ranger", "Archive"
$user_query = new WP_User_Query([
$excluded_role_ids = thalim_excluded_role_ids(); // « À ranger », « Archive » (résolus par slug)
$user_query_args = [
'search' => '*' . $search_query . '*',
'search_columns' => ['display_name'],
'number' => 6,
'orderby' => 'display_name',
'order' => 'ASC',
'meta_query' => [
];
if ( $excluded_role_ids ) {
$user_query_args['meta_query'] = [
[
'key' => 'role_1',
'value' => $excluded_role_ids,
'compare' => 'NOT IN',
],
],
]);
];
}
$user_query = new WP_User_Query( $user_query_args );
$lang = thalim_current_language();
// Direction IDs (same source as membres page and author page)