天天看點

phpwind源碼解析------index.php

phpwind的功能很強悍,設計理念也非常不錯,但代碼寫得有些亂,不過可能是php本身的特點導緻,讓我們這些寫慣了java的開發人員看起來極不習慣,并且源碼裡的注釋少得可憐,隻能自己邊看邊加了,今天看了看了根目錄下的index.php,帶注釋的源碼如下:

<?php

define('SCR','index');

require_once('global.php');

include_once(D_P.'data/bbscache/cache_index.php');

include_once(D_P.'data/bbscache/forum_cache.php');

//notice

//公告處理

$noticedb = array();

foreach ($notice_A as $value) {

if ($value['startdate']<=$timestamp && (!$value['enddate'] || $value['enddate']>=$timestamp)) {

$value['startdate'] = $value['stime'] ? $value['stime'] : get_date($value['startdate'],'y-m-d');

!$value['url'] && $value['url'] = 'notice.php#'.$value['aid'];

$noticedb[$value['aid']] = $value;

}

}

$notice_A = $noticedb;

unset($noticedb);

$topics = $article = $tposts = 0;

$cateid = (int)GetGP('cateid');

$secdomain = null;

$m = GetGP('m');

//設定預設首頁模式為門戶

if (!$cateid && $db_modedomain && $secdomain = array_search($pwServer['HTTP_HOST'], $db_modedomain)) {

$cateinfo = explode("_",$secdomain);

if ('cate' == $cateinfo[0]) {

$cateid = (int)$cateinfo[1];

$db_bbsurl = $_mainUrl;

$m = 'area';

}

unset($cateinfo);

}

//根據參數選擇模式

selectMode($m);

