<?php
if (!defined('access') || !access) {
	die();
}
$base = rtrim(__BASE_URL__, '/');

// Nexora community links are maintained from AdminCP > Website Configuration > Community Links.
$nexCommunityConfig = function_exists('loadConfig') ? loadConfig('social_links') : array();
if (!is_array($nexCommunityConfig)) $nexCommunityConfig = array();

// Backwards-compatible fallbacks for the three links already present in WebEngine settings.
$nexCommunityFallbacks = array(
	'discord' => function_exists('config') ? (string) config('social_link_discord', true) : '',
	'facebook' => function_exists('config') ? (string) config('social_link_facebook', true) : '',
	'youtube' => '',
	'instagram' => function_exists('config') ? (string) config('social_link_instagram', true) : '',
);

$nexCommunityLinks = array();
foreach (array('discord', 'facebook', 'youtube', 'instagram') as $network) {
	$url = isset($nexCommunityConfig[$network]) ? trim((string) $nexCommunityConfig[$network]) : '';
	if ($url === '' && isset($nexCommunityFallbacks[$network])) $url = trim($nexCommunityFallbacks[$network]);
	$scheme = $url !== '' ? strtolower((string) parse_url($url, PHP_URL_SCHEME)) : '';
	if ($url !== '' && filter_var($url, FILTER_VALIDATE_URL) && in_array($scheme, array('http', 'https'), true)) {
		$nexCommunityLinks[$network] = $url;
	}
}
?>
<footer class="nex-footer">
	<div class="nex-container nex-footer-inner">
		<div class="nex-footer-grid">
			<div class="nex-footer-brand">
				<a href="<?php echo $base; ?>/" class="nex-footer-logo">
					<img src="<?php echo __PATH_TEMPLATE_IMG__; ?>logo.webp" alt="<?php echo function_exists('config') ? htmlspecialchars(config('server_name', true), ENT_QUOTES, 'UTF-8') : ''; ?>" width="180" height="60" loading="lazy">
				</a>
				<p class="nex-footer-tagline"><?php echo function_exists('config') ? htmlspecialchars(config('website_meta_description', true), ENT_QUOTES, 'UTF-8') : ''; ?></p>
			</div>
			<div>
				<h3 class="nex-footer-title"><?php echo htmlspecialchars(nexora_lang('nexora_footer_info', 'Información'), ENT_QUOTES, 'UTF-8'); ?></h3>
				<ul class="nex-footer-links">
					<li><a href="<?php echo $base; ?>/news/"><?php echo function_exists('lang') ? htmlspecialchars(lang('news_txt_4', true), ENT_QUOTES, 'UTF-8') : 'Noticias'; ?></a></li>
					<li><a href="<?php echo $base; ?>/rankings/"><?php echo function_exists('lang') ? htmlspecialchars(lang('module_titles_txt_8', true), ENT_QUOTES, 'UTF-8') : 'Rankings'; ?></a></li>
					<li><a href="<?php echo $base; ?>/downloads/"><?php echo function_exists('lang') ? htmlspecialchars(lang('downloads_txt_1', true), ENT_QUOTES, 'UTF-8') : 'Descargas'; ?></a></li>
					<li><a href="<?php echo $base; ?>/tos/"><?php echo htmlspecialchars(nexora_lang('nexora_footer_terms', 'Términos y condiciones'), ENT_QUOTES, 'UTF-8'); ?></a></li>
				</ul>
			</div>
			<div>
				<h3 class="nex-footer-title"><?php echo htmlspecialchars(nexora_lang('nexora_footer_start', 'Cómo empezar'), ENT_QUOTES, 'UTF-8'); ?></h3>
				<ul class="nex-footer-links">
					<li><a href="<?php echo $base; ?>/register/"><?php echo function_exists('lang') ? htmlspecialchars(lang('menu_txt_3', true), ENT_QUOTES, 'UTF-8') : 'Registro'; ?></a></li>
					<li><a href="<?php echo $base; ?>/login/"><?php echo function_exists('lang') ? htmlspecialchars(lang('menu_txt_4', true), ENT_QUOTES, 'UTF-8') : 'Login'; ?></a></li>
					<li><a href="<?php echo $base; ?>/usercp/"><?php echo function_exists('lang') ? htmlspecialchars(lang('module_titles_txt_3', true), ENT_QUOTES, 'UTF-8') : 'Panel'; ?></a></li>
				</ul>
			</div>
			<div>
				<h3 class="nex-footer-title"><?php echo htmlspecialchars(nexora_lang('nexora_footer_social', 'Comunidad'), ENT_QUOTES, 'UTF-8'); ?></h3>
				<div class="nex-social">
					<?php if (isset($nexCommunityLinks['discord'])) { ?><a class="nex-soc nex-soc--dc" href="<?php echo htmlspecialchars($nexCommunityLinks['discord'], ENT_QUOTES, 'UTF-8'); ?>" target="_blank" rel="noopener noreferrer" aria-label="Discord" title="Discord"><span></span></a><?php } ?>
					<?php if (isset($nexCommunityLinks['facebook'])) { ?><a class="nex-soc nex-soc--fb" href="<?php echo htmlspecialchars($nexCommunityLinks['facebook'], ENT_QUOTES, 'UTF-8'); ?>" target="_blank" rel="noopener noreferrer" aria-label="Facebook" title="Facebook"><span></span></a><?php } ?>
					<?php if (isset($nexCommunityLinks['youtube'])) { ?><a class="nex-soc nex-soc--yt" href="<?php echo htmlspecialchars($nexCommunityLinks['youtube'], ENT_QUOTES, 'UTF-8'); ?>" target="_blank" rel="noopener noreferrer" aria-label="YouTube" title="YouTube"><span></span></a><?php } ?>
					<?php if (isset($nexCommunityLinks['instagram'])) { ?><a class="nex-soc nex-soc--ig" href="<?php echo htmlspecialchars($nexCommunityLinks['instagram'], ENT_QUOTES, 'UTF-8'); ?>" target="_blank" rel="noopener noreferrer" aria-label="Instagram" title="Instagram"><span></span></a><?php } ?>
				</div>
			</div>
		</div>
		<div class="nex-footer-bar">
			<span>© <?php echo date('Y'); ?> <?php echo function_exists('config') ? htmlspecialchars(config('server_name', true), ENT_QUOTES, 'UTF-8') : 'MU'; ?>. <?php echo htmlspecialchars(nexora_lang('nexora_rights', 'Todos los derechos reservados.'), ENT_QUOTES, 'UTF-8'); ?></span>
			<?php $handler->webenginePowered(); ?>
		</div>
		<p class="nex-footer-credit">
			<a class="nex-footer-credit-link" href="https://nexoravenetworks.com/" target="_blank" rel="noopener noreferrer"><?php echo htmlspecialchars(function_exists('nexora_lang') ? nexora_lang('nexora_credit_dev', 'By Nexora Ve Networks') : 'Nexora Ve Networks', ENT_QUOTES, 'UTF-8'); ?></a>
		</p>
	</div>
</footer>
