Initial commit

This commit is contained in:
2026-05-12 23:33:46 +02:00
commit ccf32dcece
104 changed files with 17439 additions and 0 deletions

263
index.php Executable file
View File

@@ -0,0 +1,263 @@
<?php
$context = Timber::context();
// Helper: split posts into active-pinned / normal and merge (pinned first, max_normal non-pinned)
$sort_with_pinned = function ($posts, string $pin_field, int $max_normal = PHP_INT_MAX) {
$today = date('Y-m-d');
$pinned = [];
$normal = [];
foreach ($posts as $post) {
$epingle = get_post_meta($post->ID, $pin_field, true);
$fin = get_post_meta($post->ID, 'date_de_fin_depinglage', true);
$active = $epingle == '1' && (empty($fin) || $fin === '0000-00-00' || $fin >= $today);
if ($active) { $pinned[] = $post; } else { $normal[] = $post; }
}
return array_merge($pinned, array_slice($normal, 0, $max_normal));
};
// --- Nombre d'items des diaporamas (depuis la page Le Laboratoire) ---
$labo_page = get_page_by_path('le-laboratoire');
$max_swiper = $labo_page ? intval(get_post_meta($labo_page->ID, 'nombres_ditems_des_diaporamas', true)) : 0;
if ($max_swiper < 1) $max_swiper = 10;
// --- Annonces diaporama ---
$annonces_raw = Timber::get_posts([
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => [[
'key' => 'afficher_dans_le_diaporama_dannonces_page_daccueil',
'value' => '1',
]],
'orderby' => 'date',
'order' => 'DESC',
'lang' => '',
'thalim_event_date_order' => true,
]);
$context['annonces'] = $sort_with_pinned($annonces_raw, 'epingler_dans_le_diaporama_dannonces', $max_swiper);
$context['annonces_cards'] = thalim_get_cards_data($annonces_raw);
// --- Publications et productions diaporama ---
$publications_raw = Timber::get_posts([
'post_type' => 'post',
'posts_per_page' => 30,
'orderby' => 'date',
'order' => 'DESC',
'lang' => '',
'tax_query' => [
'relation' => 'AND',
[
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => [4],
'operator' => 'IN',
'include_children' => true,
],
[
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => [16],
'operator' => 'NOT IN',
],
],
'meta_query' => [
'relation' => 'OR',
[
'key' => 'type_autre',
'value' => "Chapitre d'ouvrage",
'compare' => '!=',
],
[
'key' => 'type_autre',
'compare' => 'NOT EXISTS',
],
],
]);
$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) );
// --- Message du laboratoire ---
$messages_labo = Timber::get_posts([
'post_type' => 'post',
'posts_per_page' => 5,
'cat' => 268,
'orderby' => 'date',
'order' => 'DESC',
'lang' => '',
]);
$context['messages_labo'] = $messages_labo ?: [];
$context['message_labo_link'] = thalim_en_url( get_category_link(268) );
// --- 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];
$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 = [
'type_colloque_journee_d_etude', 'type_soutenance', 'type_evenement_culturel',
'type_media', 'type_captation', 'type_revue_collection', 'type_autre',
];
$now_str = date('Y-m-d H:i:s');
$make_agenda_item = function ($post, $raw_date, $type_label, $lieu, $link) use ($agenda_lang, $months_fr, $months_en) {
$ts = strtotime($raw_date);
if (!$ts) return null;
$month_idx = intval(date('n', $ts)) - 1;
return [
'post' => $post,
'ts' => $ts,
'day' => intval(date('j', $ts)),
'month' => $agenda_lang === 'en' ? $months_en[$month_idx] : $months_fr[$month_idx],
'type_label' => $type_label,
'lieu' => $lieu,
'link' => $link,
];
};
$agenda_items = [];
// 1. Upcoming médiation scientifique posts
$mediation_upcoming = Timber::get_posts([
'post_type' => 'post',
'posts_per_page' => 8,
'category__in' => $mediation_cat_ids,
'orderby' => ['date_clause' => 'ASC'],
'lang' => '',
'meta_query' => [
'date_clause' => [
'key' => 'date_de_debut',
'value' => $now_str,
'compare' => '>=',
'type' => 'DATETIME',
],
],
]);
foreach ($mediation_upcoming as $mpost) {
$raw_date = get_post_meta($mpost->ID, 'date_de_debut', true);
if (!$raw_date) continue;
$type_label = '';
foreach ($agenda_type_fields as $field) {
$val = get_post_meta($mpost->ID, $field, true);
if ($val) { $type_label = $val; break; }
}
if (!$type_label) {
foreach (get_the_category($mpost->ID) as $cat) {
if (in_array($cat->term_id, $mediation_cat_ids)) { $type_label = thalim_cat_name($cat); break; }
}
}
$item = $make_agenda_item($mpost, $raw_date, $type_label, get_post_meta($mpost->ID, 'lieu', true) ?: '', get_permalink($mpost->ID));
if ($item) $agenda_items[] = $item;
}
// 2. Upcoming séances de séminaire (cat 12)
$seances_upcoming = Timber::get_posts([
'post_type' => 'post',
'posts_per_page' => 8,
'category__in' => [12],
'orderby' => ['date_clause' => 'ASC'],
'lang' => '',
'meta_query' => [
'date_clause' => [
'key' => 'date_de_debut',
'value' => $now_str,
'compare' => '>=',
'type' => 'DATETIME',
],
],
]);
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);
$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;
}
// Sort merged list by date, keep 5 soonest
usort($agenda_items, fn($a, $b) => $a['ts'] <=> $b['ts']);
$agenda_items = array_slice($agenda_items, 0, 5);
// Fallback: if no upcoming events, show 5 most recent mediation events
if (empty($agenda_items)) {
$fallback = Timber::get_posts([
'post_type' => 'post',
'posts_per_page' => 5,
'category__in' => $mediation_cat_ids,
'orderby' => ['date_clause' => 'DESC'],
'lang' => '',
'meta_query' => [
'date_clause' => ['key' => 'date_de_debut', 'type' => 'DATETIME'],
],
]);
foreach ($fallback as $fpost) {
$raw_date = get_post_meta($fpost->ID, 'date_de_debut', true);
if (!$raw_date) continue;
$type_label = '';
foreach ($agenda_type_fields as $field) {
$val = get_post_meta($fpost->ID, $field, true);
if ($val) { $type_label = $val; break; }
}
if (!$type_label) {
foreach (get_the_category($fpost->ID) as $cat) {
if (in_array($cat->term_id, $mediation_cat_ids)) { $type_label = thalim_cat_name($cat); break; }
}
}
$item = $make_agenda_item($fpost, $raw_date, $type_label, get_post_meta($fpost->ID, 'lieu', true) ?: '', get_permalink($fpost->ID));
if ($item) $agenda_items[] = $item;
}
}
$context['agenda_items'] = $agenda_items;
$context['manifestations_link'] = thalim_en_url( add_query_arg( 'view', 'agenda', get_category_link(3) ) );
// --- Quick links ---
$newsletter_cat = get_category_by_slug('newsletter');
$newsletter_url = '';
if ($newsletter_cat) {
$nl_posts = get_posts([
'post_type' => 'post',
'posts_per_page' => 1,
'category__in' => [ $newsletter_cat->term_id ],
'include_children' => false,
'orderby' => 'date',
'order' => 'DESC',
'suppress_filters' => true,
]);
if ( ! empty( $nl_posts ) ) {
$newsletter_url = thalim_en_url( get_permalink( $nl_posts[0]->ID ) );
}
}
if ( ! $newsletter_url ) {
$newsletter_url = thalim_en_url(
$newsletter_cat ? get_category_link( $newsletter_cat->term_id ) : home_url( '/category/le-laboratoire/newsletter/' )
);
}
$context['quick_links'] = [
'agenda' => thalim_en_url(add_query_arg('view', 'agenda', get_category_link(3))),
'contacts' => thalim_en_url(home_url('/contacts/')),
'newsletter' => $newsletter_url,
];
// --- Tags (étiquettes) pour le nuage de mots-clés ---
$context['has_tags'] = !empty(get_terms([
'taxonomy' => 'post_tag',
'hide_empty' => true,
'number' => 1,
'lang' => '',
]));
Timber::render('index.twig', $context);