zuitu 最土团购源码分析(一)前台部分

无可厚非PHP还是普及度最高,最简单的语言。

想快速开发系统还是用PHP比较好。

初学PHP,那就以现在最火的团购网站源码最土来做分析学习。

 

最土网站 http://www.zuitu.com/

 

开发工具

dreamwear

xampp

 

前台分析

我们首先来看首页index.php的源码

 

<?php
require_once(dirname(__FILE__) . '/app.php');

if(!$INI['db']['host']) redirect( WEB_ROOT . '/install.php' );
if($city&&option_yes('rewritecity')){
	redirect(WEB_ROOT."/{$city['ename']}");
}

$request_uri = 'index';
$team = $teams = index_get_team($city['id']);

if ($team && $team['id']) {
	$_GET['id'] = abs(intval($team['id']));
	die(require_once( dirname(__FILE__) . '/team.php'));
}
elseif ($teams) {
	$disable_multi = true;
	die(require_once( dirname(__FILE__) . '/multi.php'));
}

include template('subscribe');
 

我勒个去,找不到HTML标签。难道HTML用模版实现的?

算了,先从第一句看吧,谁叫我是菜鸟呢。

 

 

require_once(dirname(__FILE__) . '/app.php');

直接google,过程省略。

http://php.net/manual/zh/function.require-once.php

意思就是只引用一次app.php。 app.php应该是MVC框架的控制器。

我们再看看app.php里写了什么。

 

 

<?php
require_once(dirname(__FILE__). '/include/application.php');
/* magic_quota_gpc */
$_GET = magic_gpc($_GET);
$_POST = magic_gpc($_POST);
$_COOKIE = magic_gpc($_COOKIE);

/* process currefer*/
$currefer = uencode(strval($_SERVER['REQUEST_URI']));

/* session,cache,configure,webroot register */
Session::Init();
$INI = ZSystem::GetINI();
/* end */

/* date_zone */
if(function_exists('date_default_timezone_set')) { 
	date_default_timezone_set($INI['system']['timezone']); 
}
/* end date_zone */


/* biz logic */
$currency = $INI['system']['currency'];
$login_user_id = ZLogin::GetLoginId();
$login_user = Table::Fetch('user', $login_user_id);
$hotcities = option_hotcategory('city', false, true);
$allcities = option_category('city', false, true);
$city = cookie_city(null);

/* not allow access app.php */
if($_SERVER['SCRIPT_FILENAME']==__FILE__){
	redirect( WEB_ROOT . '/index.php');
}
/* end */
$AJAX = ('XMLHttpRequest' == @$_SERVER['HTTP_X_REQUESTED_WITH']);
if (false==$AJAX) { 
	header('Content-Type: text/html; charset=UTF-8'); 
	run_cron();
} else {
	header("Cache-Control: no-store, no-cache, must-revalidate");
}
 

马勒隔壁,这么多。看得头晕,还是先把index.php看完再看下面一层吧。不然就是无限循环啊。。。切记,切记。

 

 

<?php
require_once(dirname(__FILE__) . '/app.php');	/*只加载一次app.php*/
if(!$INI['db']['host']) redirect( WEB_ROOT . '/install.php' );	/* $INI中是否存在['db']['host'],$INI在app.php中加载 */
if($city&&option_yes('rewritecity')){ /* 如果有city变量并且XXX就直接跳转到根目录所有的省链接 */
	redirect(WEB_ROOT."/{$city['ename']}");
}

$request_uri = 'index';
$team = $teams = index_get_team($city['id']); /* index_get_team函数在include/function/common.php里 */

if ($team && $team['id']) {
	$_GET['id'] = abs(intval($team['id'])); /* 字符串转整数并取绝对值,为什么要这样做? */
	die(require_once( dirname(__FILE__) . '/team.php')); /* 加载team.php 并终止*/
}
elseif ($teams) {
	$disable_multi = true;
	die(require_once( dirname(__FILE__) . '/multi.php')); 
}

include template('subscribe'); /* 加载模版subscribe, subscribe是什么? */

 

待解决疑问  

 

/* session,cache,configure,webroot register */
Session::Init();
$INI = ZSystem::GetINI();
/* end */

 

include/function/common.php

 

function index_get_team($city_id) {
	global $INI;
	$multi = option_yes('indexmulti');
	if (!$multi) return current_team($city_id);
	$city_id = abs(intval($city_id));
	$now = time();
	$size = abs(intval($INI['system']['sideteam']));
	if ($size<=1) return current_team($city_id);

	$oc = array( 
			'city_id' => array($city_id, 0), 
			'team_type' => 'normal',
			"begin_time < '{$now}'",
			"end_time > '{$now}'",
			);
	$teams = DB::LimitQuery('team', array(
				'condition' => $oc,
				'order' => 'ORDER BY `sort_order` DESC, `id` DESC',
				'size' => $size,
				));
	if(count($teams) == 1) return array_pop($teams);
	return $teams;
}
 

 

 

 

 

 

你可能感兴趣的:(Web,PHP,Ajax,mvc,cache)