-
Notifications
You must be signed in to change notification settings - Fork 0
/
article.php
318 lines (254 loc) · 10.6 KB
/
article.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<?php
/**
* ECSHOP 文章内容
* ============================================================================
* * 版权所有 2005-2012 欧嘉科技,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: article.php 17217 2011-01-19 06:29:08Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
$smarty->assign('shop_logo', htmlspecialchars($_CFG['shop_logo']));
$_REQUEST['id'] = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$article_id = $_REQUEST['id'];
if(isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] < 0)
{
$article_id = $db->getOne("SELECT article_id FROM " . $ecs->table('article') . " WHERE cat_id = '".intval($_REQUEST['cat_id'])."' ");
}
$ip_type=$_REQUEST['ip_type'];
if( $ip_type=="1" ){
$ip = $_REQUEST['ip'];
insertInto($ip);
}
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
$cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));
if (!$smarty->is_cached('article.dwt', $cache_id))
{
/* 文章详情 */
if($_REQUEST['type'] == 'sjs'){
$article = get_article_info_sjs($article_id);
}else if($_REQUEST['type'] == 'fu'){
$article = get_article_info0($article_id);
}else{
$article = get_article_info($article_id);
}
if (empty($article))
{
ecs_header("Location: ./\n");
exit;
}
if (!empty($article['link']) && $article['link'] != 'http://' && $article['link'] != 'https://')
{
ecs_header("location:$article[link]\n");
exit;
}
$smarty->assign('article_categories', article_categories_tree($article_id)); //文章分类树
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('best_goods', get_recommend_goods('best')); // 推荐商品
$smarty->assign('new_goods', get_recommend_goods('new')); // 最新商品
$smarty->assign('hot_goods', get_recommend_goods('hot')); // 热点文章
$smarty->assign('promotion_goods', get_promote_goods()); // 特价商品
$smarty->assign('related_goods', article_related_goods($_REQUEST['id'])); // 特价商品
$smarty->assign('id', $article_id);
$smarty->assign('username', $_SESSION['user_name']);
$smarty->assign('email', $_SESSION['email']);
$smarty->assign('type', '1');
$smarty->assign('promotion_info', get_promotion_info());
/* 验证码相关设置 */
if ((intval($_CFG['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
{
$smarty->assign('enabled_captcha', 1);
$smarty->assign('rand', mt_rand());
}
$smarty->assign('article', $article);
$smarty->assign('keywords', htmlspecialchars($article['keywords']));
$smarty->assign('description', htmlspecialchars($article['description']));
$catlist = array();
foreach(get_article_parent_cats($article['cat_id']) as $k=>$v)
{
$catlist[] = $v['cat_id'];
}
assign_template('a', $catlist);
$position = assign_ur_here($article['cat_id'], $article['title']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('comment_type', 1);
if($type == 'sjs'){
$table = 'ecs_article_sjs';
}else if($type == 'jg'){
$table = 'ecs_article_jg';
}else if($type = 'fu'){
$table = 'ecs_ssj';
}else{
$table = 'ecs_article';
}
/* 相关商品 */
/*$sql = "SELECT a.goods_id, g.goods_name " .
"FROM " . $ecs->table('goods_article') . " AS a, " . $ecs->table('goods') . " AS g " .
"WHERE a.goods_id = g.goods_id " .
"AND a.article_id = '$_REQUEST[id]' ";
$smarty->assign('goods_list', $db->getAll($sql));
*/
/* 上一篇下一篇文章 */
/* $next_article = $db->getRow("SELECT article_id, title FROM " .$table. " WHERE article_id > $article_id AND cat_id=$article[cat_id] AND is_open=1 LIMIT 1");
if (!empty($next_article))
{
$next_article['url'] = build_uri('article', array('aid'=>$next_article['article_id']), $next_article['title']);
$smarty->assign('next_article', $next_article);
}
$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");
if (!empty($prev_aid))
{
$prev_article = $db->getRow("SELECT article_id, title FROM " .$ecs->table('article'). " WHERE article_id = $prev_aid");
$prev_article['url'] = build_uri('article', array('aid'=>$prev_article['article_id']), $prev_article['title']);
$smarty->assign('prev_article', $prev_article);
}*/
assign_dynamic('article');
}
if(isset($article) && $article['cat_id'] > 2)
{
if($article['cat_id'] == 32){
$smarty->display('zt.dwt', $cache_id);
}else{
if($_REQUEST['type'] == 'sjs'){
$smarty->display('article_sjs.dwt', $cache_id);
}else{
$smarty->display('article_jiaru.dwt', $cache_id);
}
}
}
else if($_REQUEST['type'] == 'fu'){
$smarty->display('article_jiaru0.dwt', $cache_id);
}
else
{
$smarty->display('article_pro.dwt', $cache_id);
}
/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */
/**
* 获得指定的文章的详细信息
*
* @access private
* @param integer $article_id
* @return array
*/
function get_article_info($article_id)
{
/* 获得文章的信息 */
$sql = "SELECT a.*, IFNULL(AVG(r.comment_rank), 0) AS comment_rank ".
"FROM " .$GLOBALS['ecs']->table('article'). " AS a ".
"LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".
"WHERE a.is_open = 1 AND a.article_id = '$article_id' GROUP BY a.article_id";
$row = $GLOBALS['db']->getRow($sql);
if ($row !== false)
{
$row['comment_rank'] = ceil($row['comment_rank']); // 用户评论级别取整
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示
/* 作者信息如果为空,则用网站名称替换 */
if (empty($row['author']) || $row['author'] == '_SHOPHELP')
{
$row['author'] = $GLOBALS['_CFG']['shop_name'];
}
}
return $row;
}
/**
* 获得指定的服务商的列表
*
* @access private
* @param integer $article_id
* @return array
*/
function get_article_info0($article_id)
{
/* 获得文章的信息 */
$sql = "SELECT * ".
"FROM " .$GLOBALS['ecs']->table('ssj')." WHERE id = '$article_id' ";
$row = $GLOBALS['db']->getRow($sql);
return $row;
}
/**
*@#* 获得指定设计师的详细信息
*
* @access private
* @param integer $article_id
* @return array
*/
function get_article_info_sjs($article_id)
{
/* 获得文章的信息 */
$sql = "SELECT a.* FROM " .$GLOBALS['ecs']->table('article_sjs'). " AS a WHERE a.id = '$article_id' GROUP BY a.id";
$row = $GLOBALS['db']->getRow($sql);
if ($row !== false)
{
$row['comment_rank'] = ceil($row['comment_rank']); // 用户评论级别取整
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示
/* 作者信息如果为空,则用网站名称替换 */
if (empty($row['author']) || $row['author'] == '_SHOPHELP')
{
$row['author'] = $GLOBALS['_CFG']['shop_name'];
}
}
return $row;
}
/**
* 获得文章关联的商品
*
* @access public
* @param integer $id
* @return array
*/
function article_related_goods($id)
{
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' ga ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = ga.goods_id ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"WHERE ga.article_id = '$id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0";
$res = $GLOBALS['db']->query($sql);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
if ($row['promote_price'] > 0)
{
$arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']);
}
else
{
$arr[$row['goods_id']]['promote_price'] = 0;
}
}
return $arr;
}
?>