wangtengyu
2018-12-07 f459412e0dac4ed94106da043b4c6f8576bfe496
commit | author | age
3e083b 1 <?php
B 2
3 /**
4  * 文章内容
5 */
6
7 define('IN_ECS', true);
8
9 require(dirname(__FILE__) . '/includes/init.php');
10
11 if ((DEBUG_MODE & 2) != 2)
12 {
13     $smarty->caching = true;
14 }
15
16
17 $_REQUEST['id'] = (isset($_REQUEST['id']) && preg_match('/^-?[1-9]\d*$/', $_REQUEST['id'])) ? intval($_REQUEST['id']) : 0;
18
19
20 $article_id     = $_REQUEST['id'];
21 if(isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] < 0)
22 {
23     $article_id = $db->getOne("SELECT article_id FROM " . $ecs->table('article') . " WHERE cat_id = '".intval($_REQUEST['cat_id'])."' ");
24 }
25
26
27
28 $cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));
29
30 if (!$smarty->is_cached('article.dwt', $cache_id))
31 {
32     /* 文章详情 */
33     $article = get_article_info($article_id);
34
35     if (empty($article))
36     {
37         ecs_header("Location: ./\n");
38         exit;
39     }
40
41     if (!empty($article['link']) && $article['link'] != 'http://' && $article['link'] != 'https://')
42     {
43         ecs_header("location:$article[link]\n");
44         exit;
45     }
46
47     $smarty->assign('article_categories',   article_categories_tree($article_id)); //文章分类树
48     $smarty->assign('categories',       get_categories_tree());  // 分类树
49     $smarty->assign('helps',            get_shop_help()); // 网店帮助
50     $smarty->assign('top_goods',        get_top10());    // 销售排行
51     $smarty->assign('best_goods',       get_recommend_goods('best'));       // 推荐商品
52     $smarty->assign('new_goods',        get_recommend_goods('new'));        // 最新商品
53     $smarty->assign('hot_goods',        get_recommend_goods('hot'));        // 热点文章
54     $smarty->assign('promotion_goods',  get_promote_goods());    // 特价商品
55     $smarty->assign('related_goods',    article_related_goods($_REQUEST['id']));  // 特价商品
56     $smarty->assign('id',               $article_id);
57     $smarty->assign('username',         $_SESSION['user_name']);
58     $smarty->assign('email',            $_SESSION['email']);
59     $smarty->assign('type',            '1');
60     $smarty->assign('promotion_info', get_promotion_info());
61     $smarty->assign('cat_id', get_cat_id_art($article_id));
62
63     /* 验证码相关设置 */
64     if ((intval($_CFG['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
65     {
66         $smarty->assign('enabled_captcha', 1);
67         $smarty->assign('rand',            mt_rand());
68     }
69
70     $smarty->assign('article',      $article);
71     $smarty->assign('keywords',     htmlspecialchars($article['keywords']));
72     $smarty->assign('description', htmlspecialchars($article['description']));
73
74     $catlist = array();
75     foreach(get_article_parent_cats($article['cat_id']) as $k=>$v)
76     {
77         $catlist[] = $v['cat_id'];
78     }
79
80     assign_template('a', $catlist);
81
82     $position = assign_ur_here($article['cat_id'], $article['title']);
83     $smarty->assign('page_title',   $position['title']);    // 页面标题
84     $smarty->assign('ur_here',      $position['ur_here']);  // 当前位置
85     $smarty->assign('comment_type', 1);
86     $smarty->assign('topcatid',array_pop($catlist));
87
88
89     /* 相关商品 */
90     $sql = "SELECT a.goods_id, g.goods_name " .
91             "FROM " . $ecs->table('goods_article') . " AS a, " . $ecs->table('goods') . " AS g " .
92             "WHERE a.goods_id = g.goods_id " .
93             "AND a.article_id = '$_REQUEST[id]' ";
94     $smarty->assign('goods_list', $db->getAll($sql));
95
96     /* 上一篇下一篇文章 */
97     $next_article = $db->getRow("SELECT article_id, title FROM " .$ecs->table('article'). " WHERE article_id > $article_id AND cat_id=$article[cat_id] AND is_open=1 LIMIT 1");
98     if (!empty($next_article))
99     {
100         $next_article['url'] = build_uri('article', array('aid'=>$next_article['article_id']), $next_article['title']);
101         $smarty->assign('next_article', $next_article);
102     }
103
104     $prev_aid = $db->getOne("SELECT max(article_id) FROM " . $ecs->table('article') . " WHERE article_id < $article_id AND cat_id=$article[cat_id] AND is_open=1");
105     if (!empty($prev_aid))
106     {
107         $prev_article = $db->getRow("SELECT article_id, title FROM " .$ecs->table('article'). " WHERE article_id = $prev_aid");
108         $prev_article['url'] = build_uri('article', array('aid'=>$prev_article['article_id']), $prev_article['title']);
109         $smarty->assign('prev_article', $prev_article);
110     }
111
112     assign_dynamic('article');
113 }
114 if(isset($article) && $article['cat_id'] > 2)
115 {
116     $smarty->display('article.dwt', $cache_id);
117 }
118 else
119 {
120     $smarty->display('article_pro.dwt', $cache_id);
121 }
122
123
124 /**
125  * 获得指定的文章的详细信息
126  *
127  * @access  private
128  * @param   integer     $article_id
129  * @return  array
130  */
131 function get_article_info($article_id)
132 {
133     /* 获得文章的信息 */
134     $sql = "SELECT a.*, IFNULL(AVG(r.comment_rank), 0) AS comment_rank ".
135             "FROM " .$GLOBALS['ecs']->table('article'). " AS a ".
136             "LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".
137             "WHERE a.is_open = 1 AND a.article_id = '$article_id' GROUP BY a.article_id";
138     $row = $GLOBALS['db']->getRow($sql);
139
140     if ($row !== false)
141     {
142         $row['comment_rank'] = ceil($row['comment_rank']);                              // 用户评论级别取整
143         $row['add_time']     = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示
144
145         /* 作者信息如果为空,则用网站名称替换 */
146         if (empty($row['author']) || $row['author'] == '_SHOPHELP')
147         {
148             $row['author'] = $GLOBALS['_CFG']['shop_name'];
149         }
150     }
151
152     return $row;
153 }
154
155 /**
156  * 获得文章关联的商品
157  *
158  * @access  public
159  * @param   integer $id
160  * @return  array
161  */
162 function article_related_goods($id)
163 {
164     $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
165                 "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
166                 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
167             'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' ga ' .
168             'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = ga.goods_id ' .
169             "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
170                     "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
171             "WHERE ga.article_id = '$id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0";
172     $res = $GLOBALS['db']->query($sql);
173
174     $arr = array();
175     while ($row = $GLOBALS['db']->fetchRow($res))
176     {
177         $arr[$row['goods_id']]['goods_id']      = $row['goods_id'];
178         $arr[$row['goods_id']]['goods_name']    = $row['goods_name'];
179         $arr[$row['goods_id']]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
180             sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
181         $arr[$row['goods_id']]['goods_thumb']   = get_image_path($row['goods_id'], $row['goods_thumb'], true);
182         $arr[$row['goods_id']]['goods_img']     = get_image_path($row['goods_id'], $row['goods_img']);
183         $arr[$row['goods_id']]['market_price']  = price_format($row['market_price']);
184         $arr[$row['goods_id']]['shop_price']    = price_format($row['shop_price']);
185         $arr[$row['goods_id']]['url']           = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
186
187         if ($row['promote_price'] > 0)
188         {
189             $arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
190             $arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']);
191         }
192         else
193         {
194             $arr[$row['goods_id']]['promote_price'] = 0;
195         }
196     }
197
198     return $arr;
199 }
200 function get_cat_id_art($article_id){
201     $sql = "select cat_id from " .$GLOBALS['ecs']->table('article'). " where article_id = '$article_id'";
202     return $GLOBALS['db']->getOne($sql);
203 }
204
205 make_html();
206
207 ?>