Código PHP:
<?php
/**
* @project Flame MU Web
* @author Renato Valer
* @package MuOnline\Service
*/
namespace MuOnline\Service;
class settingsManagement
{
private $file;
private $newfile;
private $content;
private $varsKeys = array();
private $constantsKeys = array();
private $constants = array();
private $vars = array();
public function __construct($file) {
$this->file = $file;
$this->newfile = $file.'.txt';
copy($this->file, $this->newfile);
$this->content = file_get_contents($this->newfile);
$this->content = str_replace('<?php', '', $this->content);
$this->content = trim($this->content);
$this->content = preg_replace('%/\s*\*\s.*?\*/\s*%s', '', $this->content);
$this->content = preg_replace('%(#|(//)).*%', '', $this->content);
$this->saveConstants();
$this->saveVars();
}
public function getVars() {
return $this->vars;
}
public function getConstants() {
return $this->constants;
}
public function setVars($key, $value) {
$this->vars[$key] = $value;
}
public function setConstant($key, $value) {
$this->constants[$key] = $value;
}
private function saveVars() {
$content = explode('$app->offsetSet', $this->content);
array_shift($content);
$vars = array();
foreach($content as $key => $value) {
if(empty(trim($value))) {
continue;
} else {
$split = preg_split("/\'([^\']*)\',/", $value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
if (array_key_exists(1, $split)) {
$vars[] = $split[1];
}
}
}
$this->varsKeys = $vars;
}
private function saveConstants() {
$content = explode('define', $this->content);
$constants = array();
foreach($content as $key => $value) {
if(empty(trim($value))) {
continue;
} else {
$split = preg_split("/\'([^\']*)\',/", $value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
if (array_key_exists(1, $split)) {
$constants[] = $split[1];
}
}
}
$this->constantsKeys = $constants;
}
private function arrayToString($array) {
$stringArray = "array(";
$i = 1;
$count = count($array);
foreach($array as $key => $value) {
$c = $i++;
if(is_array($value)) {
if(is_string($key)) {
$stringArray .= "'".$key."' => ".$this->arrayToString($value).")";
} else {
$stringArray .= $key." => ".$this->arrayToString($value).")";
}
} else {
if(is_bool($value)) {
$value === true ? $bool = 'true' : $bool = 'false';
$stringArray .= "'".$key."' => ".$bool."";
} elseif(is_string($key)) {
$stringArray .= "'".$key."' => '".$value."'";
} else {
$stringArray .= $key." => '".$value."'";
}
}
if($c < $count) {
$stringArray .= ", ";
}
}
return $stringArray;
}
public function rewrite() {
require($this->file);
$content = '<?php';
foreach($this->constantsKeys as $key => $value) {
true === isset($this->constants[$value]) ? $val = $this->constants[$value] : $val = constant($value);
if(is_bool($val)) {
$val === true ? $bool = 'true' : $bool = 'false';
$content .= sprintf("\r\n define('%s', %s);", $value, $bool);
} elseif(is_null($value)) {
$content .= sprintf("\r\n define('%s', %s);", $value, 'null');
} else {
$content .= sprintf("\r\n define('%s', '%s');", $value, $val);
}
}
foreach($this->varsKeys as $key => $value) {
true === isset($this->vars[$value]) ? $val = $this->vars[$value] : $val = $app->offsetGet($value);
$content .= "\r\n $";
$content .= "app->offsetSet('".$value."', ";
if(is_array($val)) {
$content .= $this->arrayToString($val);
$content .= "));";
} else {
$content .= $val."));";
}
}
$content .= "\r\n\r\n";
unlink($this->file);
unlink($this->newfile);
try {
$fp = fopen($this->file, 'w+');
fwrite($fp, $content);
fclose($fp);
} catch(\Exception $e) {
return $e->getMessage();
}
}
}
Settings.php que utilizei (só para verem como era)
Código PHP:
<?php
/*
@Configuração do debug
ATENÇÃO!
Tome muito cuidado com essa configuração.
NUNCA USE o debug ativo em ambiente de produção, use apenas em ambiente de teste,
pois com debug ativo até mesmo a senha do banco de dados pode ser exposta.
*/
define('DEBUG_MODE', true); // true or false
/*
@Configurações do banco de dados
*/
define('DRIVER', 'sqlsrv');
define('HOST', '(local)'); //Host do Banco de dados
define('USER', 'sa'); //Login do Mssql
define('PASSWORD', '1234'); //Senha do Mssql
define('PORT', 1433); //Porta do Mssql
define('DATABASE', 'MuOnline'); //Banco de dados do website
define('DATABASE_ACCOUNTS', 'MuOnline'); //Banco de dados onde ficam as contas
define('DATABASE_CHARACTERS', 'MuOnline'); //Banco de dados onde ficam os personagens
/*
@Configurações de templates
*/
define('TEMPLATE', 'flamemuweb');
define('TEMPLATE_CACHE', false);
/*
@Configurações primárias
*/
define('TITLE_SITE', 'MuOnline Server - Logo do servidor.'); //Titulo - Nome do servidor
define('SERVER_NAME', 'MuOnline Server'); //Nome do servidor
define('SERVER_SLOGAN', 'Servidor 24 horas'); //Slogan do servidor
define('SERVER_VERSION', 'Season 8.3'); //Versão do servidor
define('SERVER_DROP', '20%'); //Drop do servidor
define('SERVER_XP', '100x'); //Xp do servidor
define('SERVER_BUGBLESS', 'Online'); //Bugbless status
define('SHOPPING_LINK', '#LinkShop'); //Link do shopping
define('CASH_NAME', 'Golds'); //Nome da moeda primeira moeda
define('CASH_NAME2', 'Cashs'); //Nome da moeda segunda moeda
define('POINTS_NAME', 'Pontos'); //Nome da moeda de ponto
define('DISABLE_BASIC_INFOS', false); //Desligar a busca de: Total de contas, personagens, vips, contas e personagens banidos
/*
@Na linha abaixo, coloque:
0 para Season 1 ou Abaixo - Sem DL
1 para Season 1 ou Abaixo
2 para Season 2
3 para Season 3 Episodio
4 para Season 3 Episodio 2, Até Season 5
5 para Season 6
6 para Season 6.2 ou acima
*/
define('MUSERVER_VERSION', 5); //Veja como preencher na descrição acima.
/*
@Configurações de Tabelas e Colunas
*/
$app->offsetSet('tables', array(
'currency' => array(
'table' => 'CashShopData', /* MEMB_INFO ou outra */
'id' => 'AccountID', /* se for tabela MEMB_INFO, use memb___id */
'currencies' => array(
0 => array(
'name' => 'Gold',
'column' => 'WCoinC'
),
1 => array(
'name' => 'Cash',
'column' => 'WCoinP'
),
2 => array(
'name' => 'Point',
'column' => 'GoblinPoint'
)
)
)
));
/*
@Configurações de Rankings
*/
$app->offsetSet('rankings', array(
array(
0 => array(
'name' => 'Level',
'exibition' => array('Nome', 'Level', 'Resets'),
'system' => array('table' => 'Character', 'columns' => array('Name', 'cLevel', 'ResetCount'), 'orderBy' => array('cLevel' => 'DESC', 'ResetCount' => 'DESC'))
),
1 => array(
'name' => 'Resets',
'exibition' => array('Nome', 'Resets', 'Level'),
'system' => array('table' => 'Character', 'columns' => array('Name', 'ResetCount', 'cLevel'), 'orderBy' => array('ResetCount' => 'DESC', 'cLevel' => 'DESC'))
),
2 => array(
'name' => 'Master Resets',
'exibition' => array('Nome', 'Master Resets', 'Resets', 'Level'),
'system' => array('table' => 'Character', 'columns' => array('Name', 'MasterResetCount', 'ResetCount', 'cLevel'), 'orderBy' => array('MasterResetCount' => 'DESC', 'ResetCount' => 'DESC', 'cLevel' => 'DESC'))
)
)
));
/*
@Configurações Cadastro
*/
$app->offsetSet('register', array(
'registerLogged' => false,
'emailConfirm' => false,
'emailRepeat' => false,
'bonus' => array(
'vip' => array(
'active' => true,
'type' => 1,
'days' => 3
),
'amount' => array(
'zen' => 0,
'currencies' => array(
0 => 0,
1 => 0,
2 => 0
)
),
'item' => array(
'active' => false
)
)
));
/*
@Configurações Downloads
*/
$app->offsetSet('downloads', array(
array('name' => 'Client Full', 'description' => 'Client completo', 'size' => '200Mb', 'link' => 'http://www.mediafire.com')
));
$app->offsetSet('accountPlans', array(
'free' => array('name' => 'Free'),
'vips' => array(
0 => array(
'name' => 'Vip Silver',
'active' => true,
'prices' => array(
10 => 5,
20 => 10,
30 => 20
)
),
1 => array(
'name' => 'Vip Gold',
'active' => true,
'prices' => array(
10 => 5,
20 => 10,
30 => 20
)
),
2 => array(
'name' => 'Vip Diamante',
'active' => true,
'prices' => array(
10 => 5,
20 => 10,
30 => 20
)
),
3 => array(
'name' => 'Vip Plus',
'active' => true,
'prices' => array(
10 => 5,
20 => 10,
30 => 20
)
)
)
));
Para utilizar, basta chamar a função construtora, informando o arquivo a ser editado, depois, por meio das funções setVars e SetConstant, modificar as variáveis/contantes que quiser e, por fim, chamar a função rewrite.