Propaganda
TD Member
Anyone with php experience? I have the code needs some tweaking to display properly on the site.
tags instead. When I change the tags the block doesn't display. I posted the code over at e07 forums and one guy said
"There is a lot of code that does not belong there.
For example indeed when u use [php] you should avoid <?php and ?>
Furthermore avoid html and body tags and rewrite the code to use internal e107 database classes."
Indeed the scripts does work as you can see [url]www.torontodarkly.ca/hlstatsx/top10.php[/url]
I would can simply add the code to a custom menu for it to display, or it can be written as a block. Anyway here's the code.
[code]<?php
/*
Script written by stachi
Contact: [email]stachi@gfbg-clan.de[/email]
Version: 1.3
No Copyright feel free to use and edit.
*/
define('IN_HLSTATS', true);
require('config.php');
require(INCLUDE_PATH . "/class_db.php");
require(INCLUDE_PATH . "/functions.php");
$db_classname = 'DB_' . DB_TYPE;
if ( class_exists($db_classname) ) {
$db = new $db_classname(DB_ADDR, DB_USER, DB_PASS, DB_NAME, DB_PCONNECT);
}else{
error('Database class does not exist. Please check your config.php file for DB_TYPE');
}
$game = 'css';
if ((isset($_GET['game'])) && (is_string($_GET['game'])))
$game = valid_request($_GET['game'], 0);
if ((isset($_GET['server_id'])) && (is_numeric($_GET['server_id'])))
$server_id = valid_request($_GET['server_id'], 1);
$background_color = '000000';
if (isset($_GET['bg_color']))
$background_color = valid_request($_GET['bg_color'], 0);
$color = 'ffffff';
if ((isset($_GET['color'])) && (is_string($_GET['color'])))
$color = valid_request($_GET['color'], 0);
$player_data_query = $db->query("
SELECT
lastName,
skill,
kills,
deaths,
playerId,
flag
FROM
hlstats_Players
WHERE
game='$game'
ORDER BY
skill desc
LIMIT
0,10");
if (empty($server_id)) {
$server_data_query = $db->query("
SELECT
IF(publicaddress != '', publicaddress, concat(address, ':', port)) AS addr,
publicaddress,
map_started,
act_map,
act_players,
max_players
FROM
hlstats_Servers
WHERE
game='$game'");
}else{
$server_data_query = $db->query("
SELECT
IF(publicaddress != '', publicaddress, concat(address, ':', port)) AS addr,
publicaddress,
map_started,
act_map,
act_players,
max_players
FROM
hlstats_Servers
WHERE
serverId='$server_id'");
}
$server_data = $db->fetch_array($server_data_query);
$maptime = time()-$server_data['map_started'];
$maptimehours = sprintf("%02d", floor($maptime / 3600));
$maptimemin = sprintf("%02d", floor(($maptime % 3600) / 60));
$maptimesec = sprintf("%02d", floor($maptime % 60));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[url]http://www.w3.org/1999/xhtml"[/url] lang="en" xml:lang="en" >
<head>
<title>TOP 10</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<style type="text/css">
<!--
a:link, a:visited, a:active {
font-size: 11px;
color: #<?php echo $color; ?>;
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
table {
background-color: #<?php echo $background_color; ?>;
color:#<?php echo $color; ?>;
font-size: 7pt;
width:210px;
}
.head {
height:125px;
background-image:url('hlstatsimg/top10.jpg');
}
-->
</style>
</head>
<body>
<table class="head" style="color:#000000; font-weight:bold; font-family:Verdana;" align="center">
<tr>
<td style="padding-right:0px; padding-left:6px; padding-top:29px;"><?php echo $server_data['act_map']; ?></td>
<td style="text-align:right; padding-right:6px; padding-top:29px;"><?php echo $maptimehours.':'.$maptimemin.':'.$maptimesec; ?></td>
</tr>
<tr>
<td style="padding-right:0px; padding-left:6px; padding-top:7px;"><?php echo $server_data['act_players'].'/'.$server_data['max_players']; ?></td>
</tr>
<tr>
<td style="padding-right:0px; padding-left:6px; padding-top:8px; padding-bottom:6px;"><?php echo '<a style="font-size:7pt; color:#000000;" href="steam://connect/'.$server_data['addr'].'">'.$server_data['addr'].'</a>'; ?></td>
</tr>
</table>
<table align="center">
<?php
$rank="0";
while($row = $db->fetch_array($player_data_query)) {
$flagge = $row['flag'];
if (empty($flagge))
$flagge="0";
$flagge = strtolower($flagge);
$row['flagge'] = '<img border="0" alt="'.$flagge.'" src="hlstatsimg/flags/'.$flagge.'.gif" />';
$iduser = $row['playerId'];
$row['nick'] = '<a target="_blank" href="hlstats.php?mode=playerinfo&player='.$iduser.'">'.$row['flagge'].$row['lastName'].'</a>';
$rank=$rank+1;
echo "<tr><td>".$rank.".</td><td>".$row['nick']."</td><td>".$row['skill']."</td></tr>";
}
?>
</table>
</body>
</html>[/code]
[php]
/*
Script written by stachi
Contact: [url="'javascript:window.location="mai"+"lto:"+"stachi"+"@"+"gfbg-clan.de";self.close();'"]-email-[/url]
Version: 1.3
No Copyright feel free to use and edit.
*/
define('IN_HLSTATS', true);
require('config.php');
require(INCLUDE_PATH . "/class_db.php");
require(INCLUDE_PATH . "/functions.php");
$db_classname = 'DB_' . DB_TYPE;
if ( class_exists($db_classname) ) {
$db = new $db_classname(DB_ADDR, DB_USER, DB_PASS, DB_NAME, DB_PCONNECT);
}else{
error('Database class does not exist. Please check your config.php file for DB_TYPE');
}
$game = 'css';
if ((isset($_GET['game'])) && (is_string($_GET['game'])))
$game = valid_request($_GET['game'], 0);
if ((isset($_GET['server_id'])) && (is_numeric($_GET['server_id'])))
$server_id = valid_request($_GET['server_id'], 1);
$background_color = '000000';
if (isset($_GET['bg_color']))
$background_color = valid_request($_GET['bg_color'], 0);
$color = 'ffffff';
if ((isset($_GET['color'])) && (is_string($_GET['color'])))
$color = valid_request($_GET['color'], 0);
$player_data_query = $db->query("
SELECT lastName, skill, kills, deaths, playerId, flag
FROM hlstats_Players
WHERE game='$game'
ORDER BY skill desc
LIMIT 0,10");
[/php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[url]http://www.w3.org/1999/xhtml"[/url] lang="en" xml:lang="en" >
<head>
<title>TOP 10</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<style type="text/css">
<!--
a:link, a:visited, a:active {
font-size: 11px;
color: #[php] echo $color; [/php];
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
table {
background-color: #[php] echo $background_color; [/php];
color:#[php] echo $color; [/php];
font-size: 7pt;
width:210px;
}
.head {
height:125px;
background-image:url('hlstatsimg/top10.jpg');
}
-->
</style>
</head>
<body>
<table align="center">
[php]
$rank="0";
while($row = $db->fetch_array($player_data_query))
{
$flagge = $row['flag'];
if (empty($flagge))
$flagge="0";
$flagge = strtolower($flagge);
$row['flagge'] = '<img border="0" alt="'.$flagge.'" src="hlstatsimg/flags/'.$flagge.'.gif" />';
$iduser = $row['playerId'];
$row['nick'] = '<a target="_blank" href="hlstats.php?mode=playerinfo&player='.$iduser.'">'.$row['flagge'].$row['lastName'].'</a>';
$rank=$rank+1;
echo "<tr><td>".$rank.".</td><td>".$row['nick']."</td><td>".$row['skill']."</td></tr>";
}
[/php]
</table>
</body>
</html>