if (defined('M_P') && file_exists(M_P . ($cateid > 0 ? 'cate' : 'index') . '.php')) {

//門戶模式

if ($cateid > 0) {

//門戶模式的子版塊

$_GET['fid'] = $_GET['cateid'] = $cateid;

require_once M_P.'cate.php';

} else {

//門戶首頁或圈子首頁

require_once(M_P.'index.php');

$db_newinfoifopen = 0;

}

} else {

//論壇模式

$pw_seoset = L::loadClass('seoset');

$webPageTitle = $pw_seoset->getPageTitle();

$metaDescription = $pw_seoset->getPageMetadescrip();

$metaKeywords = $pw_seoset->getPageMetakeyword();

$newpic = (int)GetCookie('newpic');

$forumdb = $catedb = $showsub = array();

$c_htm = 0;

if ($db_forumdir) {

require_once(R_P.'require/dirname.php');

} elseif ($cateid > 0) {

$catestyle = $forum[$cateid]['style'];

if ($catestyle && file_exists(D_P."data/style/$catestyle.php")) {

$skin = $catestyle;

}

#SEO

$pw_seoset->set_page('thread');

$pw_seoset->set_ifCMS($forum[$cateid]['ifcms']);

$webPageTitle = $pw_seoset->getPageTitle($forum[$cateid]['title'],$forum[$cateid]['name']);

$metaDescription = $pw_seoset->getPageMetadescrip($forum[$cateid]['metadescrip'],$forum[$cateid]['name']);

$metaKeywords = $pw_seoset->getPageMetakeyword($forum[$cateid]['keywords'],$forum[$cateid]['name']);

$sqlwhere = 'AND (f.fid=' . pwEscape($cateid) . ' OR f.fup=' . pwEscape($cateid) . ')';

unset($metakeyword);

}

require_once(R_P.'require/header.php');

!$db_showcms && $sqlwhere .= " AND f.cms!='1'";

/*The app client*/

//第三方app相關

if ($db_siteappkey && ($db_apps_list['17']['status'] == 1 || is_array($db_threadconfig))) {

$appclient = L::loadClass('appclient');

if (is_array($db_threadconfig)) {

$threadright = array();

$threadright = $appclient->getThreadRight();

}

}

/*The app client*/

if ($cookie_deploy = $_COOKIE['deploy']) {

$deployfids = explode("/t",$cookie_deploy);

$deployfids = array_flip($deployfids);

unset($cookie_deploy);

} else {

$deployfids = array();

}

//查詢表pw_forums和pw_forumdata得到版塊資訊

$query = $db->query("SELECT f.fid,f.name,f.type,f.childid,f.fup,f.logo,f.descrip,f.metadescrip,f.forumadmin,f.across,f.allowhtm,f.password,f.allowvisit,f.showsub,f.ifcms,fd.tpost,fd.topic,fd.article,fd.subtopic,fd.top1,fd.lastpost FROM pw_forums f LEFT JOIN pw_forumdata fd USING(fid) WHERE f.ifsub='0' AND f.ifcms!=2 $sqlwhere ORDER BY f.vieworder");

while ($forums = $db->fetch_array($query)) {

//循環取得每個版塊資訊

if ($forums['type'] === 'forum') {

//若為具體版塊

//子版塊設定

if ($forums['showsub'] && $forums['childid']) {

$showsub[$forums['fid']] = '';

}

//取得主題總數

$forums['topics'] = $forums['topic']+$forums['subtopic'];

if ($db_topped) {

$forums['topics'] += $forums['top1'];

$forums['article'] += $forums['top1'];

}

//計算文章和回帖總數

$article += $forums['article'];

$topics += $forums['topics'];

$tposts += $forums['tpost'];

$forums['au'] = $forums['admin'] = '';

if (!$forums['password'] && (!$forums['allowvisit'] || allowcheck($forums['allowvisit'],$groupid, $winddb['groups'],$forums['fid'],$winddb['visit']))) {

//允許通路

//取得本版塊最新貼的相關資訊

list($forums['t'],$forums['au'],$forums['newtitle'],$forums['ft']) = explode("/t",$forums['lastpost']);

$forums['pic'] = $newpic < $forums['newtitle'] && ($forums['newtitle'] + $db_newtime > $timestamp) ? 'new' : 'old';

$forums['newtitle'] = get_date($forums['newtitle']);

$forums['t'] = substrs($forums['t'],26);

} elseif ($forum[$forums['fid']]['f_type'] === 'hidden' && $groupid != 3) {

//有權限或密碼保護

if ($forums['password'] && allowcheck($forums['allowvisit'],$groupid,$winddb['groups'], $forums['fid'],$winddb['visit'])) {

$forums['pic'] = 'lock';

} else {

continue;

}

} else {

$forums['pic'] = 'lock';

}

$forums['allowhtm'] == 1 && $c_htm = 1;

//取得版塊logo

if ($db_indexfmlogo == 2) {

if(!empty($forums['logo']) && strpos($forums['logo'],'http://') === false && file_exists($attachdir.'/'.$forums['logo'])){

$forums['logo'] = "$attachpath/$forums[logo]";

}

} elseif ($db_indexfmlogo == 1 && file_exists("$imgdir/$stylepath/forumlogo/$forums[fid].gif")) {

$forums['logo'] = "$imgpath/$stylepath/forumlogo/$forums[fid].gif";

} else {

$forums['logo'] = '';

}

//取得版主資訊

if ($forums['forumadmin']) {

$forumadmin = explode(',',$forums['forumadmin']);

foreach ($forumadmin as $value) {

if ($value) {

if (!$db_adminshow) {

$forums['admin'] .= '<a href="u.php?action=show&username='.rawurlencode($value)." target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" mce_href="u.php?action=show&username='.rawurlencode($value)." target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" /">$value</a> ";

} else {

$forums['admin'] .= "<option value=/"$value/">$value</option>";

}

}

}

}

//第三方 app相關

/*The app client*/

if ($db_siteappkey && $db_apps_list['17']['status'] == 1) {

$forums['forumappinfo'] = $appclient->showForumappinfo($forums['fid'],'forum_erect,forum_across','17');

}

/*The app client*/

$forumdb[$forums['fup']][] = $forums;

} elseif ($forums['type'] === 'category') {

//若為版塊分類

//取得圖示和樣式等顯示資訊

if (isset($deployfids[$forums['fid']])) {

$forums['deploy_img'] = 'open';

$forums['tbody_style'] = 'none';

$forums['admin'] = '';

} else {

$forums['deploy_img'] = 'fold';

$forums['tbody_style'] = $forums['admin'] = '';

}

//取得版主資訊

if ($forums['forumadmin']) {

$forumadmin = explode(',',$forums['forumadmin']);

foreach ($forumadmin as $key => $value) {

if ($value) {

if ($key==10) {

$forums['admin'] .= '...';

break;

}

$forums['admin'] .= '<a href="u.php?action=show&username='.rawurlencode($value)." target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" mce_href="u.php?action=show&username='.rawurlencode($value)." target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" /" class=/"cfont/">$value</a> ";

}

}

}

$catedb[] = $forums;

}

}

$db->free_result($query);

// View sub

if (!empty($showsub)) {

foreach ($forum as $value) {

if (isset($showsub[$value['fup']]) && $value['f_type'] != 'hidden') {

$showsub[$value['fup']] .= ($showsub[$value['fup']] ? ' | ' : '')."<a href="/" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" mce_href="/" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" "thread.php?fid=$value[fid]/">$value[name]</a>";

}

}

}

unset($forums,$forum,$db_showcms);

//info deploy

if (isset($deployfids['info'])) {

$cate_img = 'open';

$cate_info = 'none';

} else {

$cate_img = 'fold';

$cate_info = '';

}

// update birth day

if ($db_indexshowbirth) {

$brithcache = '';

require_once(R_P.'require/birth.php');

}

}

// Sharing Information

//取得論壇基本統計資訊

extract($db->get_one("SELECT * FROM pw_bbsinfo WHERE id=1"));

//$rt = $db->get_one('SELECT newmember,totalmember,higholnum,higholtime,tdtcontrol,yposts,hposts,hit_tdtime,hit_control,plantime FROM pw_bbsinfo WHERE id=1');

//顯示新會員

