mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-17 01:56:07 +00:00
Incremental Refactor Templates 3
Incremental Refactor Templates 2
This commit is contained in:
+161
-24
@@ -1,39 +1,176 @@
|
||||
<?php
|
||||
<?php
|
||||
#################################################################################
|
||||
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
||||
## --------------------------------------------------------------------------- ##
|
||||
## Filename links.tpl ##
|
||||
## Developed by: Slim, Manuel Mannhardt < manuel_mannhardt@web.de > ##
|
||||
## Developed by: Slim, Manuel Mannhardt ##
|
||||
## Refactored by: Shadow Incremental Refactor ##
|
||||
## License: TravianZ Project ##
|
||||
## Copyright: TravianZ (c) 2010-2025. All rights reserved. ##
|
||||
## ##
|
||||
## Refactor notes: ##
|
||||
## - păstrată logica originală 100% ##
|
||||
## - compatibil PHP 5.6+ / 7+ ##
|
||||
## - redus cod duplicat ##
|
||||
## - securizare output HTML ##
|
||||
## - protecție basic URL ##
|
||||
## - comentarii adăugate ##
|
||||
## ##
|
||||
#################################################################################
|
||||
|
||||
// Fetch all links
|
||||
$query = $database->getLinks($session->uid);
|
||||
if (mysqli_num_rows($query) > 0){
|
||||
$links = array();
|
||||
while($data = mysqli_fetch_assoc($query)) {
|
||||
$links[] = $data;
|
||||
/**
|
||||
* Escape HTML compatibil PHP vechi
|
||||
*/
|
||||
if (!function_exists('safeHTML')) {
|
||||
function safeHTML($string)
|
||||
{
|
||||
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
|
||||
print '<table cellpadding="1" cellspacing="1"><thead><tr><td colspan="3"><a href="spieler.php?s=2">Links:</a></td></tr></thead><tbody>';
|
||||
foreach($links as $link) {
|
||||
// Check, if the url is extern
|
||||
if(substr($link['url'], -1, 1) == '*') {
|
||||
$target = ' target="_blank"';
|
||||
$external = '<img src="gpack/travian_default/img/a/external.gif" />';
|
||||
$link['url'] = str_replace('*', '', $link['url']);
|
||||
} else {
|
||||
$target = '';
|
||||
$external = '';
|
||||
}
|
||||
/**
|
||||
* Verifică URL minim
|
||||
* Compatibil PHP vechi
|
||||
*/
|
||||
if (!function_exists('safeLinkUrl')) {
|
||||
function safeLinkUrl($url)
|
||||
{
|
||||
$url = trim($url);
|
||||
|
||||
echo '<tr><td class="dot">●</td><td class="link">';
|
||||
if($session->plus == 0) { echo "buy Plus"; } else {
|
||||
echo '<a href="' . $link['url'] . '"' . $target . '>' . $link['name'] . $external . '</a></td></tr>';
|
||||
// Blochează javascript:
|
||||
if (stripos($url, 'javascript:') === 0) {
|
||||
return '#';
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
print '</tbody></table>';
|
||||
|
||||
/**
|
||||
* Fetch links utilizator
|
||||
*/
|
||||
$query = $database->getLinks($session->uid);
|
||||
|
||||
/**
|
||||
* Verifică query valid
|
||||
*/
|
||||
if ($query && mysqli_num_rows($query) > 0) {
|
||||
|
||||
/**
|
||||
* Cache links
|
||||
*/
|
||||
$links = array();
|
||||
|
||||
while ($data = mysqli_fetch_assoc($query)) {
|
||||
$links[] = $data;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- ===================== PLAYER LINKS ===================== -->
|
||||
|
||||
<table cellpadding="1" cellspacing="1">
|
||||
|
||||
<thead>
|
||||
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<a href="spieler.php?s=2">Links:</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Render links
|
||||
*/
|
||||
foreach ($links as $link) {
|
||||
|
||||
/**
|
||||
* Normalizează date
|
||||
*/
|
||||
$linkName = isset($link['name'])
|
||||
? $link['name']
|
||||
: '';
|
||||
|
||||
$linkUrl = isset($link['url'])
|
||||
? $link['url']
|
||||
: '';
|
||||
|
||||
/**
|
||||
* Link extern
|
||||
* URL terminat în *
|
||||
*/
|
||||
$isExternal = false;
|
||||
|
||||
if (substr($linkUrl, -1) === '*') {
|
||||
|
||||
$isExternal = true;
|
||||
|
||||
// Elimină *
|
||||
$linkUrl = substr($linkUrl, 0, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Securizare URL
|
||||
*/
|
||||
$linkUrl = safeLinkUrl($linkUrl);
|
||||
|
||||
/**
|
||||
* Target extern
|
||||
*/
|
||||
$target = '';
|
||||
|
||||
if ($isExternal) {
|
||||
$target = ' target="_blank" rel="noopener noreferrer"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Icon extern
|
||||
*/
|
||||
$externalIcon = '';
|
||||
|
||||
if ($isExternal) {
|
||||
|
||||
$externalIcon = '<img src="gpack/travian_default/img/a/external.gif"
|
||||
alt="External"
|
||||
title="External" />';
|
||||
}
|
||||
?>
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="dot">●</td>
|
||||
|
||||
<td class="link">
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Fără PLUS
|
||||
*/
|
||||
if ((int)$session->plus == 0) {
|
||||
|
||||
echo 'buy Plus';
|
||||
|
||||
} else {
|
||||
|
||||
echo '<a href="' . safeHTML($linkUrl) . '"' . $target . '>'
|
||||
. safeHTML($linkName)
|
||||
. $externalIcon
|
||||
. '</a>';
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<?php } ?>
|
||||
Reference in New Issue
Block a user