Overview
What it does: Includes recent X-Connect zap rendering plus a separate random champion display utility currently placed in the same section.
Best use: Useful for showing recent social content and rotating champion callouts.
Template Usage
<?php get_recent_zaps($db, 3); ?>
Notes
Recent zaps pull from xconnect_zaps.
Hashtag styling is applied to content.
This section currently includes two unrelated utilities and may be worth splitting later.
Show Code
Full Function Code
function get_recent_zaps($db, $limit = 3) {
if (!is_numeric($limit) || $limit <= 0) $limit = 3;
$stmt = $db->prepare("
SELECT z.id, z.character_id, z.content, z.created_at, c.name
FROM xconnect_zaps z
JOIN characters c ON c.id = z.character_id
WHERE z.is_deleted = 0
ORDER BY z.created_at DESC
LIMIT ?
");
$stmt->bind_param("i", $limit);
$stmt->execute();
$result = $stmt->get_result();
while ($zap = $result->fetch_assoc()) {
$charId = (int)$zap['character_id'];
$charName = htmlspecialchars($zap['name']);
$avatar = "/render_character_image.php?character_id={$charId}&series_id=3";
$date = date("M j, Y", strtotime($zap['created_at']));
$content = trim($zap['content']);
$content = preg_replace('/\n{3,}/', "\n\n", $content);
$content = preg_replace('/#(\w+)/', '<span class="hashtag">#$1</span>', $content);
$content = preg_replace('/#(\w+)/', '<span class="hashtag">#$1</span>', $content);
echo <<<HTML
<div class="zap-mini-card">
<div class="zap-header-row">
<img src="{$avatar}" alt="{$charName}" class="zap-mini-avatar">
<div class="zap-header-text">
<div class="name-line"><strong>{$charName}</strong> <span class="date-line">{$date}</span></div>
</div>
</div>
<div class="zap-mini-content">{$content}</div>
</div>
HTML;
}
$stmt->close();
}
function displayRandomChamp() {
global $db;
$result = $db->query("SELECT * FROM titles WHERE active = 1 AND image_path IS NOT NULL");
$titles = [];
while ($row = $result->fetch_assoc()) {
$titles[] = $row;
}
if (empty($titles)) {
echo "No active titles found.";
return;
}
$selected = $titles[array_rand($titles)];
$titleImagePath = 'uploads/title-images/' . $selected['image_path'];
$titleName = $selected['name'];
$championId = $selected['current_champion_id'];
$championName = "Vacant";
$championImagePath = null;
if (!empty($championId)) {
$stmt = $db->prepare("
SELECT ci.image_file, c.name
FROM character_images ci
JOIN characters c ON c.id = ci.character_id
WHERE ci.character_id = ? AND ci.series_id = 3
ORDER BY ci.id ASC LIMIT 1
");
$stmt->bind_param("i", $championId);
$stmt->execute();
$stmt->bind_result($championImage, $championNameResult);
$stmt->fetch();
$stmt->close();
if (!empty($championNameResult)) {
$championName = $championNameResult;
}
if (!empty($championImage)) {
$championImagePath = 'images/characters/characters/' . $championImage;
}
}
$backgroundPath = 'images/characters/background/championship_bg.jpg';
$queryParams = [
'background' => $backgroundPath,
'title' => $titleImagePath
];
if (!empty($championImagePath)) {
$queryParams['champion'] = $championImagePath;
}
$renderUrl = '/render_random_champion.php?' . http_build_query($queryParams);
echo '<div class="cf-box">'
. '<a href="/champions" class="cf-box__link">'
. '<img src="' . htmlspecialchars($renderUrl) . '" alt="Random Champion">'
. '<div class="cf-badge cf-badge--topleft">CURRENT CHAMPION</div>'
. '<div class="cf-badge cf-badge--bottomright">'
. '<div class="badge-title">' . htmlspecialchars($titleName, ENT_QUOTES, 'UTF-8') . '</div>'
. '<div class="badge-champ">' . htmlspecialchars($championName, ENT_QUOTES, 'UTF-8') . '</div>'
. '</div>'
. '</a>'
. '</div>';
}