$newmember = '<a href="u.php?action=show&username='.rawurlencode($newmember).'" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" mce_href="u.php?action=show&username='.rawurlencode($newmember).'" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank">'.$newmember.'</a>';

//取得主題和文章總數

$article += $o_post;

$topics += $o_post;

$tposts += $o_tpost;

// online users

//更新線上資訊

Update_ol();

$userinbbs = $guestinbbs = 0;

//從cache或資料庫取得線上資訊

if (empty($db_online)) {

include_once(D_P.'data/bbscache/olcache.php');

} else {

$query = $db->query("SELECT uid!=0 as ifuser,COUNT(*) AS count FROM pw_online GROUP BY uid!='0'");

while ($rt = $db->fetch_array($query)) {

if ($rt['ifuser']) {

$userinbbs = $rt['count'];

} else {

$guestinbbs = $rt['count'];

}

}

}

//會員總數

$usertotal = $guestinbbs + $userinbbs;

if ($db_indexonline) {

InitGP(array('online'));

empty($online) && $online = GetCookie('online');

if ($online == 'yes') {

if ($usertotal > 2000 && !CkInArray($windid,$manager)) {

$online = 'no';

Cookie('online',$online);

} else {

$index_whosonline = '';

$db_online = intval($db_online);

include_once Pcv(R_P."require/online_{$db_online}.php");

}

}

}

$showgroup = $db_showgroup ? explode(',',$db_showgroup) : array();

// Share union

if ($db_indexmqshare && $sharelink[1]) {

$sharelink[1] = "<marquee scrolldelay=/"100/" scrollamount=/"4/" οnmοuseοut=/"if (document.all!=null){this.start()}/" οnmοuseοver=/"if (document.all!=null){this.stop()}/" behavior=/"alternate/">$sharelink[1]</marquee>";

}

//update pw_feed

//更新好友動态

if ($winduid && PwStrtoTime(get_date($lastvisit,'Y-m-d')) < $tdtime && $db_hostweb == 1 && !$cateid && $groupid != 'guest' && !defined('M_P')) {

$_flag = $db->get_value("SELECT id FROM pw_feed WHERE uid = ".pwEscape($winduid)." ORDER BY id DESC LIMIT 29,1");

$_flag && $db->update("DELETE FROM pw_feed WHERE uid = ".pwEscape($winduid)." AND id < ". pwEscape($_flag));

}

//更新昨日發貼數和資料更新時間

if ($db_hostweb == 1 && $groupid != 'guest' && !$cateid && $tdtcontrol < $tdtime && !defined('M_P')) {

require_once(R_P.'require/updateforum.php');

updateshortcut();

$db->update("UPDATE pw_bbsinfo SET".pwSqlSingle(array('yposts' => $tposts, 'tdtcontrol' => $tdtime,'o_tpost'=>0))."WHERE id='1'");

$db->update("UPDATE pw_forumdata SET tpost=0 WHERE tpost<>'0'");

// $db->update("DELETE FROM pw_feed WHERE timestamp<".pwEscape($tdtime - 604800));

}

// update posts hits

if ($c_htm || $db_hithour) {

$db_hithour == 0 && $db_hithour = 4;

$hit_wtime = $hit_control * $db_hithour;

$hit_wtime > 24 && $hit_wtime = 0;

$hitsize = @filesize(D_P.'data/bbscache/hits.txt');

if ($hitsize && ($hitsize > 1024 || ($timestamp - $hit_tdtime) > $hit_wtime * 3600) && procLock('hitupdate')) {

require_once(R_P.'require/hitupdate.php');

procUnLock('hitupdate');

}

}

//更新最高線上數和最高線上時間

if ($higholnum < $usertotal) {

$db->update("UPDATE pw_bbsinfo SET ".pwSqlSingle(array('higholnum' => $usertotal,'higholtime'=> $timestamp))." WHERE id=1");

$higholnum = $usertotal;

}

//更新最高日貼

if ($hposts < $tposts) {

$db->update('UPDATE pw_bbsinfo SET hposts='.pwEscape($tposts).' WHERE id=1');

$hposts = $tposts;

}

$mostinbbstime = get_date($higholtime);

if (!$ol_offset && $db_onlinelmt != 0 && $usertotal >= $db_onlinelmt) {

Cookie('ol_offset','',0);

Showmsg('most_online');

}

if ($plantime && $timestamp > $plantime && procLock('task')) {

require_once(R_P.'require/task.php');

procUnLock('task');

}

$db_newinfoifopen && require_once(R_P."require/newinfo.php");

//取得index.htm模闆,把上去取得的各個資訊通過html展現出來,相當于control層到view層

require_once PrintEot('index');

if (isset($area_refresh_static) && $area_refresh_static && function_exists("area_static_deal")) {

$area_static_content = ob_get_contents();

area_static_deal("saveStaticContent", array('content'=>$area_static_content));

ob_clean();

echo $area_static_header, $area_static_content;

unset($area_static_header, $area_static_content);

}

footer();

?>

繼續閱讀