-
Notifications
You must be signed in to change notification settings - Fork 5
/
message.php
250 lines (219 loc) · 10.2 KB
/
message.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
<?php
/**
* ECSHOP 留言板
* ============================================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: message.php 17217 2011-01-19 06:29:08Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if (empty($_CFG['message_board']))
{
show_message($_LANG['message_board_close']);
}
$action = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';
if ($action == 'act_add_message')
{
include_once(ROOT_PATH . 'includes/lib_clips.php');
/* 验证码防止灌水刷屏 */
if ((intval($_CFG['captcha']) & CAPTCHA_MESSAGE) && gd_version() > 0)
{
include_once('includes/cls_captcha.php');
$validator = new captcha();
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
}
else
{
/* 没有验证码时,用时间来限制机器人发帖或恶意发评论 */
if (!isset($_SESSION['send_time']))
{
$_SESSION['send_time'] = 0;
}
$cur_time = gmtime();
if (($cur_time - $_SESSION['send_time']) < 30) // 小于30秒禁止发评论
{
show_message($_LANG['cmt_spam_warning']);
}
}
$user_name = '';
if (empty($_POST['anonymous']) && !empty($_SESSION['user_name']))
{
$user_name = $_SESSION['user_name'];
}
elseif (!empty($_POST['anonymous']) && !isset($_POST['user_name']))
{
$user_name = $_LANG['anonymous'];
}
elseif (empty($_POST['user_name']))
{
$user_name = $_LANG['anonymous'];
}
else
{
$user_name = htmlspecialchars(trim($_POST['user_name']));
}
$user_id = !empty($_SESSION['user_id']) ? $_SESSION['user_id'] : 0;
$message = array(
'user_id' => $user_id,
'user_name' => $user_name,
'user_email' => isset($_POST['user_email']) ? htmlspecialchars(trim($_POST['user_email'])) : '',
'msg_type' => isset($_POST['msg_type']) ? intval($_POST['msg_type']) : 0,
'msg_title' => isset($_POST['msg_title']) ? trim($_POST['msg_title']) : '',
'msg_content' => isset($_POST['msg_content']) ? trim($_POST['msg_content']) : '',
'order_id' => 0,
'msg_area' => 1,
'upload' => array()
);
if (add_message($message))
{
if (intval($_CFG['captcha']) & CAPTCHA_MESSAGE)
{
unset($_SESSION[$validator->session_word]);
}
else
{
$_SESSION['send_time'] = $cur_time;
}
$msg_info = $_CFG['message_check'] ? $_LANG['message_submit_wait'] : $_LANG['message_submit_done'];
show_message($msg_info, $_LANG['message_list_lnk'], 'message.php');
}
else
{
$err->show($_LANG['message_list_lnk'], 'message.php');
}
}
if ($action == 'default')
{
assign_template();
$position = assign_ur_here(0, $_LANG['message_board']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('cat_list', cat_list(0, 0, true, 2, false));
$smarty->assign('brand_list', get_brand_list());
$smarty->assign('promotion_info', get_promotion_info());
$smarty->assign('enabled_mes_captcha', (intval($_CFG['captcha']) & CAPTCHA_MESSAGE));
$sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('comment')." WHERE STATUS =1 AND comment_type =0 ";
$record_count = $db->getOne($sql);
$sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('feedback')." WHERE `msg_area`='1' AND `msg_status` = '1' ";
$record_count += $db->getOne($sql);
/* 获取留言的数量 */
$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
$pagesize = get_library_number('message_list', 'message_board');
$pager = get_pager('message.php', array(), $record_count, $page, $pagesize);
$msg_lists = get_msg_list($pagesize, $pager['start']);
assign_dynamic('message_board');
$smarty->assign('rand', mt_rand());
$smarty->assign('msg_lists', $msg_lists);
$smarty->assign('pager', $pager);
$smarty->display('message_board.dwt');
}
/**
* 获取留言的详细信息
*
* @param integer $num
* @param integer $start
*
* @return array
*/
function get_msg_list($num, $start)
{
/* 获取留言数据 */
$msg = array();
$mysql_ver = $GLOBALS['db']->version();
if($mysql_ver > '3.2.3')
{
$sql = "(SELECT 'comment' AS tablename, comment_id AS ID, content AS msg_content, null AS msg_title, add_time AS msg_time, id_value AS id_value, comment_rank AS comment_rank, null AS message_img, user_name AS user_name, '6' AS msg_type ";
$sql .= " FROM " .$GLOBALS['ecs']->table('comment');
$sql .= "WHERE STATUS =1 AND comment_type =0) ";
$sql .= " UNION ";
$sql .= "(SELECT 'feedback' AS tablename, msg_id AS ID, msg_content AS msg_content, msg_title AS msg_title, msg_time AS msg_time, null AS id_value, null AS comment_rank, message_img AS message_img, user_name AS user_name, msg_type AS msg_type ";
$sql .= " FROM " .$GLOBALS['ecs']->table('feedback');
$sql .= " WHERE `msg_area`='1' AND `msg_status` = '1') ";
$sql .= " ORDER BY msg_time DESC ";
}
else
{
$con_sql = "SELECT 'comment' AS tablename, comment_id AS ID, content AS msg_content, null AS msg_title, add_time AS msg_time, id_value AS id_value, comment_rank AS comment_rank, null AS message_img, user_name AS user_name, '6' AS msg_type ";
$con_sql .= " FROM " .$GLOBALS['ecs']->table('comment');
$con_sql .= "WHERE STATUS =1 AND comment_type =0 ";
$fee_sql = "SELECT 'feedback' AS tablename, msg_id AS ID, msg_content AS msg_content, msg_title AS msg_title, msg_time AS msg_time, null AS id_value, null AS comment_rank, message_img AS message_img, user_name AS user_name, msg_type AS msg_type ";
$fee_sql .= " FROM " .$GLOBALS['ecs']->table('feedback');
$fee_sql .= " WHERE `msg_area`='1' AND `msg_status` = '1' ";
$cre_con = "CREATE TEMPORARY TABLE tmp_table ".$con_sql;
$GLOBALS['db']->query($cre_con);
$cre_con = "INSERT INTO tmp_table ".$fee_sql;
$GLOBALS['db']->query($cre_con);
$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('tmp_table') . " ORDER BY msg_time DESC ";
}
$res = $GLOBALS['db']->SelectLimit($sql, $num, $start);
while ($rows = $GLOBALS['db']->fetchRow($res))
{
for($i = 0; $i < count($rows); $i++)
{
$msg[$rows['msg_time']]['user_name'] = htmlspecialchars($rows['user_name']);
$msg[$rows['msg_time']]['msg_content'] = str_replace('\r\n', '<br />', htmlspecialchars($rows['msg_content']));
$msg[$rows['msg_time']]['msg_content'] = str_replace('\n', '<br />', $msg[$rows['msg_time']]['msg_content']);
$msg[$rows['msg_time']]['msg_time'] = local_date($GLOBALS['_CFG']['time_format'], $rows['msg_time']);
$msg[$rows['msg_time']]['msg_type'] = $GLOBALS['_LANG']['message_type'][$rows['msg_type']];
$msg[$rows['msg_time']]['msg_title'] = nl2br(htmlspecialchars($rows['msg_title']));
$msg[$rows['msg_time']]['message_img'] = $rows['message_img'];
$msg[$rows['msg_time']]['tablename'] = $rows['tablename'];
if(isset($rows['order_id']))
{
$msg[$rows['msg_time']]['order_id'] = $rows['order_id'];
}
$msg[$rows['msg_time']]['comment_rank'] = $rows['comment_rank'];
$msg[$rows['msg_time']]['id_value'] = $rows['id_value'];
/*如果id_value为true为商品评论,根据商品id取出商品名称*/
if($rows['id_value'])
{
$sql_goods = "SELECT goods_name FROM ".$GLOBALS['ecs']->table('goods');
$sql_goods .= "WHERE goods_id= ".$rows['id_value'];
$goods_res = $GLOBALS['db']->getRow($sql_goods);
$msg[$rows['msg_time']]['goods_name'] = $goods_res['goods_name'];
$msg[$rows['msg_time']]['goods_url'] = build_uri('goods', array('gid' => $rows['id_value']), $goods_res['goods_name']);
}
}
$msg[$rows['msg_time']]['tablename'] = $rows['tablename'];
$id = $rows['ID'];
$reply = array();
if(isset($msg[$rows['msg_time']]['tablename']))
{
$table_name = $msg[$rows['msg_time']]['tablename'];
if ($table_name == 'feedback')
{
$sql = "SELECT user_name AS re_name, user_email AS re_email, msg_time AS re_time, msg_content AS re_content ,parent_id".
" FROM " .$GLOBALS['ecs']->table('feedback') .
" WHERE parent_id = '" . $id. "'";
}
else
{
$sql = 'SELECT user_name AS re_name, email AS re_email, add_time AS re_time, content AS re_content ,parent_id
FROM ' . $GLOBALS['ecs']->table('comment') .
" WHERE parent_id = $id ";
}
$reply = $GLOBALS['db']->getRow($sql);
if ($reply)
{
$msg[$rows['msg_time']]['re_name'] = $reply['re_name'];
$msg[$rows['msg_time']]['re_email'] = $reply['re_email'];
$msg[$rows['msg_time']]['re_time'] = local_date($GLOBALS['_CFG']['time_format'], $reply['re_time']);
$msg[$rows['msg_time']]['re_content'] = nl2br(htmlspecialchars($reply['re_content']));
}
}
}
return $msg;
}
?>