clean nickname of players

This commit is contained in:
kremsy 2013-12-24 13:27:59 +01:00
parent dccc237c4f
commit 4bdf9d558a
3 changed files with 14 additions and 2 deletions

View File

@ -52,6 +52,15 @@ abstract class Formatter {
return date("Y-m-d H:i:s", $seconds); return date("Y-m-d H:i:s", $seconds);
} }
/**
* Strip all codes except colors from the string
*/
public static function stripCodesWithoutColors($string) {
$string = preg_replace('/(?<!\$)((?:\$\$)*)\$[^$0-9a-hlp]/iu', '$1', $string);
$string = self::stripLinks($string);
return $string;
}
/** /**
* Strip $codes from the string * Strip $codes from the string
* *
@ -61,7 +70,7 @@ abstract class Formatter {
public static function stripCodes($string) { public static function stripCodes($string) {
$string = preg_replace('/(?<!\$)((?:\$\$)*)\$[^$0-9a-hlp]/iu', '$1', $string); $string = preg_replace('/(?<!\$)((?:\$\$)*)\$[^$0-9a-hlp]/iu', '$1', $string);
$string = self::stripLinks($string); $string = self::stripLinks($string);
$string = self::stripColors($string); //$string = self::stripColors($string);
return $string; return $string;
} }

View File

@ -1,6 +1,7 @@
<?php <?php
namespace ManiaControl\Players; namespace ManiaControl\Players;
use ManiaControl\Formatter;
/** /**
* Class representing players * Class representing players
@ -42,7 +43,7 @@ class Player {
} }
$this->pid = $rpcInfos['PlayerId']; $this->pid = $rpcInfos['PlayerId'];
$this->login = $rpcInfos['Login']; $this->login = $rpcInfos['Login'];
$this->nickname = $rpcInfos['NickName']; $this->nickname = Formatter::stripCodesWithoutColors($rpcInfos['NickName']);
$this->path = $rpcInfos['Path']; $this->path = $rpcInfos['Path'];
$this->language = $rpcInfos['Language']; $this->language = $rpcInfos['Language'];
$this->avatar = $rpcInfos['Avatar']['FileName']; $this->avatar = $rpcInfos['Avatar']['FileName'];

View File

@ -18,6 +18,7 @@ use FML\Script\Tooltips;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
@ -135,6 +136,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
$i = 1; $i = 1;
$y -= 10; $y -= 10;
foreach($players as $listPlayer){ foreach($players as $listPlayer){
//$path = substr($listPlayer->path, 6); //$path = substr($listPlayer->path, 6);
//$path = $listPlayer->getCountry() . " - " . $listPlayer->getProvince(); //$path = $listPlayer->getCountry() . " - " . $listPlayer->getProvince();
$path = $listPlayer->getProvince(); $path = $listPlayer->getProvince();