欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP網(wǎng)頁游戲?qū)W習(xí)之Xnova(ogame)源碼解讀(二)

 更新時間:2014年06月23日 17:28:49   作者:鐵船長  
這篇文章主要介紹了PHP網(wǎng)頁游戲Xnova(ogame)源碼解讀的安裝文件源碼,需要的朋友可以參考下

三、 安裝(install/index.php)

這個文件是安裝頁面,一開始就可以看到定義了兩個常量:

define('INSIDE' , true);
define('INSTALL' , true); 


因?yàn)檫@兩個常量在接下來的代碼中總是用到,所以在這里先說明下。INSIDE是用來防止攻擊的;INSTALL是用來記錄現(xiàn)在是否處于安裝游戲的進(jìn)程中。

接下來Include兩個文件:extension.inc和common,這兩個都是正宗的php文件。首先extension.inc里面加入了防止攻擊的代碼,并且把php文件的擴(kuò)展名隱藏起來,就是這句$phpEx = “php”。那么'common.'.$phpEx其實(shí)就是common.php了。

includeLang('install/install'); 


這句是load語言文件,includeLang()函數(shù)聲明在includes/unlocalised.php文件中,這個文件中還有很多的小函數(shù)。

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);
} 

函數(shù)的功能是個根據(jù)用戶的所用的語種 include 相應(yīng)的代碼,XnovaTC3版本里面是支持每個用戶使用不同的語言的,我使用的版本無此功能。

繼續(xù)往下,取得當(dāng)前要顯示的頁面內(nèi)容,就是到了安裝步驟幾了;然后進(jìn)入一個大的switch。在這之前有一個這樣的語句:

$MainTPL = gettemplate('install/ins_body'); 

Gettemplate()函數(shù)同樣聲明在includes/unlocalised.php文件中,

function gettemplate ($templatename) {
 global $xnova_root_path;
 $filename = $xnova_root_path . TEMPLATE_DIR . TEMPLATE_NAME . '/' . $templatename . ".tpl";
 return ReadFromFile($filename);
} 

函數(shù)的功能是取得一個指定文件的內(nèi)容,這個指定的文件是這樣構(gòu)成的:

$ugamela_root_path . TEMPLATE_DIR . TEMPLATE_NAME . '/' . $templatename . ".tpl"; 

TEMPLATE_DIR的值是'templates/',TEMPLATE_NAME的值是'OpenGame',那么前面的 gettemplate

('install/ins_body')就是取得templates/OpenGame/install/ins_body.tpl文件中的內(nèi)容。這樣的函數(shù)還有幾個,大家都要記住,后面會經(jīng)常用到。

case ‘intro':

一看就應(yīng)該知道,是說明介紹的頁面,不過里面有個我們首次見到的函數(shù)parsetemplate(),聲明在includes/unlocalised.php文件中,

function parsetemplate ($template, $array) {
return preg_replace('#\{([a-z0-9\-_]*?)\}#Ssie', '( ( isset($array[\'\1\']) ) ? $array[\'\1\'] : \'\' );', $template);
} 

函數(shù)的功能是利用正則表達(dá)式,對$template中的特定字符串(就是由 {} 括起來的內(nèi)容),用$array的值進(jìn)行替換,來實(shí)現(xiàn)多語言功能。

case ‘ins':

這個分枝是具體安裝過程,分成4個步驟頁面,由$page變量控制顯示哪一個頁面。

1. 當(dāng)$page值為1時,先進(jìn)行一些錯誤判斷;如果沒有錯誤,就讀取 templates/install/ins_form.tpl模板,parse出并構(gòu)成有服務(wù)器地址、數(shù)據(jù)庫名、表名前綴、用戶名和密碼的頁面。安裝者輸入數(shù)據(jù)后,點(diǎn)擊install進(jìn)入下一步的流程。

2. 當(dāng)$page值為2時,取得第一步輸入的數(shù)據(jù),并嘗試連接數(shù)據(jù)庫;如果連接不上數(shù)據(jù)庫則提示錯誤;連上數(shù)據(jù)庫則繼續(xù)后續(xù)的過程,包括:在config.php文件中寫入數(shù)據(jù)庫連接信息;根據(jù)includes/databaseinfos.php文件內(nèi)容創(chuàng)建表結(jié)構(gòu)。

3. 當(dāng)$page值為3時,判斷上一步是否發(fā)生錯誤,沒有發(fā)生則顯示一些信息并parse出創(chuàng)建管理員帳號的表單,進(jìn)入下一個流程。

4. 當(dāng)$page值為4時,取得上一步輸入的數(shù)據(jù),有帳號、密碼、email等;一些判斷之后創(chuàng)建這個管理員帳號,創(chuàng)建的過程以后注冊的時候再詳細(xì)說明。

至此,安裝主要過程就結(jié)束了,主要步驟就是這些,代碼也不難理解。最后還有一個函數(shù)要講解下,就是display(),聲明在includes/function.php文件中,

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();
} 

函數(shù)的功能是顯示普通用戶頁眉和管理員頁眉的區(qū)分,是否顯示頂部的信息欄等,此函數(shù)中還調(diào)用了其他函數(shù),如:StdUserHeader()、AdminUserHeader()、ShowTopNavigationBar()和 StdFooter()都不復(fù)雜,其實(shí)現(xiàn)都是前面介紹過的 parsetempalte()和gettemplate(),這里就不詳細(xì)說明了。

相關(guān)文章

最新評論