Hi all,
I know that Lunat already use my solution on his site, but we don't shure that found all bugs.
I trust on your help.
1. in the file member.php
find line with
$sql = "SELECT c.comment_id, c.user_id AS comment_user_id,
insert into
c.response, c.comment_response,
1.1 find
if ($comment_row['comment_user_id'] != GUEST) {
add above
if ($comment_row['comment_response'] != 0 && $comment_row['response'] != 0) {
$sql = "UPDATE ".COMMENTS_TABLE."
SET comment_response = ".$comment_row['comment_response']."
WHERE comment_response = ".$comment_row['comment_id'];
$site_db->query($sql);
}
elseif ($comment_row['response'] && $comment_row['comment_response'] == 0) {
$sql = "UPDATE ".COMMENTS_TABLE."
SET comment_response = 0
WHERE comment_response = ".$comment_row['comment_id'];
$site_db->query($sql);
}
elseif ($comment_row['comment_response'] && $comment_row['response'] == 0) {
$response_id = $comment_row['comment_response'];
while ($response_id != 0) {
$sql = "SELECT comment_id, user_id, comment_response
FROM ".COMMENTS_TABLE."
WHERE comment_id = $response_id";
$row = $site_db->query_firstrow($sql);
$response_id = $row['comment_response'];
$com_id = $row['comment_id'];
$sql = "DELETE FROM ".COMMENTS_TABLE."
WHERE comment_id = $com_id";
$site_db->query($sql);
update_comment_count($comment_row['image_id'], $row['user_id']);
}
}
2. in the file details.php
find
$comment_text = un_htmlspecialchars(trim($HTTP_POST_VARS['comment_text']));
add below
$response_to = (isset($HTTP_POST_VARS['response_to'])) ? un_htmlspecialchars(trim($HTTP_POST_VARS['response_to'])) : "";
2.1 find
if (!$error) {
$sql = "INSERT INTO ".COMMENTS_TABLE."
(image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
VALUES
($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
$site_db->query($sql);
$commentid = $site_db->get_insert_id();
update_comment_count($id, $user_info['user_id']);
$msg = $lang['comment_success'];
replace with
if (!$error) {
if ($response_to) {
$response = 1;
} else {$response = 0;}
$sql = "INSERT INTO ".COMMENTS_TABLE."
(image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date, response)
VALUES
($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().", '$response')";
$site_db->query($sql);
$commentid = $site_db->get_insert_id();
update_comment_count($id, $user_info['user_id']);
$msg = $lang['comment_success'];
if ($response_to) {
$sql = "UPDATE ".COMMENTS_TABLE."
SET comment_response = '$commentid'
WHERE comment_id = $response_to";
$site_db->query($sql);
}
2.2 find line with
$sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name,
insert into
c.comment_response, c.response,
2.3 find
WHERE c.image_id = $image_id
replace with
WHERE c.image_id = $image_id AND c.response = 0
2.4 find
$comment_user_info = $lang['userlevel_guest'];
add below
$comment_headline = format_text($comment_row[$i]['comment_headline'], 0, $config['wordwrap_comments'], 0, 0);
2.5 find
$admin_links = "";
if ($user_info['user_level'] == ADMIN) {
$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=editcomment&comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['edit']."</a> ";
$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=removecomment&comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['delete']."</a>";
}
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editcomment&".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['edit']."</a> ";
$admin_links .= ($config['user_delete_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removecomment&".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['delete']."</a>";
}
add below
$responses = "";
$response_comment_id = "";
if ($comment_row[$i]['comment_response'] != 0) {
$bg_number = $bgcounter;
$response_bg = ($bg_number++ % 2 == 0) ? 1 : 2;
$responses .= "<br /><table width=\"90%\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" style=\"border: 1px solid #004C75;\">\n";
$response_row['comment_response'] = $comment_row[$i]['comment_response'];
while ($response_row['comment_response'] != 0) {
$sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS response_user_name, c.comment_headline, c.comment_text, c.comment_ip, c.comment_date, c.comment_response".get_user_table_field(", u.", "user_level").get_user_table_field(", u.", "user_name")."
FROM ".COMMENTS_TABLE." c
LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = c.user_id)
WHERE c.comment_id = ".$response_row['comment_response'];
$response_row = $site_db->query_firstrow($sql);
$response_user_name = format_text($response_row['response_user_name'], 2);
$response_user_info = $lang['userlevel_guest'];
$response_user_id = $response_row['user_id'];
$response_date = format_date($config['date_format']." ".$config['time_format'], $response_row['comment_date']);
$response_text = format_text($response_row['comment_text'], $config['html_comments'], $config['wordwrap_comments'], $config['bb_comments'], $config['bb_img_comments']);
$response_comment_id = $response_row['comment_id'];
if (isset($response_row[$user_table_fields['user_name']]) && $response_user_id != GUEST) {
$response_user_profile_link = !empty($url_show_profile) ? $site_sess->url(preg_replace("/{user_id}/", $response_user_id, $url_show_profile)) : $site_sess->url(ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$response_user_id);
$response_user_name = "<a href=\"".$response_user_profile_link."\">".format_text($response_row[$user_table_fields['user_name']], 2)."</a>";
if (!isset($response_row[$user_table_fields['user_level']]) || (isset($response_row[$user_table_fields['user_level']]) && $response_row[$user_table_fields['user_level']] == USER)) {
$response_user_info = $lang['userlevel_user'];
}
elseif ($response_row[$user_table_fields['user_level']] == ADMIN) {
$response_user_info = $lang['userlevel_admin'];
}
}
$response_user_ip = ($user_info['user_level'] == ADMIN) ? $response_row['comment_ip'] : "";
$response_admin_links = "";
if ($user_info['user_level'] == ADMIN) {
$response_admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=editcomment&comment_id=".$response_row['comment_id']))."\" target=\"_blank\">".$lang['edit']."</a> ";
$response_admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=removecomment&comment_id=".$response_row['comment_id']))."\" target=\"_blank\">".$lang['delete']."</a>";
}
elseif ($is_image_owner) {
$response_admin_links .= ($config['user_edit_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editcomment&".URL_COMMENT_ID."=".$response_row['comment_id'])."\">".$lang['edit']."</a> ";
$response_admin_links .= ($config['user_delete_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removecomment&".URL_COMMENT_ID."=".$response_row['comment_id'])."\">".$lang['delete']."</a>";
}
$responses .= "<tr>\n<a name=\"comment".$response_comment_id."\"></a>\n<td class=\"commentrow".$response_bg."\">\n";
$responses .= "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
$responses .= "<tr>\n<td><b>".$lang['response'].$response_user_name."</b> (".$response_user_info.")</td>\n";
$responses .= "<td align=\"right\">".$response_date."</td>\n</tr>\n";
$responses .= "<tr>\n<td colspan=\"2\"><hr>\n".$response_text."</td>\n</tr>\n";
$responses .= "<tr>\n<td>".$response_user_ip."</td>\n";
$responses .= "<td align=\"right\">".$response_admin_links."</td>\n</tr>\n";
$responses .= "</table>\n</td>\n</tr>\n";
$response_bg = ($bg_number++ % 2 == 0) ? 1 : 2;
}
$responses .= "</table>\n";
}
$response_to_id = "";
if ($response_comment_id) {
$response_to_id .= $response_comment_id;
} else {
$response_to_id .= $comment_row[$i]['comment_id'];
}
2.6 find
"comment_headline" => format_text($comment_row[$i]['comment_headline'], 0, $config['wordwrap_comments'], 0, 0),
replace with
"comment_headline" => $comment_headline,
"responses" => $responses,
"response_to_id" => $response_to_id,
"lang_post_response" => $lang['post_response'],
2.7 find
$comment_text = (isset($HTTP_POST_VARS['comment_text']) && $error) ? format_text(trim(stripslashes($HTTP_POST_VARS['comment_text'])), 2) : "";
add below
$response_to = (isset($HTTP_POST_VARS['response_to']) && $error) ? format_text(trim(stripslashes($HTTP_POST_VARS['response_to'])), 2) : "";
2.8 find
"comment_text" => $comment_text,
add below
"response_to" => $response_to,
"lang_clear" => $lang['clear'],
"lang_clear_desc" => $lang['clear_desc'],
3. in the file lang/your_lang/main.php
add
//-----------------------------------------------------
//--- Mod Responses to Comment -------------------------
// ----------------------------------------------------
$lang['response'] = "Response: ";
$lang['post_response'] = "Post response";
$lang['clear'] = "Clear";
$lang['clear_desc'] = "<span class=\"small\"> - will saved as a new comment (not response)</span>";
4. in the file admin/comments.php
find
$sql = "SELECT comment_id, image_id, user_id, user_name, comment_headline
FROM ".COMMENTS_TABLE."
WHERE comment_id IN ($comment_ids)";
$comment_result = $site_db->query($sql);
while ($comment_row = $site_db->fetch_array($comment_result)) {
replace with
$sql = "SELECT comment_id, image_id, user_id, user_name, comment_headline, response, comment_response
FROM ".COMMENTS_TABLE."
WHERE comment_id IN ($comment_ids)";
$comment_result = $site_db->query($sql);
while ($comment_row = $site_db->fetch_array($comment_result)) {
if ($comment_row['comment_response'] != 0 && $comment_row['response'] != 0) {
$sql = "UPDATE ".COMMENTS_TABLE."
SET comment_response = ".$comment_row['comment_response']."
WHERE comment_response = ".$comment_row['comment_id'];
$site_db->query($sql);
}
elseif ($comment_row['response'] && $comment_row['comment_response'] == 0) {
$sql = "UPDATE ".COMMENTS_TABLE."
SET comment_response = 0
WHERE comment_response = ".$comment_row['comment_id'];
$site_db->query($sql);
}
elseif ($comment_row['comment_response'] && $comment_row['response'] == 0) {
$response_id = $comment_row['comment_response'];
while ($response_id != 0) {
$sql = "SELECT comment_id, user_id, comment_response
FROM ".COMMENTS_TABLE."
WHERE comment_id = $response_id";
$row = $site_db->query_firstrow($sql);
$response_id = $row['comment_response'];
$com_id = $row['comment_id'];
$sql = "DELETE FROM ".COMMENTS_TABLE."
WHERE comment_id = $com_id";
$site_db->query($sql);
update_comment_count($comment_row['image_id'], $row['user_id']);
}
}
5. in the file comment_bit.html
find
{comment_text}
add below
{if responses}<br />{responses}<br />{endif responses}
5.1 for the link "post response" use:
<a href="#comment_form" onClick="get_link('{comment_headline}', '{response_to_id}')" /><b>{lang_post_response}</b></a>
6. in the file comment_form.html
before all content add
<script language="javascript" type="text/javascript">
function get_link(headline, hidden_id){
document.commentform.comment_headline.value=headline
document.commentform.response_to.value=hidden_id
}
function clear_link() {
document.commentform.comment_headline.value=""
document.commentform.response_to.value=""
}
</script>
<a name="comment_form"></a>
6.1 find
<form name="commentform" action="{self}" method="post" onsubmit="postbutton.disabled=true;">
add below
<input type="hidden" name="response_to" value="{response_to}" />
6.2 find
<input type="text" name="comment_headline" size="30" value="{comment_headline}" class="commentinput" />
after add
<br /><a href="#comment_form" onClick="clear_link()">{lang_clear}</a>{lang_clear_desc}
7. install mod
upload to root directory the atached file responses_install.php, install mod and delete this file from your server.