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:
54
index.php
54
index.php
@@ -30,7 +30,6 @@ $annonces_raw = Timber::get_posts([
|
||||
]],
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'lang' => '',
|
||||
'thalim_event_date_order' => true,
|
||||
]);
|
||||
$context['annonces'] = $sort_with_pinned($annonces_raw, 'epingler_dans_le_diaporama_dannonces', $max_swiper);
|
||||
@@ -42,20 +41,19 @@ $publications_raw = Timber::get_posts([
|
||||
'posts_per_page' => 30,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'lang' => '',
|
||||
'tax_query' => [
|
||||
'relation' => 'AND',
|
||||
[
|
||||
'taxonomy' => 'category',
|
||||
'field' => 'term_id',
|
||||
'terms' => [4],
|
||||
'terms' => [ thalim_cat_id('publications') ],
|
||||
'operator' => 'IN',
|
||||
'include_children' => true,
|
||||
],
|
||||
[
|
||||
'taxonomy' => 'category',
|
||||
'field' => 'term_id',
|
||||
'terms' => [16],
|
||||
'terms' => [ thalim_cat_id('articles') ],
|
||||
'operator' => 'NOT IN',
|
||||
],
|
||||
],
|
||||
@@ -74,24 +72,34 @@ $publications_raw = Timber::get_posts([
|
||||
]);
|
||||
$context['publications'] = $sort_with_pinned($publications_raw, 'epingler_dans_le_diaporama_des_publications_et_productions', $max_swiper);
|
||||
$context['publications_cards'] = thalim_get_cards_data($publications_raw);
|
||||
$context['publications_link'] = thalim_en_url( get_category_link(4) );
|
||||
$context['annonces_link'] = thalim_en_url( get_permalink(29100) );
|
||||
$context['publications_link'] = thalim_en_url( get_category_link( thalim_cat_id('publications') ) );
|
||||
// Page « annonces » résolue par slug dans add_to_context() (annonces_url),
|
||||
// au lieu d'un get_permalink(29100) codé en dur (post potentiellement absent).
|
||||
$context['annonces_link'] = $context['annonces_url'];
|
||||
|
||||
// --- Message du laboratoire ---
|
||||
$messages_labo = Timber::get_posts([
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => 5,
|
||||
'cat' => 268,
|
||||
'cat' => thalim_cat_id('message-labo'),
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'lang' => '',
|
||||
]);
|
||||
$context['messages_labo'] = $messages_labo ?: [];
|
||||
$context['message_labo_link'] = thalim_en_url( get_category_link(268) );
|
||||
$context['message_labo_link'] = thalim_en_url( get_category_link( thalim_cat_id('message-labo') ) );
|
||||
|
||||
// --- Agenda (médiation scientifique + séances de séminaire à venir) ---
|
||||
$agenda_lang = thalim_current_language();
|
||||
$mediation_cat_ids = [5, 18, 19, 20, 21, 22, 23];
|
||||
// Catégories « agenda » résolues par slug (médiation + newsletter/gazette historiques)
|
||||
$mediation_cat_ids = array_values( array_filter( [
|
||||
thalim_cat_id('mediation'),
|
||||
thalim_cat_id('evenements-culturels'),
|
||||
thalim_cat_id('medias'),
|
||||
thalim_cat_id('newsletter'),
|
||||
thalim_cat_id('gazette'),
|
||||
thalim_cat_id('podcast'),
|
||||
thalim_cat_id('captations'),
|
||||
] ) );
|
||||
$months_fr = ['jan.', 'fév.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'];
|
||||
$months_en = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.'];
|
||||
$agenda_type_fields = [
|
||||
@@ -123,7 +131,6 @@ $mediation_upcoming = Timber::get_posts([
|
||||
'posts_per_page' => 8,
|
||||
'category__in' => $mediation_cat_ids,
|
||||
'orderby' => ['date_clause' => 'ASC'],
|
||||
'lang' => '',
|
||||
'meta_query' => [
|
||||
'date_clause' => [
|
||||
'key' => 'date_de_debut',
|
||||
@@ -150,13 +157,12 @@ foreach ($mediation_upcoming as $mpost) {
|
||||
if ($item) $agenda_items[] = $item;
|
||||
}
|
||||
|
||||
// 2. Upcoming séances de séminaire (cat 12)
|
||||
// 2. Upcoming séances de séminaire
|
||||
$seances_upcoming = Timber::get_posts([
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => 8,
|
||||
'category__in' => [12],
|
||||
'category__in' => [ thalim_cat_id('seance') ],
|
||||
'orderby' => ['date_clause' => 'ASC'],
|
||||
'lang' => '',
|
||||
'meta_query' => [
|
||||
'date_clause' => [
|
||||
'key' => 'date_de_debut',
|
||||
@@ -169,19 +175,7 @@ $seances_upcoming = Timber::get_posts([
|
||||
foreach ($seances_upcoming as $seance) {
|
||||
$raw_date = get_post_meta($seance->ID, 'date_de_debut', true);
|
||||
if (!$raw_date) continue;
|
||||
// Direct DB lookup — bypasses Polylang and other hook filters
|
||||
global $wpdb;
|
||||
$parent_id = $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT pm.post_id FROM {$wpdb->postmeta} pm
|
||||
JOIN {$wpdb->posts} p ON p.ID = pm.post_id
|
||||
WHERE pm.meta_key = 'seances' AND pm.meta_value = %s
|
||||
AND p.post_status = 'publish'
|
||||
LIMIT 1",
|
||||
(string) $seance->ID
|
||||
));
|
||||
$link = $parent_id
|
||||
? get_permalink((int) $parent_id) . '#seance-' . $seance->ID
|
||||
: get_permalink($seance->ID);
|
||||
$link = thalim_get_seance_link($seance->ID);
|
||||
$label = $agenda_lang === 'en' ? 'Seminar session' : 'Séance de séminaire';
|
||||
$item = $make_agenda_item($seance, $raw_date, $label, get_post_meta($seance->ID, 'lieu', true) ?: '', $link);
|
||||
if ($item) $agenda_items[] = $item;
|
||||
@@ -198,7 +192,6 @@ if (empty($agenda_items)) {
|
||||
'posts_per_page' => 5,
|
||||
'category__in' => $mediation_cat_ids,
|
||||
'orderby' => ['date_clause' => 'DESC'],
|
||||
'lang' => '',
|
||||
'meta_query' => [
|
||||
'date_clause' => ['key' => 'date_de_debut', 'type' => 'DATETIME'],
|
||||
],
|
||||
@@ -222,7 +215,7 @@ if (empty($agenda_items)) {
|
||||
}
|
||||
|
||||
$context['agenda_items'] = $agenda_items;
|
||||
$context['manifestations_link'] = thalim_en_url( add_query_arg( 'view', 'agenda', get_category_link(3) ) );
|
||||
$context['manifestations_link'] = thalim_en_url( add_query_arg( 'view', 'agenda', get_category_link( thalim_cat_id('manifestations') ) ) );
|
||||
|
||||
// --- Quick links ---
|
||||
$newsletter_cat = get_category_by_slug('newsletter');
|
||||
@@ -247,7 +240,7 @@ if ( ! $newsletter_url ) {
|
||||
);
|
||||
}
|
||||
$context['quick_links'] = [
|
||||
'agenda' => thalim_en_url(add_query_arg('view', 'agenda', get_category_link(3))),
|
||||
'agenda' => thalim_en_url(add_query_arg('view', 'agenda', get_category_link( thalim_cat_id('manifestations') ))),
|
||||
'contacts' => thalim_en_url(home_url('/contacts/')),
|
||||
'newsletter' => $newsletter_url,
|
||||
];
|
||||
@@ -257,7 +250,6 @@ $context['has_tags'] = !empty(get_terms([
|
||||
'taxonomy' => 'post_tag',
|
||||
'hide_empty' => true,
|
||||
'number' => 1,
|
||||
'lang' => '',
|
||||
]));
|
||||
|
||||
Timber::render('index.twig', $context);
|
||||
Reference in New Issue
Block a user