| 1 |
<?php</span> |
|---|
| 2 |
<span class="code-lang">$root_path = './'; |
|---|
| 3 |
require ($root_path . 'include/config.php'); |
|---|
| 4 |
require ($root_path . 'include/bbcode/bbcode.lib.php'); |
|---|
| 5 |
require ($root_path . 'include/functions_post.php'); |
|---|
| 6 |
|
|---|
| 7 |
$userdata = session_pagestart($user_ip); |
|---|
| 8 |
init_userprefs($userdata); |
|---|
| 9 |
loggedinorreturn(); |
|---|
| 10 |
parked(); |
|---|
| 11 |
check_ban(BAN_COMMENTS); |
|---|
| 12 |
|
|---|
| 13 |
$action = request_var('action', ''); |
|---|
| 14 |
$type = request_var('type', '');</span> |
|---|
| 15 |
<span class="code-lang"> |
|---|
| 16 |
switch ( $type ) { |
|---|
| 17 |
case TYPE_REQUEST: |
|---|
| 18 |
$sql_table = REQUESTS_TABLE; |
|---|
| 19 |
$filename = 'requests'; |
|---|
| 20 |
$field = 'request AS name, id, cat AS category, comments AS comments_count, userid AS owner'; |
|---|
| 21 |
$comment_field = 'comments'; |
|---|
| 22 |
$where_id = 'id'; |
|---|
| 23 |
break; |
|---|
| 24 |
|
|---|
| 25 |
case TYPE_OFFER: |
|---|
| 26 |
$sql_table = OFFERS_TABLE; |
|---|
| 27 |
$filename = 'offers'; |
|---|
| 28 |
$field = 'name, id, category, comments AS comments_count, userid AS owner'; |
|---|
| 29 |
$comment_field = 'comments'; |
|---|
| 30 |
$where_id = 'id'; |
|---|
| 31 |
break; |
|---|
| 32 |
|
|---|
| 33 |
case TYPE_TORRENT: |
|---|
| 34 |
$sql_table = TORRENTS_TABLE; |
|---|
| 35 |
$filename = 'details'; |
|---|
| 36 |
$field = 'name, disable_comments, fid AS id, category, comments AS comments_count, owner'; |
|---|
| 37 |
$comment_field = 'comments'; |
|---|
| 38 |
$where_id = 'fid'; |
|---|
| 39 |
break; |
|---|
| 40 |
|
|---|
| 41 |
case TYPE_NEWS: |
|---|
| 42 |
$sql_table = NEWS_TABLE; |
|---|
| 43 |
$filename = 'news'; |
|---|
| 44 |
$field = 'title AS name, news_disable_comments AS disable_comments, NULL AS category, id, news_comments AS comments_count, userid AS owner'; |
|---|
| 45 |
$comment_field = 'news_comments'; |
|---|
| 46 |
$where_id = 'id'; |
|---|
| 47 |
break; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
switch ( $action ) { |
|---|
| 51 |
case 'smiles': |
|---|
| 52 |
$form = request_var('form', ''); |
|---|
| 53 |
$text = request_var('text', ''); |
|---|
| 54 |
generate_smilies('window', $form, $text); |
|---|
| 55 |
break; |
|---|
| 56 |
|
|---|
| 57 |
case 'add': |
|---|
| 58 |
$id = request_var('tid', 0); |
|---|
| 59 |
$text = request_var('message', ''); |
|---|
| 60 |
|
|---|
| 61 |
switch ( $type ) { |
|---|
| 62 |
case TYPE_REQUEST: |
|---|
| 63 |
$where = 'id = ' . $id; |
|---|
| 64 |
break; |
|---|
| 65 |
|
|---|
| 66 |
case TYPE_OFFER: |
|---|
| 67 |
$where = 'id = ' . $id; |
|---|
| 68 |
break; |
|---|
| 69 |
|
|---|
| 70 |
case TYPE_TORRENT: |
|---|
| 71 |
$where = 'fid = ' . $id; |
|---|
| 72 |
break; |
|---|
| 73 |
|
|---|
| 74 |
case TYPE_NEWS: |
|---|
| 75 |
$where = 'id = ' . $id; |
|---|
| 76 |
$cache->destroy('sql', NEWS_TABLE); |
|---|
| 77 |
break; |
|---|
| 78 |
|
|---|
| 79 |
default: |
|---|
| 80 |
trigger_error('INVALID_TYPE'); |
|---|
| 81 |
break; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
$sql = 'SELECT ' . $field . ' FROM ' . $sql_table . ' WHERE ' . $where; |
|---|
| 85 |
$result = $db->sql_query($sql); |
|---|
| 86 |
if ( !$arr = $db->sql_fetchrow($result) ) { |
|---|
| 87 |
trigger_error(sprintf($lang['invalid_id'], $id)); |
|---|
| 88 |
} |
|---|
| 89 |
if ( isset($arr['disable_comments']) && $arr['disable_comments'] ) { |
|---|
| 90 |
trigger_error($lang['comments_disabled']); |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
if ( isset($_POST['post']) ) { |
|---|
| 94 |
|
|---|
| 95 |
require_once ($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_merge.php'); |
|---|
| 96 |
|
|---|
| 97 |
if ( !$text ) { |
|---|
| 98 |
trigger_error($lang['post_something']); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
if ( preg_match("/\[mod.*?\]/si", $text) && $userdata['class'] < UC_MODERATOR ) { |
|---|
| 102 |
trigger_error($lang['access_denied']); |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
$sql = 'SELECT comment_added, comment_user, comment_id, comment_text |
|---|
| 106 |
FROM ' . COMMENTS_TABLE . ' |
|---|
| 107 |
WHERE comment_for_id = ' . $id . ' AND comment_type = ' . $type . ' |
|---|
| 108 |
ORDER BY comment_id DESC LIMIT 1'; |
|---|
| 109 |
$result = $db->sql_query($sql); |
|---|
| 110 |
$merge_arr = $db->sql_fetchrow($result); |
|---|
| 111 |
|
|---|
| 112 |
$time2merge = intval($config['time_to_merge']) * 3600; |
|---|
| 113 |
$mod_tag = 0; |
|---|
| 114 |
if ( preg_match("/\[mod.*?\]/si", $merge_arr['comment_text']) ) { |
|---|
| 115 |
$mod_tag = 1; |
|---|
| 116 |
} |
|---|
| 117 |
if ( ( $userdata['uid'] == $merge_arr['comment_user'] ) && ( ( time() - $merge_arr['comment_added'] ) < $time2merge ) && !$mod_tag ) { |
|---|
| 118 |
if ( (time() - intval($merge_arr['comment_added'])) < intval($config['merge_flood_interval']) ) { |
|---|
| 119 |
trigger_error($lang['flood_error']); |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
$newid = $merge_arr['comment_id']; |
|---|
| 123 |
|
|---|
| 124 |
$merged_after = (time() - $merge_arr['comment_added']); |
|---|
| 125 |
$merged_sec = $merged_after % 60; |
|---|
| 126 |
$merged_min = ($merged_after/60) % 60; |
|---|
| 127 |
$merged_hours = ($merged_after/3600) % 24 ; |
|---|
| 128 |
$merged_days = ($merged_after/86400) % 31; |
|---|
| 129 |
|
|---|
| 130 |
$s_st = ($merged_sec) ? seconds_st($merged_sec) : ''; |
|---|
| 131 |
$m_st = ($merged_min) ? minutes_st($merged_min) : ''; |
|---|
| 132 |
$h_st = ($merged_hours) ? hours_st($merged_hours) : ''; |
|---|
| 133 |
$d_st = ($merged_days) ? days_st($merged_days) : ''; |
|---|
| 134 |
|
|---|
| 135 |
$separator = sprintf($lang['merge_separator'],$d_st,$h_st,$m_st,$s_st); |
|---|
| 136 |
|
|---|
| 137 |
$updated_comment = "'" . $db->sql_escape($merge_arr['comment_text'] . $separator . $text) . "'"; |
|---|
| 138 |
|
|---|
| 139 |
$sql = 'UPDATE ' . COMMENTS_TABLE . ' SET comment_text = ' . $updated_comment . ', comment_added = ' . time() . ' WHERE comment_id = ' . $merge_arr['comment_id']; |
|---|
| 140 |
$db->sql_query($sql); |
|---|
| 141 |
|
|---|
| 142 |
//$db->sql_query($sql); |
|---|
| 143 |
} |
|---|
| 144 |
else { |
|---|
| 145 |
$sql = 'SELECT MAX(comment_added) AS max_added FROM ' . COMMENTS_TABLE . ' WHERE comment_user = ' . $userdata['uid']; |
|---|
| 146 |
$result = $db->sql_query($sql); |
|---|
| 147 |
$max_added = ( $flood_row = $db->sql_fetchrow($result) ) ? $flood_row['max_added'] : 0; |
|---|
| 148 |
|
|---|
| 149 |
if (intval($flood_row['max_added']) > 0 && (time() - intval($flood_row['max_added'])) < intval($config['flood_interval'])) { |
|---|
| 150 |
trigger_error($lang['flood_error']); |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
$text = "'" . $db->sql_escape($text) . "'"; |
|---|
| 154 |
$sql = 'INSERT INTO ' . COMMENTS_TABLE . ' (comment_user, comment_for_id, comment_added, comment_text, comment_type) VALUES (' . $userdata['uid'] . ', ' . $id . ', ' . time() . ', ' . $text . ', ' . $type . ')'; |
|---|
| 155 |
$db->sql_query($sql); |
|---|
| 156 |
|
|---|
| 157 |
$newid = $db->sql_nextid($sql); |
|---|
| 158 |
|
|---|
| 159 |
$sql = 'UPDATE ' . $sql_table . ' SET ' . $comment_field . ' = ' . $comment_field . ' + 1 WHERE ' . $where; |
|---|
| 160 |
$db->sql_query($sql); |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
$db->sql_query($sql); |
|---|
| 164 |
|
|---|
| 165 |
if ( $userdata['commentpm'] ) { |
|---|
| 166 |
$sql = 'SELECT COUNT(*) AS count FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_for_id = ' . $id . ' AND checkcomm_type = ' . $type . ' AND checkcomm_userid = ' . $userdata['uid']; |
|---|
| 167 |
$result = $db->sql_query($sql); |
|---|
| 168 |
$docheck = ( $row = $db->sql_fetchrow($result) ) ? $row['count'] : 0; |
|---|
| 169 |
if ( !$docheck ) { |
|---|
| 170 |
$sql = 'INSERT INTO ' . COMMENTS_NOTIFY_TABLE . ' (checkcomm_userid, checkcomm_for_id, checkcomm_type, checkcomm_last_comment_id, checkcomm_view_status) VALUES (' . $userdata['uid'] . ', ' . $id . ', ' . $type . ', ' . $newid . ', ' . VIEW_STATUS_VIEWED . ')'; |
|---|
| 171 |
$db->sql_query($sql); |
|---|
| 172 |
} |
|---|
| 173 |
}*/ |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
user_notification($userdata['commentpm'], $type, array('for_id' => $id, 'last_id' => $newid, 'name' => $arr['name'])); |
|---|
| 177 |
redirect( append_sid($root_path . 'comment.php?cid=' . $newid) ); |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
$name = $arr['name']; |
|---|
| 182 |
$short_name = split_string($arr['name'], 55); |
|---|
| 183 |
|
|---|
| 184 |
$tpl = textbbcode($text); |
|---|
| 185 |
$template->assign_vars(array('TEXTBBCODE' => $tpl)); |
|---|
| 186 |
|
|---|
| 187 |
switch ( $type ) { |
|---|
| 188 |
case TYPE_TORRENT: |
|---|
| 189 |
|
|---|
| 190 |
$seo->set_torrent_url($id, $arr['name'], $arr['category']); |
|---|
| 191 |
|
|---|
| 192 |
break; |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
$template->assign_vars(array( |
|---|
| 196 |
'S_FORM_ACTION' => append_sid($root_path . 'comment.php?type=' . $type . '&action=add&tid=' . $id), |
|---|
| 197 |
'NAME' => $short_name, |
|---|
| 198 |
'TYPE' => $type, |
|---|
| 199 |
'ID' => $id, |
|---|
| 200 |
'COMMENTS_COUNT' => $arr['comments_count'], |
|---|
| 201 |
'ADD_NEW_COMMENT' => sprintf($lang['add_comment_to'], append_sid($root_path . $filename . '.php?id=' . $id), $short_name) |
|---|
| 202 |
)); |
|---|
| 203 |
|
|---|
| 204 |
preview_commentable($type, $id, $arr['owner']); |
|---|
| 205 |
|
|---|
| 206 |
stdhead(sprintf($lang['add_comment_to_header'], $name)); |
|---|
| 207 |
$template->set_filenames(array( |
|---|
| 208 |
'body' => 'comments_add_body.html' |
|---|
| 209 |
)); |
|---|
| 210 |
stdfoot(); |
|---|
| 211 |
break; |
|---|
| 212 |
|
|---|
| 213 |
case 'edit': |
|---|
| 214 |
$commentid = request_var('cid', 0); |
|---|
| 215 |
|
|---|
| 216 |
switch ( $type ) { |
|---|
| 217 |
case TYPE_TORRENT: |
|---|
| 218 |
$select = 't.name, t.fid AS id'; |
|---|
| 219 |
$from = TORRENTS_TABLE . ' t'; |
|---|
| 220 |
$where = 'c.comment_for_id = t.fid'; |
|---|
| 221 |
break; |
|---|
| 222 |
|
|---|
| 223 |
case TYPE_REQUEST: |
|---|
| 224 |
$select = 'r.request AS name, r.id'; |
|---|
| 225 |
$from = REQUESTS_TABLE . ' r'; |
|---|
| 226 |
$where = 'c.comment_for_id = r.id'; |
|---|
| 227 |
break; |
|---|
| 228 |
|
|---|
| 229 |
case TYPE_OFFER: |
|---|
| 230 |
$select = 'o.name, o.id'; |
|---|
| 231 |
$from = OFFERS_TABLE . ' o'; |
|---|
| 232 |
$where = 'c.comment_for_id = o.id'; |
|---|
| 233 |
break; |
|---|
| 234 |
|
|---|
| 235 |
case TYPE_NEWS: |
|---|
| 236 |
$select = 'n.title AS name, n.id'; |
|---|
| 237 |
$from = NEWS_TABLE . ' n'; |
|---|
| 238 |
$where = 'c.comment_for_id = n.id'; |
|---|
| 239 |
break; |
|---|
| 240 |
|
|---|
| 241 |
default: |
|---|
| 242 |
trigger_error('INVALID_TYPE'); |
|---|
| 243 |
break; |
|---|
| 244 |
} |
|---|
| 245 |
|
|---|
| 246 |
$sql = 'SELECT c.*, ' . $select . ', u.class |
|---|
| 247 |
FROM ' . COMMENTS_TABLE . ' c LEFT JOIN ' . USERS_TABLE . ' u ON c.comment_editedby = u.uid, ' . $from . ' |
|---|
| 248 |
WHERE c.comment_id = ' . $commentid . ' AND ' . $where; |
|---|
| 249 |
|
|---|
| 250 |
$result = $db->sql_query($sql); |
|---|
| 251 |
|
|---|
| 252 |
if ( !($arr = $db->sql_fetchrow($result)) ) { |
|---|
| 253 |
trigger_error(sprintf($lang['invalid_id'], $commentid)); |
|---|
| 254 |
} |
|---|
| 255 |
|
|---|
| 256 |
if ( $arr['comment_user'] != $userdata['uid'] && $userdata['class'] < UC_MODERATOR ) { |
|---|
| 257 |
trigger_error($lang['access_denied']); |
|---|
| 258 |
} |
|---|
| 259 |
if ( $userdata['class'] < UC_MODERATOR && $arr['class'] >= UC_MODERATOR ) { |
|---|
| 260 |
trigger_error($lang['access_denied']); |
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
if ( isset($_POST['post']) ) { |
|---|
| 264 |
$text = request_var('message', ''); |
|---|
| 265 |
if (!$text) { |
|---|
| 266 |
trigger_error($lang['post_something']); |
|---|
| 267 |
} |
|---|
| 268 |
if (preg_match("/\[mod.*?\]/si", $text) && $userdata['class'] < UC_MODERATOR) { |
|---|
| 269 |
trigger_error($lang['access_denied']); |
|---|
| 270 |
} |
|---|
| 271 |
$editedat = time(); |
|---|
| 272 |
$text = "'" . $db->sql_escape($text) . "'"; |
|---|
| 273 |
$sql = 'UPDATE ' . COMMENTS_TABLE . ' SET comment_text = ' . $text . ', comment_editedat=' . $editedat . ', comment_editedby=' . $userdata['uid'] . ' WHERE comment_id = ' . $commentid; |
|---|
| 274 |
$db->sql_query($sql); |
|---|
| 275 |
redirect( append_sid($filename . '.php?id=' . $arr['id'] . '&viewcomm=' . $commentid) . "#comm" . $commentid); |
|---|
| 276 |
} |
|---|
| 277 |
if( isset($_POST['message']) ) { |
|---|
| 278 |
$arr['comment_text'] = request_var('message', ''); |
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
$name = split_string($arr['name'], 55); |
|---|
| 282 |
$tpl = textbbcode($arr['comment_text']); |
|---|
| 283 |
$template->assign_vars(array('TEXTBBCODE' => $tpl)); |
|---|
| 284 |
$template->assign_vars(array( |
|---|
| 285 |
'S_FORM_ACTION' => append_sid($root_path . 'comment.php?type=' . $type . '&action=edit&cid=' . $commentid), |
|---|
| 286 |
'NAME' => $name, |
|---|
| 287 |
'TYPE' => $type, |
|---|
| 288 |
'ID' => $commentid, |
|---|
| 289 |
'EDIT_COMMENT' => sprintf($lang['edit_comment_to'], $name) ) |
|---|
| 290 |
); |
|---|
| 291 |
|
|---|
| 292 |
stdhead(sprintf($lang['edit_comment_to'], $arr['name'])); |
|---|
| 293 |
$template->set_filenames(array( |
|---|
| 294 |
'body' => 'comments_edit_body.html' |
|---|
| 295 |
)); |
|---|
| 296 |
stdfoot(); |
|---|
| 297 |
break; |
|---|
| 298 |
|
|---|
| 299 |
case 'check': |
|---|
| 300 |
case 'checkoff': |
|---|
| 301 |
$tid = request_var('tid', 0); |
|---|
| 302 |
|
|---|
| 303 |
$sql = 'SELECT COUNT(*) AS count FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_for_id = ' . $tid . ' AND checkcomm_type = ' . $type . ' AND checkcomm_userid = ' . $userdata['uid']; |
|---|
| 304 |
$result = $db->sql_query($sql); |
|---|
| 305 |
$docheck = ( $row = $db->sql_fetchrow($result) ) ? $row['count'] : 0; |
|---|
| 306 |
meta_refresh(3, append_sid($filename . '.php?id=' . $tid)); |
|---|
| 307 |
|
|---|
| 308 |
if ( $docheck && $action == 'check' ) { |
|---|
| 309 |
trigger_error($lang['you_already_check']); |
|---|
| 310 |
} |
|---|
| 311 |
|
|---|
| 312 |
if ( $action == 'check' ) { |
|---|
| 313 |
$sql = 'SELECT comment_id FROM ' . COMMENTS_TABLE . ' WHERE comment_for_id = ' . $tid . ' AND comment_type = ' . $type . ' ORDER BY comment_added DESC'; |
|---|
| 314 |
$result = $db->sql_query_limit($sql, 1); |
|---|
| 315 |
$last_comment_id = ( $row = $db->sql_fetchrow($result) ) ? $row['comment_id'] : 0; |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
$sql = 'INSERT INTO ' . COMMENTS_NOTIFY_TABLE . ' (checkcomm_userid, checkcomm_for_id, checkcomm_type, checkcomm_view_status, checkcomm_last_comment_id) VALUES (' . $userdata['uid'] . ', ' . $tid . ', ' . $type . ', ' . VIEW_STATUS_VIEWED . ', ' . $last_comment_id . ')'; |
|---|
| 319 |
$db->sql_query($sql); |
|---|
| 320 |
trigger_error($lang['now_check_on']); |
|---|
| 321 |
} |
|---|
| 322 |
else { |
|---|
| 323 |
$sql = 'DELETE FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_userid = ' . $userdata['uid'] . ' AND checkcomm_type = ' . $type . ' AND checkcomm_for_id = ' . $tid; |
|---|
| 324 |
$db->sql_query($sql); |
|---|
| 325 |
trigger_error($lang['now_check_off']); |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
break; |
|---|
| 329 |
|
|---|
| 330 |
case 'delete': |
|---|
| 331 |
if ( $userdata['class'] < UC_MODERATOR ) { |
|---|
| 332 |
trigger_error($lang['access_denied']); |
|---|
| 333 |
} |
|---|
| 334 |
$id = request_var('cid', 0); |
|---|
| 335 |
$sure = request_var('sure', 0); |
|---|
| 336 |
|
|---|
| 337 |
if ( !$sure ) { |
|---|
| 338 |
trigger_error(sprintf($lang['are_you_sure'], append_sid($root_path . 'comment.php?type=' . $type . '&action=delete&cid=' . $id . '&sure=1'))); |
|---|
| 339 |
} |
|---|
| 340 |
|
|---|
| 341 |
$sql = 'SELECT c.comment_for_id, ' . $field . ' |
|---|
| 342 |
FROM ' . COMMENTS_TABLE . ' c, ' . $sql_table . ' |
|---|
| 343 |
WHERE c.comment_for_id = ' . $where_id . ' |
|---|
| 344 |
AND comment_id = ' . $id; |
|---|
| 345 |
$result = $db->sql_query($sql); |
|---|
| 346 |
if ( !$arr = $db->sql_fetchrow($result) ) { |
|---|
| 347 |
trigger_error(sprintf($lang['invalid_id'], $id) ); |
|---|
| 348 |
} |
|---|
| 349 |
|
|---|
| 350 |
switch ( $type ) { |
|---|
| 351 |
case TYPE_TORRENT: |
|---|
| 352 |
|
|---|
| 353 |
$seo->set_torrent_url($arr['id'], $arr['name'], $arr['category']); |
|---|
| 354 |
|
|---|
| 355 |
break; |
|---|
| 356 |
} |
|---|
| 357 |
|
|---|
| 358 |
$sql = 'DELETE FROM ' . COMMENTS_TABLE . ' WHERE comment_id = ' . $id; |
|---|
| 359 |
$db->sql_query($sql); |
|---|
| 360 |
|
|---|
| 361 |
$sql = 'DELETE FROM ' . SIMPATY_TABLE . ' WHERE simpid = ' . $id . ' AND type = 1'; |
|---|
| 362 |
$db->sql_query($sql); |
|---|
| 363 |
|
|---|
| 364 |
$sql = 'DELETE FROM ' . REPORTS_TABLE . ' WHERE type = 3 AND votedfor = ' . $id; |
|---|
| 365 |
$db->sql_query($sql); |
|---|
| 366 |
|
|---|
| 367 |
$sql = 'UPDATE ' . COMMENTS_NOTIFY_TABLE . ' SET checkcomm_view_status = ' . VIEW_STATUS_VIEWED . ' WHERE checkcomm_last_comment_id = ' . $id; |
|---|
| 368 |
$db->sql_query($sql); |
|---|
| 369 |
|
|---|
| 370 |
$sql = 'UPDATE ' . $sql_table . ' SET ' . $comment_field . ' = ' . $comment_field . ' - 1 WHERE ' . $where_id . ' = ' . $arr['comment_for_id']; |
|---|
| 371 |
$db->sql_query($sql); |
|---|
| 372 |
|
|---|
| 373 |
redirect( append_sid($root_path . $filename . '.php?id=' . $arr['comment_for_id'])); |
|---|
| 374 |
break; |
|---|
| 375 |
|
|---|
| 376 |
case 'quote': |
|---|
| 377 |
$id = request_var('cid', 0); |
|---|
| 378 |
|
|---|
| 379 |
switch ( $type ) { |
|---|
| 380 |
case TYPE_TORRENT: |
|---|
| 381 |
$select = 't.name, t.fid AS id, t.disable_comments, t.owner'; |
|---|
| 382 |
$from = TORRENTS_TABLE . ' t'; |
|---|
| 383 |
$where = 'c.comment_for_id = t.fid'; |
|---|
| 384 |
break; |
|---|
| 385 |
|
|---|
| 386 |
case TYPE_REQUEST: |
|---|
| 387 |
$select = 'r.request AS name, r.id, r.userid AS owner'; |
|---|
| 388 |
$from = REQUESTS_TABLE . ' r'; |
|---|
| 389 |
$where = 'c.comment_for_id = r.id'; |
|---|
| 390 |
break; |
|---|
| 391 |
|
|---|
| 392 |
case TYPE_OFFER: |
|---|
| 393 |
$select = 'o.name, o.id, o.userid AS owner'; |
|---|
| 394 |
$from = OFFERS_TABLE . ' o'; |
|---|
| 395 |
$where = 'c.comment_for_id = o.id'; |
|---|
| 396 |
break; |
|---|
| 397 |
|
|---|
| 398 |
case TYPE_NEWS: |
|---|
| 399 |
$select = 'n.title AS name, n.id, n.news_disable_comments AS disable_comments, n.userid AS owner'; |
|---|
| 400 |
$from = NEWS_TABLE . ' n'; |
|---|
| 401 |
$where = 'c.comment_for_id = n.id'; |
|---|
| 402 |
$cache->destroy('sql', NEWS_TABLE); |
|---|
| 403 |
break; |
|---|
| 404 |
} |
|---|
| 405 |
|
|---|
| 406 |
$sql = 'SELECT c.*, u.name AS username, u.privacy, u.uid, ' . $select . ' |
|---|
| 407 |
FROM ' . COMMENTS_TABLE . ' c, ' . USERS_TABLE . ' u, ' . $from . ' |
|---|
| 408 |
WHERE c.comment_id = ' . $id . ' AND ' . $where . ' AND comment_type = ' . $type . ' AND c.comment_user = u.uid'; |
|---|
| 409 |
|
|---|
| 410 |
$result = $db->sql_query($sql); |
|---|
| 411 |
if ( !($arr = $db->sql_fetchrow($result)) ) { |
|---|
| 412 |
trigger_error(sprintf($lang['invalid_id'], $id)); |
|---|
| 413 |
} |
|---|
| 414 |
if ( isset($arr['disable_comments']) && $arr['disable_comments'] ) { |
|---|
| 415 |
trigger_error($lang['comments_disabled']); |
|---|
| 416 |
} |
|---|
| 417 |
$name = split_string($arr['name'], 55); |
|---|
| 418 |
|
|---|
| 419 |
$username = ( $arr['uid'] == ANONYMOUS || ( $arr['privacy'] == PRIVACY_LEVEL_HIGH && $arr['owner'] == $arr['uid'] ) ? $lang['unknown'] : $arr['username'] ); |
|---|
| 420 |
|
|---|
| 421 |
$quoted_text = '[quote="' . $username . '"]' . $arr['comment_text'] . '[/quote]'; |
|---|
| 422 |
|
|---|
| 423 |
$tpl = textbbcode(trim($quoted_text)); |
|---|
| 424 |
$template->assign_vars(array('TEXTBBCODE' => $tpl)); |
|---|
| 425 |
|
|---|
| 426 |
$template->assign_vars(array( |
|---|
| 427 |
'S_FORM_ACTION' => append_sid($root_path . 'comment.php?type=' . $type . '&action=add&tid=' . $arr['id']), |
|---|
| 428 |
'NAME' => $name, |
|---|
| 429 |
'TYPE' => $type, |
|---|
| 430 |
'ID' => $arr['id'], |
|---|
| 431 |
'ADD_NEW_COMMENT' => sprintf($lang['add_comment_to'], append_sid($filename . '.php?id=' . $arr['id']), $name), |
|---|
| 432 |
)); |
|---|
| 433 |
|
|---|
| 434 |
preview_commentable($type, $arr['id'], $arr['owner']); |
|---|
| 435 |
|
|---|
| 436 |
stdhead(sprintf($lang['add_comment_to_header'], $name)); |
|---|
| 437 |
$template->set_filenames(array( |
|---|
| 438 |
'body' => 'comments_add_body.html' |
|---|
| 439 |
)); |
|---|
| 440 |
stdfoot(); |
|---|
| 441 |
break; |
|---|
| 442 |
|
|---|
| 443 |
case 'mass_delete': |
|---|
| 444 |
if ( $userdata['class'] < UC_MODERATOR ) { |
|---|
| 445 |
trigger_error('access_denied'); |
|---|
| 446 |
} |
|---|
| 447 |
|
|---|
| 448 |
$comm_ary = request_var('comment', array( 0 => 0 )); |
|---|
| 449 |
$id = request_var('id', 0); |
|---|
| 450 |
$type = request_var('type', 0); |
|---|
| 451 |
|
|---|
| 452 |
$sql = 'SELECT ' . $field . ' FROM ' . $sql_table . ' WHERE ' . $where_id . ' = ' . $id; |
|---|
| 453 |
$result = $db->sql_query($sql); |
|---|
| 454 |
if ( !$redirect_row = $db->sql_fetchrow($result) ) { |
|---|
| 455 |
trigger_error(sprintf($lang['invalid_id'], $id)); |
|---|
| 456 |
} |
|---|
| 457 |
|
|---|
| 458 |
switch ( $type ) { |
|---|
| 459 |
case TYPE_TORRENT: |
|---|
| 460 |
|
|---|
| 461 |
$seo->set_torrent_url($redirect_row['id'], $redirect_row['name'], $redirect_row['category']); |
|---|
| 462 |
|
|---|
| 463 |
break; |
|---|
| 464 |
} |
|---|
| 465 |
|
|---|
| 466 |
if ( $comm_size = sizeof($comm_ary) ) { |
|---|
| 467 |
$sql = 'UPDATE ' . $sql_table . ' SET ' . $comment_field . ' = ' . $comment_field . ' - ' . $comm_size . ' WHERE ' . $where_id . ' = ' . $id; |
|---|
| 468 |
$db->sql_query($sql); |
|---|
| 469 |
|
|---|
| 470 |
$sql = 'DELETE FROM ' . COMMENTS_TABLE . ' WHERE ' . $db->sql_in_set('comment_id', $comm_ary); |
|---|
| 471 |
$db->sql_query($sql); |
|---|
| 472 |
|
|---|
| 473 |
$sql = 'DELETE FROM ' . SIMPATY_TABLE . ' WHERE ' . $db->sql_in_set('simpid', $comm_ary) . ' AND type = ' . SIMPATY_COMMENT; |
|---|
| 474 |
$db->sql_query($sql); |
|---|
| 475 |
|
|---|
| 476 |
$sql = 'DELETE FROM ' . REPORTS_TABLE . ' WHERE type = 3 AND ' . $db->sql_in_set('votedfor', $comm_ary); |
|---|
| 477 |
$db->sql_query($sql); |
|---|
| 478 |
|
|---|
| 479 |
$sql = 'UPDATE ' . COMMENTS_NOTIFY_TABLE . ' SET checkcomm_view_status = ' . VIEW_STATUS_VIEWED . ' WHERE ' . $db->sql_in_set('checkcomm_last_comment_id', $comm_ary);; |
|---|
| 480 |
$db->sql_query($sql); |
|---|
| 481 |
} |
|---|
| 482 |
|
|---|
| 483 |
redirect(append_sid($root_path . $filename . '.php?id=' . $id . '&view=comments')); |
|---|
| 484 |
break; |
|---|
| 485 |
|
|---|
| 486 |
default: |
|---|
| 487 |
$id = request_var('cid', 0); |
|---|
| 488 |
|
|---|
| 489 |
$sql = 'SELECT comment_for_id, comment_type FROM ' . COMMENTS_TABLE . ' WHERE comment_id = ' . $id; |
|---|
| 490 |
$result = $db->sql_query($sql); |
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 494 |
$sql = 'SELECT COUNT(*) AS count FROM ' . COMMENTS_TABLE . ' WHERE comment_type = ' . $row['comment_type'] . ' AND comment_for_id = ' . $row['comment_for_id'] . ' AND comment_id <= ' . $id; |
|---|
| 495 |
$result = $db->sql_query( $sql ); |
|---|
| 496 |
$page = ( $page_row = $db->sql_fetchrow( $result ) ) ? ceil( $page_row['count'] / $config['posts_per_page'] ) : 1; |
|---|
| 497 |
|
|---|
| 498 |
switch ( $row['comment_type'] ) { |
|---|
| 499 |
case TYPE_TORRENT: |
|---|
| 500 |
$sql = 'SELECT name, fid AS id, category FROM ' . TORRENTS_TABLE . ' WHERE fid = ' . $row['comment_for_id']; |
|---|
| 501 |
$filename = 'details'; |
|---|
| 502 |
break; |
|---|
| 503 |
|
|---|
| 504 |
case TYPE_REQUEST: |
|---|
| 505 |
$sql = 'SELECT request AS name, id, cat AS category FROM ' . REQUESTS_TABLE . ' WHERE id = ' . $row['comment_for_id']; |
|---|
| 506 |
$filename = 'requests'; |
|---|
| 507 |
break; |
|---|
| 508 |
|
|---|
| 509 |
case TYPE_OFFER: |
|---|
| 510 |
$sql = 'SELECT name, id, category FROM ' . OFFERS_TABLE . ' WHERE id = ' . $row['comment_for_id']; |
|---|
| 511 |
$filename = 'offers'; |
|---|
| 512 |
break; |
|---|
| 513 |
|
|---|
| 514 |
case TYPE_NEWS: |
|---|
| 515 |
$sql = 'SELECT title AS name, NULL AS category, id FROM ' . NEWS_TABLE . ' WHERE id = ' . $row['comment_for_id']; |
|---|
| 516 |
$filename = 'news'; |
|---|
| 517 |
break; |
|---|
| 518 |
} |
|---|
| 519 |
$result = $db->sql_query($sql); |
|---|
| 520 |
$redirect_row = $db->sql_fetchrow($result); |
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
$seo->set_torrent_url($redirect_row['id'], $redirect_row['name'], $redirect_row['category']); |
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
redirect(append_sid($root_path . $filename . '.php?id=' . $row['comment_for_id'] . '&page=' . $page . '&viewcomm=' . $id) . '#comm' . $id); |
|---|
| 527 |
} |
|---|
| 528 |
else { |
|---|
| 529 |
trigger_error('comment_not_found'); |
|---|
| 530 |
} |
|---|
| 531 |
break; |
|---|
| 532 |
} |
|---|
| 533 |
?> |
|---|
| 534 |
|
|---|