首页 后端开发 php教程 uploadinstallincludesauto_init.php源码分析

uploadinstallincludesauto_init.php源码分析

Jun 23, 2016 pm 01:42 PM

  1 <?php  2   3 /**  4  * ECSHOP 首页文件  5  * ============================================================================  6  * * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。  7  * 网站地址: http://www.ecshop.com;  8  * ----------------------------------------------------------------------------  9  * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和 10  * 使用;不允许对程序代码以任何形式任何目的的再发布。 11  * ============================================================================ 12  * $Author: liubo $ 13  * $Id: index.php 17217 2011-01-19 06:29:08Z liubo $ 14 */ 15  16 define('IN_ECS', true); 17  18 require(dirname(__FILE__) . '/includes/init.php'); 19  20 if ((DEBUG_MODE & 2) != 2) 21 { 22     $smarty->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之类脚本的执行时间,原谅我没文化,在此罗嗦了一大堆。

    本站声明
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

    热AI工具

    Undresser.AI Undress

    Undresser.AI Undress

    人工智能驱动的应用程序,用于创建逼真的裸体照片

    AI Clothes Remover

    AI Clothes Remover

    用于从照片中去除衣服的在线人工智能工具。

    Undress AI Tool

    Undress AI Tool

    免费脱衣服图片

    Clothoff.io

    Clothoff.io

    AI脱衣机

    Video Face Swap

    Video Face Swap

    使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

    热工具

    记事本++7.3.1

    记事本++7.3.1

    好用且免费的代码编辑器

    SublimeText3汉化版

    SublimeText3汉化版

    中文版,非常好用

    禅工作室 13.0.1

    禅工作室 13.0.1

    功能强大的PHP集成开发环境

    Dreamweaver CS6

    Dreamweaver CS6

    视觉化网页开发工具

    SublimeText3 Mac版

    SublimeText3 Mac版

    神级代码编辑软件(SublimeText3)

    在PHP API中说明JSON Web令牌(JWT)及其用例。 在PHP API中说明JSON Web令牌(JWT)及其用例。 Apr 05, 2025 am 12:04 AM

    JWT是一种基于JSON的开放标准,用于在各方之间安全地传输信息,主要用于身份验证和信息交换。1.JWT由Header、Payload和Signature三部分组成。2.JWT的工作原理包括生成JWT、验证JWT和解析Payload三个步骤。3.在PHP中使用JWT进行身份验证时,可以生成和验证JWT,并在高级用法中包含用户角色和权限信息。4.常见错误包括签名验证失败、令牌过期和Payload过大,调试技巧包括使用调试工具和日志记录。5.性能优化和最佳实践包括使用合适的签名算法、合理设置有效期、

    会话如何劫持工作,如何在PHP中减轻它? 会话如何劫持工作,如何在PHP中减轻它? Apr 06, 2025 am 12:02 AM

    会话劫持可以通过以下步骤实现:1.获取会话ID,2.使用会话ID,3.保持会话活跃。在PHP中防范会话劫持的方法包括:1.使用session_regenerate_id()函数重新生成会话ID,2.通过数据库存储会话数据,3.确保所有会话数据通过HTTPS传输。

    描述扎实的原则及其如何应用于PHP的开发。 描述扎实的原则及其如何应用于PHP的开发。 Apr 03, 2025 am 12:04 AM

    SOLID原则在PHP开发中的应用包括:1.单一职责原则(SRP):每个类只负责一个功能。2.开闭原则(OCP):通过扩展而非修改实现变化。3.里氏替换原则(LSP):子类可替换基类而不影响程序正确性。4.接口隔离原则(ISP):使用细粒度接口避免依赖不使用的方法。5.依赖倒置原则(DIP):高低层次模块都依赖于抽象,通过依赖注入实现。

    在PHPStorm中如何进行CLI模式的调试? 在PHPStorm中如何进行CLI模式的调试? Apr 01, 2025 pm 02:57 PM

    在PHPStorm中如何进行CLI模式的调试?在使用PHPStorm进行开发时,有时我们需要在命令行界面(CLI)模式下调试PHP�...

    如何在系统重启后自动设置unixsocket的权限? 如何在系统重启后自动设置unixsocket的权限? Mar 31, 2025 pm 11:54 PM

    如何在系统重启后自动设置unixsocket的权限每次系统重启后,我们都需要执行以下命令来修改unixsocket的权限:sudo...

    解释PHP中的晚期静态绑定(静态::)。 解释PHP中的晚期静态绑定(静态::)。 Apr 03, 2025 am 12:04 AM

    静态绑定(static::)在PHP中实现晚期静态绑定(LSB),允许在静态上下文中引用调用类而非定义类。1)解析过程在运行时进行,2)在继承关系中向上查找调用类,3)可能带来性能开销。

    框架安全功能:防止漏洞。 框架安全功能:防止漏洞。 Mar 28, 2025 pm 05:11 PM

    文章讨论了框架中的基本安全功能,以防止漏洞,包括输入验证,身份验证和常规更新。

    See all articles