First step to namespaces

This commit is contained in:
Shoghi Cervantes
2014-03-05 23:43:16 +01:00
parent 23b8fc32ff
commit 5ea31b57ce
406 changed files with 3418 additions and 3597 deletions

View File

@ -19,7 +19,9 @@
*
*/
/***REM_START***/
namespace PocketMine\Wizard;
use PocketMine\Utils\Config as Config;
use PocketMine;
class Installer{
const DEFAULT_NAME = "Minecraft: PE Server";
@ -82,7 +84,7 @@ LICENSE;
}
private function generateBaseConfig(){
$config = new Config(DATA_PATH . "server.properties", Config::PROPERTIES);
$config = new Utils\Config(DATA . "server.properties", Utils\Config::PROPERTIES);
echo "[?] ".$this->lang->name_your_server." (".self::DEFAULT_NAME."): ";
$config->set("server-name", $this->getInput(self::DEFAULT_NAME));
echo "[*] ".$this->lang->port_warning."\n";
@ -122,13 +124,13 @@ LICENSE;
if($op === ""){
echo "[!] ".$this->lang->op_warning."\n";
}else{
$ops = new Config(DATA_PATH."ops.txt", Config::ENUM);
$ops = new Utils\Config(DATA."ops.txt", Utils\Config::ENUM);
$ops->set($op, true);
$ops->save();
}
echo "[*] ".$this->lang->whitelist_info."\n";
echo "[?] ".$this->lang->whitelist_enable." (y/N): ";
$config = new Config(DATA_PATH . "server.properties", Config::PROPERTIES);
$config = new Utils\Config(DATA . "server.properties", Utils\Config::PROPERTIES);
if(strtolower($this->getInput("n")) === "y"){
echo "[!] ".$this->lang->whitelist_warning."\n";
$config->set("white-list", true);
@ -139,7 +141,7 @@ LICENSE;
}
private function networkFunctions(){
$config = new Config(DATA_PATH . "server.properties", Config::PROPERTIES);
$config = new Utils\Config(DATA . "server.properties", Utils\Config::PROPERTIES);
echo "[!] ".$this->lang->query_warning1."\n";
echo "[!] ".$this->lang->query_warning2."\n";
echo "[?] ".$this->lang->query_disable." (y/N): ";
@ -153,7 +155,7 @@ LICENSE;
echo "[?] ".$this->lang->rcon_enable." (y/N): ";
if(strtolower($this->getInput("n")) === "y"){
$config->set("enable-rcon", true);
$password = substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10);
$password = substr(base64_encode(Utils\Utils::getRandomBytes(20, false)), 3, 10);
$config->set("rcon.password", $password);
echo "[*] ".$this->lang->rcon_password.": ".$password."\n";
}else{
@ -172,7 +174,7 @@ LICENSE;
echo "[*] ".$this->lang->ip_get."\n";
$externalIP = Utils::getIP();
$externalIP = Utils\Utils::getIP();
$internalIP = gethostbyname(trim(`hostname`));
echo "[!] ".$this->lang->get("ip_warning", array("{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"), array($externalIP, $internalIP))."\n";
@ -193,95 +195,4 @@ LICENSE;
}
}
class InstallerLang{
public static $languages = array(
"en" => "English",
"es" => "Español",
"zh" => "中文",
"ru" => "Pyccĸий",
"ja" => "日本語",
"de" => "Deutsch",
//"vi" => "Tiếng Việt",
"ko" => "한국어",
"fr" => "Français",
"it" => "Italiano",
//"lv" => "Latviešu",
"nl" => "Nederlands",
//"pt" => "Português",
"sv" => "Svenska",
"fi" => "Suomi",
"tr" => "Türkçe",
//"et" => "Eesti",
);
private $texts = array();
private $lang;
private $langfile;
public function __construct($lang = ""){
if(file_exists(FILE_PATH."src/lang/Installer/".$lang.".ini")){
$this->lang = $lang;
$this->langfile = FILE_PATH."src/lang/Installer/".$lang.".ini";
}else{
$l = glob(FILE_PATH."src/lang/Installer/".$lang."_*.ini");
if(count($l) > 0){
$files = array();
foreach($l as $file){
$files[$file] = filesize($file);
}
arsort($files);
reset($files);
$l = key($files);
$l = substr($l, strrpos($l, "/") + 1, -4);
$this->lang = isset(self::$languages[$l]) ? $l:$lang;
$this->langfile = FILE_PATH."src/lang/Installer/".$l.".ini";
}else{
$this->lang = "en";
$this->langfile = FILE_PATH."src/lang/Installer/en.ini";
}
}
$this->loadLang(FILE_PATH."src/lang/Installer/en.ini", "en");
if($this->lang !== "en"){
$this->loadLang($this->langfile, $this->lang);
}
}
public function getLang(){
return ($this->lang);
}
public function loadLang($langfile, $lang = "en"){
$this->texts[$lang] = array();
$texts = explode("\n", str_replace(array("\r", "\/\/"), array("", "//"), file_get_contents($langfile)));
foreach($texts as $line){
$line = trim($line);
if($line === ""){
continue;
}
$line = explode("=", $line);
$this->texts[$lang][array_shift($line)] = str_replace(array("\\n", "\\N",), "\n", implode("=", $line));
}
}
public function get($name, $search = array(), $replace = array()){
if(!isset($this->texts[$this->lang][$name])){
if($this->lang !== "en" and isset($this->texts["en"][$name])){
return $this->texts["en"][$name];
}else{
return $name;
}
}elseif(count($search) > 0){
return str_replace($search, $replace, $this->texts[$this->lang][$name]);
}else{
return $this->texts[$this->lang][$name];
}
}
public function __get($name){
return $this->get($name);
}
}
/***REM_END***/
}

