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:
97
category.php
97
category.php
@@ -4,8 +4,8 @@ $category = get_queried_object();
|
||||
$context['category'] = Timber::get_term($category);
|
||||
$context['cards'] = [];
|
||||
|
||||
$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();
|
||||
|
||||
// Parent category slug for color theming
|
||||
if ($category->parent) {
|
||||
@@ -54,68 +54,25 @@ $all_cats = get_categories([
|
||||
'exclude' => $excluded_ids,
|
||||
]);
|
||||
|
||||
$filter_parents = [];
|
||||
foreach ($all_cats as $cat) {
|
||||
if ($cat->parent == 0) {
|
||||
$link = get_category_link($cat->term_id);
|
||||
if ($filter_query) $link .= '?' . $filter_query;
|
||||
$filter_parents[] = [
|
||||
'id' => $cat->term_id,
|
||||
'name' => thalim_cat_name($cat),
|
||||
'slug' => $cat->slug,
|
||||
'link' => $link,
|
||||
];
|
||||
}
|
||||
}
|
||||
$context['filter_parents'] = $filter_parents;
|
||||
// Liens de filtre : navigation vers la page de catégorie, en conservant axe/dates
|
||||
$make_cat_link = function ($cat) use ($filter_query) {
|
||||
$link = get_category_link($cat->term_id);
|
||||
return $filter_query ? $link . '?' . $filter_query : $link;
|
||||
};
|
||||
$context['filter_parents'] = thalim_archive_filter_parents($all_cats, $make_cat_link);
|
||||
|
||||
// Children of active rubrique for catégorie filter (with links)
|
||||
$active_rubrique_id = $context['active_rubrique'];
|
||||
$is_direct = (bool) get_query_var('thalim_direct_posts');
|
||||
$lang = thalim_current_language();
|
||||
|
||||
$filter_categories = [];
|
||||
foreach ($all_cats as $cat) {
|
||||
if ($cat->parent == $active_rubrique_id) {
|
||||
$link = get_category_link($cat->term_id);
|
||||
if ($filter_query) $link .= '?' . $filter_query;
|
||||
$filter_categories[] = [
|
||||
'id' => $cat->term_id,
|
||||
'name' => thalim_cat_name($cat),
|
||||
'slug' => $cat->slug,
|
||||
'link' => $link,
|
||||
];
|
||||
}
|
||||
}
|
||||
$filter_categories = thalim_archive_filter_children($all_cats, $active_rubrique_id, $make_cat_link);
|
||||
|
||||
// Add "Autres" entry if the active rubrique has posts directly assigned to it
|
||||
if ($is_direct) {
|
||||
$has_direct_posts = true;
|
||||
} else {
|
||||
$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,
|
||||
]],
|
||||
]);
|
||||
$has_direct_posts = $direct_check->have_posts();
|
||||
}
|
||||
$has_direct_posts = $is_direct ?: thalim_rubrique_has_direct_posts($active_rubrique_id);
|
||||
if ($has_direct_posts && !empty($filter_categories)) {
|
||||
$autres_link = trailingslashit(get_category_link($active_rubrique_id)) . 'autres/';
|
||||
if ($filter_query) $autres_link .= '?' . $filter_query;
|
||||
$filter_categories[] = [
|
||||
'id' => 'autres',
|
||||
'name' => $lang === 'en' ? 'Other' : 'Autres',
|
||||
'slug' => 'autres',
|
||||
'link' => $autres_link,
|
||||
];
|
||||
$filter_categories[] = thalim_archive_autres_entry($autres_link);
|
||||
}
|
||||
|
||||
$context['filter_categories'] = $filter_categories;
|
||||
@@ -135,23 +92,23 @@ $children = get_categories([
|
||||
'exclude' => $excluded_ids,
|
||||
]);
|
||||
|
||||
// Ordre personnalisé des sous-catégories (term_id => position).
|
||||
// Ordre personnalisé des sous-catégories (slug => position).
|
||||
// Les termes absents du tableau sont placés en dernier (position 999).
|
||||
$subcategory_order = [
|
||||
// Publications et productions (parent: 4)
|
||||
15 => 0, // Ouvrages
|
||||
16 => 1, // Articles
|
||||
65 => 2, // Revues et collections
|
||||
17 => 3, // Multimédia
|
||||
// Activités (parent: 3)
|
||||
11 => 0, // Séminaires
|
||||
10 => 1, // Colloques et journées d'études
|
||||
13 => 2, // Communications
|
||||
14 => 3, // Soutenances
|
||||
// Publications et productions
|
||||
'ouvrages' => 0,
|
||||
'articles' => 1,
|
||||
'revues-et-collections' => 2,
|
||||
'multimedia' => 3,
|
||||
// Manifestations scientifiques
|
||||
'seminaires' => 0,
|
||||
'colloques-et-journees-detudes' => 1,
|
||||
'communications' => 2,
|
||||
'soutenances' => 3,
|
||||
];
|
||||
usort($children, function($a, $b) use ($subcategory_order) {
|
||||
$pos_a = $subcategory_order[$a->term_id] ?? 999;
|
||||
$pos_b = $subcategory_order[$b->term_id] ?? 999;
|
||||
$pos_a = $subcategory_order[$a->slug] ?? 999;
|
||||
$pos_b = $subcategory_order[$b->slug] ?? 999;
|
||||
return $pos_a - $pos_b;
|
||||
});
|
||||
|
||||
@@ -188,7 +145,6 @@ if (!$is_direct && !empty($children)) {
|
||||
'posts_per_page' => 3,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'lang' => '',
|
||||
'thalim_event_date_order' => true,
|
||||
], $extra_query_args);
|
||||
$posts = $sort_with_pinned( Timber::get_posts($query_args) );
|
||||
@@ -212,7 +168,6 @@ if (!$is_direct && !empty($children)) {
|
||||
'posts_per_page' => 3,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'lang' => '',
|
||||
'thalim_event_date_order' => true,
|
||||
], $extra_query_args);
|
||||
$direct_posts = $sort_with_pinned( Timber::get_posts($direct_query_args) );
|
||||
@@ -244,7 +199,6 @@ if (!$is_direct && !empty($children)) {
|
||||
'posts_per_page' => 12,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'lang' => '',
|
||||
'thalim_event_date_order' => true,
|
||||
], $extra_query_args);
|
||||
if ( $pinned_ids ) {
|
||||
@@ -259,7 +213,6 @@ if (!$is_direct && !empty($children)) {
|
||||
'post__in' => $pinned_ids,
|
||||
'orderby' => 'post__in',
|
||||
'posts_per_page' => -1,
|
||||
'lang' => '',
|
||||
], $extra_query_args ) ) : [];
|
||||
|
||||
$context['cards'] = thalim_get_cards_data($pinned_posts) + thalim_get_cards_data($posts);
|
||||
@@ -288,6 +241,6 @@ $context['agenda_toggle_url'] = add_query_arg( $toggle_params, $toggle_base );
|
||||
$cat_lang = thalim_current_language();
|
||||
$pres_fr = get_term_meta( $category->term_id, 'presentation', true ) ?: '';
|
||||
$pres_en = get_term_meta( $category->term_id, 'presentation_en', true ) ?: '';
|
||||
$context['term_presentation'] = wpautop( ( $cat_lang === 'en' && $pres_en ) ? $pres_en : $pres_fr );
|
||||
$context['term_presentation'] = wpautop( wp_kses_post( ( $cat_lang === 'en' && $pres_en ) ? $pres_en : $pres_fr ) );
|
||||
|
||||
Timber::render('category.twig', $context);
|
||||
|
||||
Reference in New Issue
Block a user