Discuz X:家园底层逻辑浅析(1)
作者:Garry 发布于:2012-3-23 10:31 Friday 分类:代码研究
首发于:http://www.PHPig.net,转载请注明。
点击X的家园,看到连接是home.php,下面就看看这个文件。
01 | define( 'APPTYPEID' , 1); |
02 | define( 'CURSCRIPT' , 'home' ); |
04 | require_once './source/class/class_core.php' ; |
05 | require_once './source/function/function_home.php' ; |
07 | $discuz = & discuz_core::instance(); |
10 | $cachelist = array ( 'magic' , 'userapp' , 'usergroups' , 'blockclass' ); |
11 | $discuz ->cachelist = $cachelist ; |
19 | if (!in_array( $mod , array ( 'space' , 'spacecp' , 'misc' , 'magic' , 'editor' , 'userapp' , 'invite' , 'task' , 'medal' ))) { |
24 | define( 'CURMODULE' , $mod ); |
27 | require_once libfile( 'home/' . $mod , 'module' ); |
home_space.php,看看这个文件
01 | if (!defined( 'IN_DISCUZ' )) { |
02 | exit ( 'Access Denied' ); |
05 | $uid = empty ( $_GET [ 'uid' ]) ? 0 : intval ( $_GET [ 'uid' ]); |
08 | if ( $_GET [ 'username' ]) { |
09 | $member = DB::fetch_first( "SELECT uid FROM " .DB::table( 'common_member' ). " WHERE username='$_GET[username]' LIMIT 1" ); |
10 | $uid = $member [ 'uid' ]; |
11 | } elseif ( $_GET [ 'domain' ]) { |
12 | $member = DB::fetch_first( "SELECT uid FROM " .DB::table( 'common_member_field_home' ). " WHERE domain='$_GET[domain]' LIMIT 1" ); |
13 | $uid = $member [ 'uid' ]; |
17 | $dos = array ( 'index' , 'doing' , 'blog' , 'album' , 'friend' , 'wall' , |
18 | 'notice' , 'share' , 'home' , 'pm' , 'videophoto' , 'top' , 'favorite' , |
19 | 'thread' , 'trade' , 'poll' , 'activity' , 'debate' , 'reward' , 'group' , 'profile' ); |
22 | $do = (! empty ( $_GET [ 'do' ]) && in_array( $_GET [ 'do' ], $dos ))? $_GET [ 'do' ]: 'index' ; |
25 | if ( empty ( $uid )) $uid = $_G [ 'uid' ]; |
28 | $space = getspace( $uid , 'uid' ); |
30 | showmessage( 'space_does_not_exist' ); |
36 | if (in_array( $do , array ( 'doing' , 'blog' , 'album' , 'share' , 'home' , 'thread' , 'trade' , 'poll' , 'activity' , 'debate' , 'reward' , 'group' ))) { |
37 | $_GET [ 'view' ] = 'all' ; |
40 | showmessage( 'login_before_enter_home' , 'member.php?mod=logging&action=login' ); |
45 | if ( $space [ 'status' ] == -1) { |
46 | showmessage( 'space_has_been_locked' ); |
50 | if (!ckprivacy( $do , 'view' )) { |
51 | include template( 'home/space_privacy' ); |
56 | if (! $space [ 'self' ]) $_GET [ 'view' ] = 'me' ; |
69 | $seccodecheck = $_G [ 'setting' ][ 'seccodestatus' ] & 4; |
70 | $secqaacheck = $_G [ 'setting' ][ 'secqaa' ][ 'status' ] & 2; |
73 | require_once libfile( 'space/' . $do , 'include' ); |
整理一下,
点‘家园’,实际就是访问home.php,也就是home.php?mod=space&do=home,具体文件是source/module/home/home_space.php,如果do没有或者参数不在允许范围,则home.php?mod=space访问的是home.php?mod=space&do=index,‘个人空间’,也就是别人访问你的那个空间。是不是很绕,事实就是这么绕。
反正记住,do=home是我的中心,do=index是个人空间,这里的do也可以是Doing,album等。