Skip to content

Commit

Permalink
fix stripcolorname
Browse files Browse the repository at this point in the history
  • Loading branch information
HarpyWar committed Mar 9, 2019
1 parent 140751f commit bb66ed2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
4 changes: 3 additions & 1 deletion api.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
case "server":
$players = array();

if (!isset($_REQUEST['name'])) die('invalid server "name"');
$hostName = urldecode($_REQUEST['name']);
if ($hostName == '') die('error');
$hostName = $db->clean($hostName);
$res = $db->select('*','onServers',"WHERE serverName = '$hostName'");
foreach ($res as $row) {
Expand All @@ -50,6 +50,7 @@
$players = $db->select('id, serverName, playerName, p.playerID, nick, model, country, AllRating',
'onServers s','LEFT JOIN nfkLive_playerStats p ON p.name = s.playerName LEFT JOIN AltStat_Players a ON a.PlayerId = p.playerID WHERE s.playerName <> \'Null\' GROUP BY playerName,serverName ORDER BY id');

/*
$plrs = array();
foreach($players as $plr){
$plrs[$plr['serverName']][] = array(
Expand All @@ -63,6 +64,7 @@
);
}
$players_unique = array();
*/

$srvs = array();
foreach($servers as $srv){
Expand Down
23 changes: 9 additions & 14 deletions inc/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,22 @@ function GameTypeShortU($gt) {
}

function stripColor($nick) {
$pure = "";
$pure = "";
for ($i = 0; $i<strlen($nick); $i++ ) {
if (($nick[$i] != '^') && $i > 0 && ($nick[$i-1] != '^'))
$pure .= $nick[$i];
if ($nick[$i] == '^')
$i++;
else
$pure .= $nick[$i];
}
return $pure;
return html_entity_decode($pure);
}

/**
* Strip name colors
*/
function stripNameColor($nick)
{
for ($i = 0; $i<=strlen($nick); $i++ )
{
if (($nick[$i] != '^') and (!is_numeric($nick[$i+1])) )
if (($nick[$i-1] != '^') and (!is_numeric($nick[$i])) )
$pure .= $nick[$i];
}
//$pure = htmlspecialchars($pure);
return $pure;
return stripColor($nick);
}

/**
Expand Down Expand Up @@ -704,10 +699,10 @@ function getUserName($xdata) {
}

function getIcons($player, $profile = true, $flag = true, $ico = true, $colored = false) {
if ($player['author'] <> "") $player['name'] = $player['author'];
if (isset($player['author']) && $player['author'] <> "") $player['name'] = $player['author'];

if ($colored) {
if ($player['nick'] <> "") $plr_name = parseNameColor(clearName($player['nick'])); else $plr_name = clearName($player['name']);
if (isset($player['nick']) && $player['nick'] <> "") $plr_name = parseNameColor(clearName($player['nick'])); else $plr_name = clearName($player['name']);
} else $plr_name = clearName($player['name']);

if ($profile) {
Expand Down
14 changes: 2 additions & 12 deletions nplanet.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,8 @@
<?php

require_once("inc/config.inc.php");
require_once("inc/functions.inc.php");
require_once("mods/inc/nfk_planet.inc.php");
function stripNameColor($nick)
{
$pure = "";
for ($i = 0; $i < strlen($nick); $i++ )
{
if (($nick[$i] != '^') && $i > 0 && ($nick[$i-1] != '^'))
$pure .= $nick[$i];
}

return $pure;
}

function cmpServers($a, $b)
{
Expand Down Expand Up @@ -80,7 +70,7 @@ function cmpServers($a, $b)
foreach ($servers as $key => $server)
{
//preg_replace('/\W/', '', $a);
$hostlink = stripNameColor($server['Hostname']);
$hostlink = stripColor($server['Hostname']);
$hostlinkx = $hostlink;
$hostlink = str_replace("#", "%23", $hostlink);
//$link = ((substr($server["Hostname"], 0, 3) == "Rip") or (substr($server["Hostname"], 0, 9) == "[twuo.ru]")) ? ('<a target="_blank" href="/server/'.$hostlink.'">'.$hostlinkx.'</a>'):($hostlinkx);
Expand Down

0 comments on commit bb66ed2

Please sign in to comment.