38443-vm/index.php_partial_fix
2026-02-20 23:46:55 +00:00

104 lines
9.9 KiB
Plaintext

<?php if (!empty($m['metadata'])):
$meta = json_decode($m['metadata'], true);
if ($meta):
$borderColor = htmlspecialchars($meta['color'] ?? 'var(--blurple)');
if (!empty($meta['is_poll'])):
?>
<div class="poll-container rich-embed mt-2 p-3 rounded" style="border-left: 4px solid <?php echo $borderColor; ?>;">
<div class="embed-site-name mb-1" style="font-size: 0.75em; color: var(--text-muted); text-transform: uppercase; font-weight: bold;">📊 SONDAGE</div>
<?php if (!empty($meta['title'])): ?>
<div class="embed-title d-block mb-1" style="font-weight: 600; color: #00a8fc; font-size: 1.1em;"><?php echo htmlspecialchars($meta['title']); ?></div>
<?php endif; ?>
<?php if (!empty($meta['description'])): ?>
<div class="embed-description mb-2" style="font-size: 0.9em; color: var(--text-normal); max-height: 100px; overflow: hidden; position: relative;"><?php echo parse_markdown($meta['description']); ?></div>
<div class="read-more-btn small mb-2" style="display: none; cursor: pointer; color: var(--blurple); font-weight: 600;">Voir plus</div>
<?php endif; ?>
<div class="poll-options-list">
<?php
$total_votes = 0;
if (isset($m['votes_data'])) {
foreach($m['votes_data'] as $v) $total_votes += $v['vote_count'];
}
$options = $meta['options'] ?? [];
foreach($options as $idx => $opt):
$count = 0;
$user_voted = false;
if (isset($m['votes_data'])) {
foreach($m['votes_data'] as $v) {
if ($v['option_index'] == $idx) {
$count = $v['vote_count'];
$user_ids = explode(',', $v['user_ids'] ?? '');
if (in_array($current_user_id, $user_ids)) {
$user_voted = true;
}
break;
}
}
}
$percent = $total_votes > 0 ? round(($count / $total_votes) * 100) : 0;
$is_expired = !empty($meta['end_date']) && strtotime($meta['end_date']) < time();
?>
<div class="poll-option <?php echo $user_voted ? 'voted' : ''; ?> <?php echo $is_expired ? 'expired' : ''; ?>" data-message-id="<?php echo $m['id']; ?>" data-option-index="<?php echo $idx; ?>">
<div class="poll-progress-container">
<div class="poll-progress-bar" style="width: <?php echo $percent; ?>%"></div>
<span class="poll-option-text"><?php echo htmlspecialchars($opt); ?></span>
<span class="poll-option-percent"><?php echo $percent; ?>% (<?php echo $count; ?>)</span>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="poll-footer mt-2" style="font-size: 0.75em; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center;">
<span><?php echo $total_votes; ?> vote<?php echo $total_votes > 1 ? 's' : ''; ?> · <?php echo ($meta['choice_type'] ?? 'single') === 'multiple' ? 'Plusieurs choix' : 'Choix unique'; ?></span>
<?php if (!empty($meta['end_date'])): ?>
<span class="poll-deadline <?php echo $is_expired ? 'text-danger' : ''; ?>">
<?php echo $is_expired ? 'Terminé' : 'Expire le ' . date('d/m/Y H:i', strtotime($meta['end_date'])); ?>
</span>
<?php endif; ?>
</div>
</div>
<?php else: ?>
<div class="rich-embed mt-2 p-3 rounded" style="background: rgba(0,0,0,0.1); border-left: 4px solid <?php echo $borderColor; ?>; max-width: 520px;">
<?php if (!empty($meta['site_name']) && empty($meta['is_rss']) && empty($meta['is_manual_announcement'])): ?>
<div class="embed-site-name mb-1" style="font-size: 0.75em; color: var(--text-muted); text-transform: uppercase; font-weight: bold;"><?php echo htmlspecialchars($meta['site_name']); ?></div>
<?php endif; ?>
<?php if (!empty($meta['title'])): ?>
<?php if (!empty($meta['url'])): ?>
<a href="<?php echo htmlspecialchars($meta['url']); ?>" target="_blank" class="embed-title d-block mb-1 text-decoration-none" style="font-weight: 600; color: #00a8fc; font-size: 1.1em;"><?php echo htmlspecialchars($meta['title']); ?></a>
<?php else: ?>
<div class="embed-title d-block mb-1" style="font-weight: 600; color: #00a8fc; font-size: 1.1em;"><?php echo htmlspecialchars($meta['title']); ?></div>
<?php endif; ?>
<?php endif; ?>
<?php if (!empty($meta['is_rss'])): ?>
<div class="embed-meta mb-2" style="font-size: 0.8em; color: var(--text-muted);">
<?php
$parts = [];
if (!empty($meta['category'])) $parts[] = htmlspecialchars($meta['category']);
if (!empty($meta['date'])) $parts[] = htmlspecialchars($meta['date']);
if (!empty($meta['author'])) $parts[] = htmlspecialchars($meta['author']);
echo implode(' · ', $parts);
?>
</div>
<?php endif; ?>
<?php if (!empty($meta['is_manual_announcement'])): ?>
<div class="embed-meta mb-2" style="font-size: 0.8em; color: var(--text-muted);">
<?php echo date('d/m/Y H:i', strtotime($m['created_at'])); ?>
</div>
<?php endif; ?>
<?php if (!empty($meta['description'])): ?>
<div class="embed-description mb-2" style="font-size: 0.9em; color: var(--text-normal); max-height: 100px; overflow: hidden; position: relative;"><?php echo parse_markdown($meta['description']); ?></div>
<div class="read-more-btn small mb-2" style="display: none; cursor: pointer; color: var(--blurple); font-weight: 600;">Voir plus</div>
<?php endif; ?>
<?php if (!empty($meta['is_manual_announcement']) && !empty($meta['url'])): ?>
<div class="embed-footer mt-2">
<a href="<?php echo htmlspecialchars($meta['url']); ?>" target="_blank" class="btn btn-sm btn-outline-info" style="font-size: 0.8em;">Source / En savoir plus</a>
</div>
<?php endif; ?>
<?php if (!empty($meta['image'])): ?>
<div class="embed-image">
<img src="<?php echo htmlspecialchars($meta['image']); ?>" class="rounded" style="max-width: 100%; max-height: 300px; object-fit: contain;">
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; endif; ?>