View File

@ -0,0 +1,113 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace PocketMine\Wizard;
use PocketMine;
class InstallerLang{
public static $languages = array(
"en" => "English",
"es" => "Español",
"zh" => "中文",
"ru" => "Pyccĸий",
"ja" => "日本語",
"de" => "Deutsch",
//"vi" => "Tiếng Việt",
"ko" => "한국어",
"fr" => "Français",
"it" => "Italiano",
//"lv" => "Latviešu",
"nl" => "Nederlands",
//"pt" => "Português",
"sv" => "Svenska",
"fi" => "Suomi",
"tr" => "Türkçe",
//"et" => "Eesti",
);
private $texts = array();
private $lang;
private $langfile;
public function __construct($lang = ""){
if(file_exists(PATH."src/lang/Installer/".$lang.".ini")){
$this->lang = $lang;
$this->langfile = PATH."src/lang/Installer/".$lang.".ini";
}else{
$l = glob(PATH."src/lang/Installer/".$lang."_*.ini");
if(count($l) > 0){
$files = array();
foreach($l as $file){
$files[$file] = filesize($file);
}
arsort($files);
reset($files);
$l = key($files);
$l = substr($l, strrpos($l, "/") + 1, -4);
$this->lang = isset(self::$languages[$l]) ? $l:$lang;
$this->langfile = PATH."src/lang/Installer/".$l.".ini";
}else{
$this->lang = "en";
$this->langfile = PATH."src/lang/Installer/en.ini";
}
}
$this->loadLang(PATH."src/lang/Installer/en.ini", "en");
if($this->lang !== "en"){
$this->loadLang($this->langfile, $this->lang);
}
}
public function getLang(){
return ($this->lang);
}
public function loadLang($langfile, $lang = "en"){
$this->texts[$lang] = array();
$texts = explode("\n", str_replace(array("\r", "\/\/"), array("", "//"), file_get_contents($langfile)));
foreach($texts as $line){
$line = trim($line);
if($line === ""){
continue;
}
$line = explode("=", $line);
$this->texts[$lang][array_shift($line)] = str_replace(array("\\n", "\\N",), "\n", implode("=", $line));
}
}
public function get($name, $search = array(), $replace = array()){
if(!isset($this->texts[$this->lang][$name])){
if($this->lang !== "en" and isset($this->texts["en"][$name])){
return $this->texts["en"][$name];
}else{
return $name;
}
}elseif(count($search) > 0){
return str_replace($search, $replace, $this->texts[$this->lang][$name]);
}else{
return $this->texts[$this->lang][$name];
}
}
public function __get($name){
return $this->get($name);
}
}