1 caching = true; 23 } 24 $ua = strtolower($_SERVER['HTTP_USER_AGENT']); 25 26 $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i"; 27 28 if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')) 29 { 30 $Loaction = 'mobile/'; 31 32 if (!empty($Loaction)) 33 { 34 ecs_header("Location: $Loaction\n"); 35 36 exit; 37 } 38 39 } 40 /*------------------------------------------------------ */ 41 //-- Shopex系統地址轉換 42 /*------------------------------------------------------ */ 43 if (!empty($_GET['gOo'])) 44 { 45 if (!empty($_GET['gcat'])) 46 { 47 /* 商品分類。*/ 48 $Loaction = 'category.php?id=' . $_GET['gcat']; 49 } 50 elseif (!empty($_GET['acat'])) 51 { 52 /* 文章分類。*/ 53 $Loaction = 'article_cat.php?id=' . $_GET['acat']; 54 } 55 elseif (!empty($_GET['goodsid'])) 56 { 57 /* 商品詳情。*/ 58 $Loaction = 'goods.php?id=' . $_GET['goodsid']; 59 } 60 elseif (!empty($_GET['articleid'])) 61 { 62 /* 文章詳情。*/ 63 $Loaction = 'article.php?id=' . $_GET['articleid']; 64 } 65 66 if (!empty($Loaction)) 67 { 68 ecs_header("Location: $Loaction\n"); 69 70 exit; 71 } 72 } 73 74 //判斷是否有ajax請求 75 $act = !empty($_GET['act']) ? $_GET['act'] : ''; 76 if ($act == 'cat_rec') 77 { 78 $rec_array = array(1 => 'best', 2 => 'new', 3 => 'hot'); 79 $rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1'; 80 $cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0'; 81 include_once('includes/cls_json.php'); 82 $json = new JSON; 83 $result = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id); 84 85 $children = get_children($cat_id); 86 $smarty->assign($rec_array[$rec_type] . '_goods', get_category_recommend_goods($rec_array[$rec_type], $children)); // 推薦商品 87 $smarty->assign('cat_rec_sign', 1); 88 $result['content'] = $smarty->fetch('library/recommend_' . $rec_array[$rec_type] . '.lbi'); 89 die($json->encode($result)); 90 } 91 92 /*------------------------------------------------------ */ 93 //-- 判斷是否存在緩衝,如果存在則調用緩衝,反之讀取相應內容 94 /*------------------------------------------------------ */ 95 /* 緩衝編號 */ 96 $cache_id = sprintf('%X', crc32($_SESSION['user_rank'] . '-' . $_CFG['lang'])); 97 98 if (!$smarty->is_cached('index.dwt', $cache_id)) 99 {100 assign_template();101 102 $position = assign_ur_here();103 $smarty->assign('page_title', $position['title']); // 頁面標題104 $smarty->assign('ur_here', $position['ur_here']); // 當前位置105 106 /* meta information */107 $smarty->assign('keywords', htmlspecialchars($_CFG['shop_keywords']));108 $smarty->assign('description', htmlspecialchars($_CFG['shop_desc']));109 $smarty->assign('flash_theme', $_CFG['flash_theme']); // Flash輪播圖片模板110 111 $smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? 'feed.xml' : 'feed.php'); // RSS URL112 113 $smarty->assign('categories', get_categories_tree()); // 分類樹114 $smarty->assign('helps', get_shop_help()); // 網店協助115 $smarty->assign('top_goods', get_top10()); // 銷售排行116 117 $smarty->assign('best_goods', get_recommend_goods('best')); // 推薦商品118 $smarty->assign('new_goods', get_recommend_goods('new')); // 最新商品119 $smarty->assign('hot_goods', get_recommend_goods('hot')); // 熱點文章120 $smarty->assign('promotion_goods', get_promote_goods()); // 特價商品121 $smarty->assign('brand_list', get_brands());122 $smarty->assign('promotion_info', get_promotion_info()); // 增加一個動態顯示所有促銷資訊的標籤欄123 124 $smarty->assign('invoice_list', index_get_invoice_query()); // 發貨查詢125 $smarty->assign('new_articles', index_get_new_articles()); // 最新文章126 $smarty->assign('group_buy_goods', index_get_group_buy()); // 團購商品127 $smarty->assign('auction_list', index_get_auction()); // 拍賣活動128 $smarty->assign('shop_notice', $_CFG['shop_notice']); // 商店公告129 130 /* 首頁主廣告設定 */131 $smarty->assign('index_ad', $_CFG['index_ad']);132 if ($_CFG['index_ad'] == 'cus')133 {134 $sql = 'SELECT ad_type, content, url FROM ' . $ecs->table("ad_custom") . ' WHERE ad_status = 1';135 $ad = $db->getRow($sql, true);136 $smarty->assign('ad', $ad);137 }138 139 /* links */140 $links = index_get_links();141 $smarty->assign('img_links', $links['img']);142 $smarty->assign('txt_links', $links['txt']);143 $smarty->assign('data_dir', DATA_DIR); // 資料目錄144 145 /* 首頁推薦分類 */146 $cat_recommend_res = $db->getAll("SELECT c.cat_id, c.cat_name, cr.recommend_type FROM " . $ecs->table("cat_recommend") . " AS cr INNER JOIN " . $ecs->table("category") . " AS c ON cr.cat_id=c.cat_id");147 if (!empty($cat_recommend_res))148 {149 $cat_rec_array = array();150 foreach($cat_recommend_res as $cat_recommend_data)151 {152 $cat_rec[$cat_recommend_data['recommend_type']][] = array('cat_id' => $cat_recommend_data['cat_id'], 'cat_name' => $cat_recommend_data['cat_name']);153 }154 $smarty->assign('cat_rec', $cat_rec);155 }156 157 /* 頁面中的動態內容 */158 assign_dynamic('index');159 }160 161 $smarty->display('index.dwt', $cache_id);162 163 /*------------------------------------------------------ */164 //-- PRIVATE FUNCTIONS165 /*------------------------------------------------------ */166 167 /**168 * 調用發貨單查詢169 *170 * @access private171 * @return array172 */173 function index_get_invoice_query()174 {175 $sql = 'SELECT o.order_sn, o.invoice_no, s.shipping_code FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o' .176 ' LEFT JOIN ' . $GLOBALS['ecs']->table('shipping') . ' AS s ON s.shipping_id = o.shipping_id' .177 " WHERE invoice_no > '' AND shipping_status = " . SS_SHIPPED .178 ' ORDER BY shipping_time DESC LIMIT 10';179 $all = $GLOBALS['db']->getAll($sql);180 181 foreach ($all AS $key => $row)182 {183 $plugin = ROOT_PATH . 'includes/modules/shipping/' . $row['shipping_code'] . '.php';184 185 if (file_exists($plugin))186 {187 include_once($plugin);188 189 $shipping = new $row['shipping_code'];190 $all[$key]['invoice_no'] = $shipping->query((string)$row['invoice_no']);191 }192 }193 194 clearstatcache();195 196 return $all;197 }198 199 /**200 * 獲得最新的文章列表。201 *202 * @access private203 * @return array204 */205 function index_get_new_articles()206 {207 $sql = 'SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id, ac.cat_name ' .208 ' FROM ' . $GLOBALS['ecs']->table('article') . ' AS a, ' .209 $GLOBALS['ecs']->table('article_cat') . ' AS ac' .210 ' WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1' .211 ' ORDER BY a.article_type DESC, a.add_time DESC LIMIT ' . $GLOBALS['_CFG']['article_number'];212 $res = $GLOBALS['db']->getAll($sql);213 214 $arr = array();215 foreach ($res AS $idx => $row)216 {217 $arr[$idx]['id'] = $row['article_id'];218 $arr[$idx]['title'] = $row['title'];219 $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?220 sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];221 $arr[$idx]['cat_name'] = $row['cat_name'];222 $arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);223 $arr[$idx]['url'] = $row['open_type'] != 1 ?224 build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);225 $arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']);226 }227 228 return $arr;229 }230 231 /**232 * 獲得最新的團購活動233 *234 * @access private235 * @return array236 */237 function index_get_group_buy()238 {239 $time = gmtime();240 $limit = get_library_number('group_buy', 'index');241 242 $group_buy_list = array();243 if ($limit > 0)244 {245 $sql = 'SELECT gb.act_id AS group_buy_id, gb.goods_id, gb.ext_info, gb.goods_name, g.goods_thumb, g.goods_img ' .246 'FROM ' . $GLOBALS['ecs']->table('goods_activity') . ' AS gb, ' .247 $GLOBALS['ecs']->table('goods') . ' AS g ' .248 "WHERE gb.act_type = '" . GAT_GROUP_BUY . "' " .249 "AND g.goods_id = gb.goods_id " .250 "AND gb.start_time <= '" . $time . "' " .251 "AND gb.end_time >= '" . $time . "' " .252 "AND g.is_delete = 0 " .253 "ORDER BY gb.act_id DESC " .254 "LIMIT $limit" ;255 $res = $GLOBALS['db']->query($sql);256 257 while ($row = $GLOBALS['db']->fetchRow($res))258 {259 /* 如果縮圖為空白,使用預設圖片 */260 $row['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);261 $row['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);262 263 /* 根據價格階梯,計算最低價 */264 $ext_info = unserialize($row['ext_info']);265 $price_ladder = $ext_info['price_ladder'];266 if (!is_array($price_ladder) || empty($price_ladder))267 {268 $row['last_price'] = price_format(0);269 }270 else271 {272 foreach ($price_ladder AS $amount_price)273 {274 $price_ladder[$amount_price['amount']] = $amount_price['price'];275 }276 }277 ksort($price_ladder);278 $row['last_price'] = price_format(end($price_ladder));279 $row['url'] = build_uri('group_buy', array('gbid' => $row['group_buy_id']));280 $row['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?281 sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];282 $row['short_style_name'] = add_style($row['short_name'],'');283 $group_buy_list[] = $row;284 }285 }286 287 return $group_buy_list;288 }289 290 /**291 * 取得拍賣活動列表292 * @return array293 */294 function index_get_auction()295 {296 $now = gmtime();297 $limit = get_library_number('auction', 'index');298 $sql = "SELECT a.act_id, a.goods_id, a.goods_name, a.ext_info, g.goods_thumb ".299 "FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS a," .300 $GLOBALS['ecs']->table('goods') . " AS g" .301 " WHERE a.goods_id = g.goods_id" .302 " AND a.act_type = '" . GAT_AUCTION . "'" .303 " AND a.is_finished = 0" .304 " AND a.start_time <= '$now'" .305 " AND a.end_time >= '$now'" .306 " AND g.is_delete = 0" .307 " ORDER BY a.start_time DESC" .308 " LIMIT $limit";309 $res = $GLOBALS['db']->query($sql);310 311 $list = array();312 while ($row = $GLOBALS['db']->fetchRow($res))313 {314 $ext_info = unserialize($row['ext_info']);315 $arr = array_merge($row, $ext_info);316 $arr['formated_start_price'] = price_format($arr['start_price']);317 $arr['formated_end_price'] = price_format($arr['end_price']);318 $arr['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);319 $arr['url'] = build_uri('auction', array('auid' => $arr['act_id']));320 $arr['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?321 sub_str($arr['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr['goods_name'];322 $arr['short_style_name'] = add_style($arr['short_name'],'');323 $list[] = $arr;324 }325 326 return $list;327 }328 329 /**330 * 獲得所有的友情連結331 *332 * @access private333 * @return array334 */335 function index_get_links()336 {337 $sql = 'SELECT link_logo, link_name, link_url FROM ' . $GLOBALS['ecs']->table('friend_link') . ' ORDER BY show_order';338 $res = $GLOBALS['db']->getAll($sql);339 340 $links['img'] = $links['txt'] = array();341 342 foreach ($res AS $row)343 {344 if (!empty($row['link_logo']))345 {346 $links['img'][] = array('name' => $row['link_name'],347 'url' => $row['link_url'],348 'logo' => $row['link_logo']);349 }350 else351 {352 $links['txt'][] = array('name' => $row['link_name'],353 'url' => $row['link_url']);354 }355 }356 357 return $links;358 }359 360 ?>
調用結構層級
\upload\index.php
\upload\includes\init.php
\upload\install\index.php
\upload\install\auto_index.php
\upload\install\includes\auto_init.php
@ini_set('display_errors', 1); //設定顯示錯誤
error_reporting(E_ALL ^ E_NOTICE); //報告所有的錯誤、通知,其中通知是指令碼發現的可能是錯誤的地方
clearstatcache(); //清除緩衝
define('ROOT_PATH', str_replace('install/includes/auto_init.php', '', str_replace('\\', '/', __FILE__))); //定義常量'ROOT_PATH'為網站根目錄upload/
if (isset($_SERVER['PHP_SELF'])) //定義常量'PHP_SELF'為,$_SERVER['PHP_SELF'](當前執行指令碼的檔案名稱)或$_SERVER['SCRIPT_NAME'](當前執行指令碼所在檔案夾的路徑)
{
define('PHP_SELF', $_SERVER['PHP_SELF']);
}
else
{
define('PHP_SELF', $_SERVER['SCRIPT_NAME']);
}
define('EC_CHARSET','utf-8'); //定義常量'EC_CHARSET'和'EC_DB_CHARSET'為UTF8
define('EC_DB_CHARSET','utf8');
require(ROOT_PATH . 'includes/lib_base.php'); //引用基礎函數庫,公用函數庫,時間函數庫,方便之後調用其中的函數
require(ROOT_PATH . 'includes/lib_common.php');
require(ROOT_PATH . 'includes/lib_time.php');
require(ROOT_PATH . 'includes/cls_error.php'); //產生一個錯誤類對象,模板為message.dwt,此處並未匯入dwt檔案,只是給類成員對象$_template賦值
$err = new ecs_error('message.dwt');
require(ROOT_PATH . 'install/includes/cls_template.php'); //產生一個模板類對象,並給類成員物件路徑$path賦值
$smarty = new template(ROOT_PATH . 'install/templates/');
require(ROOT_PATH . 'install/includes/lib_auto_installer.php'); //調用lib_auto_installer.php實際上什麼也沒做,lib_auto_installer.php提供了一系列庫函數以供調用
header('Content-type: text/html; charset='.EC_CHARSET); //告訴瀏覽器文本類型,編碼格式,其中EC_CHARSET在前面定義過,值為'utf-8'。
@set_time_limit(360); //設定指令碼的最長執行時間為360秒,如果超過了時間限制,程式結束
總結一下:
這個php為自動安裝程式做了初始化工作,包括產生一個錯誤類ecs_error對象(執行建構函式將公有成員變數$_template值設為‘message.dwt’),產生一個模板類template對象(執行建構函式將公有成員變數$path值設為'/upload/install/templates/';告訴瀏覽器文本類型為text/html,編碼格式utf8;設定指令碼最長執行時間為360秒。
對於最後一條語句@set_time_limit(360)我有一些疑問想和大家分享一下。
set_time_limit函數實際上和修改php.ini中的max_execution_time可以起到一樣的效果。這裡說設定指令碼最長執行時間為360秒,最初看到這條語句我陷入了一個誤區:由於從頂層的index.php到這個php是一路require過來,並且在執行時require語句會被它所包含的檔案直接替換,那麼這個360秒到底是限制哪一個php的的執行時間。就在我百思不得其解時,看到了指令碼這個詞,然後忽然想到這個函數不是用來限制php檔案的執行時間,php檔案也不是指令檔,這個函數是用來限制ecshop中用到的js之類指令碼的執行時間,原諒我沒文化,在此羅嗦了一大堆。