Third, installation (install/index.php)
This file is the installation page and you can see that the two constants are defined at the outset:
Define (' INSIDE ', true);
Define (' INSTALL ', true);
Because these two constants are always used in the next code, here's what to say first. Inside is used to prevent attacks; Install is used to record whether it is now in the process of installing the game.
Next, include two files: Extension.inc and Common, both of which are authentic PHP files. First extension.inc inside the code to prevent the attack, and the php file extension to hide, is this sentence $phpex = "php." Then ' common. ' $phpEx is actually common.php.
Includelang (' Install/install ');
This is the load language file, the Includelang () function is declared in the includes/unlocalised.php file, and there are a lot of small functions in the file.
function Includelang ($filename, $ext = '. Mo ') {
global $xnova _root_path, $lang, $user;
if ($user [' Lang ']!= ') {
$SelLanguage = $user [' Lang '];
} else {
$SelLanguage = Default_lang;
}
Include ($xnova _root_path. "language/". $SelLanguage. " /". $filename. $ext);
}
function is a user based on the language include the appropriate code, XNOVATC3 version is to support each user in a different language, I use the version does not have this function.
Go down and get the content of the page you want to display, which is how many steps to install; then enter a big switch. Before that, there was a statement like this:
$MainTPL = gettemplate (' install/ins_body ');
The GetTemplate () function is also declared in the includes/unlocalised.php file,
function GetTemplate ($templatename) {
global $xnova _root_path;
$filename = $xnova _root_path. Template_dir. Template_name. '/' . $templatename. ". TPL";
Return ReadFromFile ($filename);
function is to obtain the contents of a specified file, the specified file is composed of:
$ugamela _root_path. Template_dir. Template_name. '/' . $templatename. ". TPL";
The value of the Template_dir is ' templates/', the value of Template_name is ' opengame ', then the front gettemplate
(' Install/ins_body ') is to get the contents of the Templates/opengame/install/ins_body.tpl file. There are a few of these functions, and we have to remember that they are often used later.
Case ' intro ':
A look should know, is the description of the page, but there is a first time we see the function parsetemplate (), declared in the includes/unlocalised.php file,
function Parsetemplate ($template, $array) {return
preg_replace (' #\{(a-z0-9\-_]*?) \} #Ssie ', ' (isset ($array [\ ' \1\ ']) $array [\ ' \1\ ']: \ '); ', $template;
function is the function of the use of regular expressions, a specific string in the $template (that is, the contents of {}), with the value of $array to replace, to achieve multilingual functionality.
Case ' ins ':
This branch is the specific installation process, divided into 4 steps page, controlled by the $page variable to show which page.
1. When the $page value is 1 o'clock, make some error judgments, and if there is no error, read the TEMPLATES/INSTALL/INS_FORM.TPL template and parse the page that contains the server address, database name, table name prefix, user name and password. After the installer enters the data, click Install to enter the next process.
2. When the $page value is 2 o'clock, obtain the data entered in the first step and attempt to connect to the database, and if the database is not connected, prompt for an error, and the subsequent process of connecting to the database, including: Writing database connection information in the config.php file; according to includes/ Databaseinfos.php the contents of the file to create the table structure.
3. When the $page value is 3 o'clock, to determine if the previous step has been an error, not to show some information and parse out the creation of the Administrator account form, into the next process.
4. When the $page value is 4 o'clock, to obtain the data entered in the previous step, there are accounts, passwords, emails, etc. some judgments after the creation of this administrator account, the creation of the process after the registration details.
At this point, the installation of the main process is over, the main step is this, the code is not difficult to understand. Finally there is a function to explain, that is display (), declared in the includes/function.php file,
function display ($page, $title = ', $topnav = true, $metatags = ', $AdminPage = False) {
Global $link, $game _config , $debug, $user, $planetrow;
if (! $AdminPage) {
$DisplayPage = Stduserheader ($title, $metatags);
} else {
$DisplayPage = Adminuserheader ($title, $metatags);
}
if ($topnav) {
$DisplayPage. = Showtopnavigationbar ($user, $planetrow);
$DisplayPage. = "<center>\n". $page. " \n</center>\n ";
Affichage du Debug si necessaire
if ($user [' authlevel '] = = 1 | | $user [' authlevel '] = = 3) {
if ($game _config[') Debug '] = = 1) $debug->echo_log ();
}
$DisplayPage. = Stdfooter ();
if (Isset ($link)) {
@mysql_close ($link);
}
echo $DisplayPage;
Die ();
The function is to display the distinction between the normal user header and the administrator header, whether to display the top InfoBar, and so on, and other functions are called in this function, such as Stduserheader (), Adminuserheader (), Showtopnavigationbar (), and Stdfooter () is not complex, and its implementation is described in the previous parsetempalte () and GetTemplate (), here is not explained in detail.