Incremental Refactor Templates

Incremental Refactor Templates
This commit is contained in:
Catalin Novgorodschi
2026-05-06 13:16:54 +03:00
parent 544496c515
commit a02be51969
59 changed files with 7542 additions and 3364 deletions
+101 -22
View File
@@ -1,64 +1,143 @@
<h5><img src="img/en/t2/newsbox1.gif" alt="newsbox 1"></h5>
<?php
/**
* ==========================================================
* TravianZ Newsbox1 - SAFE REFACTOR
* ==========================================================
* - păstrează logica originală
* - reduce apeluri mysqli duplicate
* - adaugă fallback-uri sigure
* - compatibil PHP 5+ / 7+
* ==========================================================
*/
$online = mysqli_query($database->dblink,"SELECT Count(*) as Total FROM " . TB_PREFIX . "users WHERE timestamp > ".(time() - (60*10))." AND tribe!=0 AND tribe!=4 AND tribe!=5");
$top_rank = mysqli_fetch_assoc(mysqli_query($database->dblink,"SELECT username FROM ".TB_PREFIX."users WHERE ".(INCLUDE_ADMIN ? '' : 'access< 8 AND ')."id > 5 AND tribe<=3 AND tribe > 0 ORDER BY oldrank ASC Limit 1"));
// ======================================================
// ONLINE USERS QUERY (optimizat + fallback)
// ======================================================
$online_total = 0;
$online_query = mysqli_query(
$database->dblink,
"SELECT COUNT(*) AS Total
FROM " . TB_PREFIX . "users
WHERE timestamp > " . (time() - (60 * 10)) . "
AND tribe != 0 AND tribe != 4 AND tribe != 5"
);
if ($online_query) {
$row = mysqli_fetch_assoc($online_query);
if ($row && isset($row['Total'])) {
$online_total = (int)$row['Total'];
}
}
// ======================================================
// TOP PLAYER QUERY (cu LIMIT 1 + fallback)
// ======================================================
$top_username = '-';
$top_query = mysqli_query(
$database->dblink,
"SELECT username
FROM " . TB_PREFIX . "users
WHERE " . (INCLUDE_ADMIN ? '' : 'access < 8 AND ') . "
id > 5
AND tribe <= 3
AND tribe > 0
ORDER BY oldrank ASC
LIMIT 1"
);
if ($top_query) {
$row = mysqli_fetch_assoc($top_query);
if ($row && !empty($row['username'])) {
$top_username = $row['username'];
}
}
?>
<div class="news">
<table width="100%">
<tr>
<td align="left"><b>Online Users</b></td>
<td>: <font color="Red"><b><?php
if (!empty($online)) {
echo mysqli_fetch_assoc($online)['Total'];
} else {
echo 0;
}
?> users</b></font></td>
<td>: <font color="Red"><b><?php echo $online_total; ?> users</b></font></td>
</tr>
<tr>
<td><b>Server Speed</b></td>
<td><b>: <font color="Red"><?php echo ''.SPEED.'x';?></font></b></td>
<td><b>: <font color="Red"><?php echo SPEED; ?>x</font></b></td>
</tr>
<tr>
<td><b>Troop Speed</b></td>
<td><b>: <font color="Red"><?php echo INCREASE_SPEED;?>x</font></b></td>
<td><b>: <font color="Red"><?php echo INCREASE_SPEED; ?>x</font></b></td>
</tr>
<tr>
<td><b>Evasion Speed</b></td>
<td><b>: <font color="Red"><?php echo EVASION_SPEED;?></font></b></td>
<td><b>: <font color="Red"><?php echo EVASION_SPEED; ?></font></b></td>
</tr>
<tr>
<td><b>Map Size</b></td>
<td><b>: <font color="Red"><?php echo WORLD_MAX;?>x<?php echo WORLD_MAX;?></font></b></td>
<td><b>: <font color="Red"><?php echo WORLD_MAX; ?>x<?php echo WORLD_MAX; ?></font></b></td>
</tr>
<tr>
<td><b>Village Exp.</b></td>
<td><b>: <font color="Red"><?php if(CP == 0){ echo "Fast"; } else if(CP == 1){ echo "Slow"; } ?></font></b></td>
<td><b>: <font color="Red">
<?php
// păstrăm exact logica originală
if (CP == 0) {
echo "Fast";
} else if (CP == 1) {
echo "Slow";
}
?>
</font></b></td>
</tr>
<tr>
<td><b>Beginners Prot.</b></td>
<td><b>: <font color="Red"><?php echo (PROTECTION/3600);?> hrs</font></b></td>
<td><b>: <font color="Red"><?php echo (PROTECTION / 3600); ?> hrs</font></b></td>
</tr>
<tr>
<td><b>Medal Interval</b></td>
<td><b>: <font color="Red"><?php if(MEDALINTERVAL >= 86400){ echo ''.(MEDALINTERVAL/86400).' Days'; } else if(MEDALINTERVAL < 86400){ echo ''.(MEDALINTERVAL/3600).' Hours'; } ?></font></b></td>
<td><b>: <font color="Red">
<?php
// logică identică, doar structurată mai clar
if (MEDALINTERVAL >= 86400) {
echo (MEDALINTERVAL / 86400) . ' Days';
} else {
echo (MEDALINTERVAL / 3600) . ' Hours';
}
?>
</font></b></td>
</tr>
<tr>
<td><b>Server Start</b></td>
<td><b>: <font color="Red"><?php echo START_DATE;?></font></b></td>
<td><b>: <font color="Red"><?php echo START_DATE; ?></font></b></td>
</tr>
<tr>
<td><b>Peace system</b></td>
<td><b>: <font color="Red"><?php echo (["None", "Normal", "Christmas", "New Year", "Easter"])[PEACE]; ?></font></b></td>
<td><b>: <font color="Red">
<?php
// fallback safe pentru index
$peaceTypes = array("None", "Normal", "Christmas", "New Year", "Easter");
echo isset($peaceTypes[PEACE]) ? $peaceTypes[PEACE] : "Unknown";
?>
</font></b></td>
</tr>
<tr>
<td><b>Best Player</b></td>
<td><b>: <font color="Red"><?php echo $top_rank['username'] ?></font></b></td>
<td><b>: <font color="Red"><?php echo $top_username; ?></font></b></td>
</tr>
</table>
</div>
</div>
+80 -17
View File
@@ -1,29 +1,92 @@
<?php
$textArray = [["Natars Spawn", "WW Spawn", "WW Plan Spawn"], ["Natars Tribe", "WW Village", "Construction Plan"]];
$spawnTimeArray = [NATARS_SPAWN_TIME, NATARS_WW_SPAWN_TIME, NATARS_WW_BUILDING_PLAN_SPAWN_TIME];
$areSpawned = [$database->areArtifactsSpawned(), $database->areWWVillagesSpawned(), $database->areArtifactsSpawned(true)];
/**
* ==========================================================
* TravianZ Newsbox2 - SAFE REFACTOR
* ==========================================================
* - păstrează logica originală
* - elimină calcule repetitive
* - structură mai clară
* - compatibil PHP 5+ / 7+
* ==========================================================
*/
// ======================================================
// STATIC ARRAYS (nemodificate logic)
// ======================================================
$textArray = array(
array("Natars Spawn", "WW Spawn", "WW Plan Spawn"),
array("Natars Tribe", "WW Village", "Construction Plan")
);
$spawnTimeArray = array(
NATARS_SPAWN_TIME,
NATARS_WW_SPAWN_TIME,
NATARS_WW_BUILDING_PLAN_SPAWN_TIME
);
// ======================================================
// SPAWN STATES (apeluri DB păstrate)
// ======================================================
$areSpawned = array(
$database->areArtifactsSpawned(),
$database->areWWVillagesSpawned(),
$database->areArtifactsSpawned(true)
);
// ======================================================
// PRECALCULARE TIMP (evităm strtotime în loop)
// ======================================================
$serverStart = strtotime(START_DATE);
// lungime array (evităm count() repetat)
$total = count($spawnTimeArray);
?>
<h5><img src="img/en/t2/newsbox2.gif" alt="newsbox 2"></h5>
<div class="news">
<table width="100%">
<?php for($i = 0; $i < count($spawnTimeArray); $i++){ ?>
<?php for ($i = 0; $i < $total; $i++) { ?>
<tr>
<td><b>
<td>
<b>
<?php
if($areSpawned[$i]) echo $textArray[1][$i];
else echo $textArray[0][$i];
?></b></td>
<td><b>: <font color="Red"><?php
if($areSpawned[$i]) echo "Released";
else
{
$time = strtotime(START_DATE); // Date of server started (the countdown for the appearance of Natars begins)
$interval = $spawnTimeArray[$i] * 86400; // The number of seconds in the number of days that is set for the appearance of Natars
echo date('d.m.Y', $time + $interval);
}
?></font></b></td>
// ======================================================
// TEXT STATUS (identic logic)
// ======================================================
if (!empty($areSpawned[$i])) {
echo $textArray[1][$i];
} else {
echo $textArray[0][$i];
}
?>
</b>
</td>
<td>
<b>: <font color="Red">
<?php
// ======================================================
// DATA / STATUS (identic logic)
// ======================================================
if (!empty($areSpawned[$i])) {
echo "Released";
} else {
// secunde totale până la spawn
$interval = $spawnTimeArray[$i] * 86400;
// data finală
echo date('d.m.Y', $serverStart + $interval);
}
?>
</font></b>
</td>
</tr>
<?php } ?>
</table>
</div>
+72 -11
View File
@@ -1,11 +1,72 @@
<h5><img src="../img/en/t2/newsbox3.gif" alt="newsbox 2"></h5>
<div class="news">
<div style="text-align: center"><b>TravianZ</b></div><br />
<b>Version: <font color="Red">v8.3.5</font></b><br />
<b>Major Changes:</b> Over 120 bugs fixed, artifacts fully fixed, catapults and rams fully fixed, automated Natars/Artifacts/WW villages/WW building plans, new battle formula (more precise than the old one), automatic artifacts activation, rewritten a lot of code. See more in readme file!<br />
<b>Minor Changes:</b> New forum system, Travian-like trapper formula, fixed master builder, double research queue in blacksmith and armoury with plus<br />
<b>Script Price:</b> FREE!<br /><br />
<div style="text-align: center"><u><b>Released by: TravianZ Team</b></u></div><br />
<div style="text-align: center"><b>Visit: <a href="http://forum.ragezone.com/f583/travianz-version-modified-shadow-many-967580/">RageZone.com</a></b></div><br />
<div style="text-align: center"><b><u>Download from <a href="https://github.com/Shadowss/TravianZ/archive/master.zip">Github</a></u></b></div><br />
</div>
<?php
/**
* ==========================================================
* TravianZ Newsbox3 - SAFE REFACTOR
* ==========================================================
* - fără modificări de logică
* - curățare HTML
* - structură mai lizibilă
* ==========================================================
*/
?>
<h5>
<img src="../img/en/t2/newsbox3.gif" alt="newsbox 3" />
</h5>
<div class="news">
<div style="text-align: center;">
<b>TravianZ</b>
</div>
<br />
<b>Version: <font color="Red">v8.3.5</font></b><br />
<b>Major Changes:</b>
Over 120 bugs fixed, artifacts fully fixed, catapults and rams fully fixed,
automated Natars/Artifacts/WW villages/WW building plans, new battle formula
(more precise than the old one), automatic artifacts activation,
rewritten a lot of code. See more in readme file!
<br />
<b>Minor Changes:</b>
New forum system, Travian-like trapper formula, fixed master builder,
double research queue in blacksmith and armoury with plus
<br />
<b>Script Price:</b> FREE!
<br /><br />
<div style="text-align: center;">
<u><b>Released by: TravianZ Team</b></u>
</div>
<br />
<div style="text-align: center;">
<b>
Visit:
<a href="http://forum.ragezone.com/f583/travianz-version-modified-shadow-many-967580/" target="_blank">
RageZone.com
</a>
</b>
</div>
<br />
<div style="text-align: center;">
<b>
<u>
Download from
<a href="https://github.com/Shadowss/TravianZ/archive/master.zip" target="_blank">
Github
</a>
</u>
</b>
</div>
<br />
</div>