4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: Lunat on December 05, 2008, 05:59:00 PM

Title: [MOD] Answers in Comments like on YouTube
Post by: Lunat on December 05, 2008, 05:59:00 PM
Whether it is possible, that users could answer concrete comments to a photo?
I'm need the following: that user could answer each other in comments to photos like on youtube





The answer and solution by alekinna here :
http://www.4homepages.de/forum/index.php?topic=23498.msg130641#msg130641
Title: Re: Answers in comments
Post by: batu544 on December 06, 2008, 12:17:21 PM
Oh !! yes.. by posting a new comment  :mrgreen:

Title: Re: Answers in comments
Post by: Lunat on December 10, 2008, 02:16:12 PM
so, hwo can help?
Title: Re: Answers in comments
Post by: Nicky on December 10, 2008, 02:41:54 PM
Lunat,

in 4images user can post comments to the photo..

or do you mean comments for comment?
Title: Re: Answers in comments
Post by: Lunat on December 10, 2008, 02:46:19 PM
oh ok. I'm know it!  :lol:

I'm need the following: that user could answer each other in comments to photos

P.S. Sorry,for my bad english, I try as I can  :!: :mrgreen:
Title: Re: Answers in comments
Post by: V@no on December 10, 2008, 03:08:53 PM
Something like on youtube?
Title: Re: Answers in comments
Post by: Lunat on December 10, 2008, 03:14:04 PM
Something like on photosight.ru (for example (http://www.photosight.ru/photos/2988702))

V@no русский ты наш человек)) Спасибо за прошлую помощь. Пока ты тут, перехожу на русский. Вот смотри как на фотосайте например тут (http://www.photosight.ru/photos/2988702). в 7 и 9 комментарии. То есть например автор фотки может ответить на конкретный коммент. И получается градация некая...
Title: Re: Answers in comments
Post by: Lunat on December 12, 2008, 04:33:24 PM
and like on youtube. yes.
Title: Re: Answers in comments
Post by: Lunat on December 15, 2008, 12:18:55 PM
People wish to communicate, but often pass answers to the comments. BECAUSE there are no notices  :(
Title: Re: Answers in comments
Post by: alekinna on January 13, 2009, 09:02:18 PM
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
Code: [Select]
$sql = "SELECT c.comment_id, c.user_id AS comment_user_id,
insert into
Code: [Select]
c.response, c.comment_response,
1.1 find
Code: [Select]
if ($comment_row['comment_user_id'] != GUEST) {
add above
Code: [Select]
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
Code: [Select]
$comment_text = un_htmlspecialchars(trim($HTTP_POST_VARS['comment_text']));
add below
Code: [Select]
$response_to = (isset($HTTP_POST_VARS['response_to'])) ? un_htmlspecialchars(trim($HTTP_POST_VARS['response_to'])) : "";
2.1 find
Code: [Select]
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
Code: [Select]
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
Code: [Select]
$sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name,
insert into
Code: [Select]
c.comment_response, c.response,
2.3 find
Code: [Select]
WHERE c.image_id = $image_id
replace with
Code: [Select]
WHERE c.image_id = $image_id AND c.response = 0
2.4 find
Code: [Select]
$comment_user_info = $lang['userlevel_guest'];
add below
Code: [Select]
$comment_headline = format_text($comment_row[$i]['comment_headline'], 0, $config['wordwrap_comments'], 0, 0);
2.5 find
Code: [Select]
$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&amp;comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=removecomment&amp;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&amp;".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['edit']."</a>&nbsp;";
        $admin_links .= ($config['user_delete_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removecomment&amp;".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['delete']."</a>";
      }

add below
Code: [Select]
$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&amp;".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&amp;comment_id=".$response_row['comment_id']))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
            $response_admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=removecomment&amp;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&amp;".URL_COMMENT_ID."=".$response_row['comment_id'])."\">".$lang['edit']."</a>&nbsp;";
            $response_admin_links .= ($config['user_delete_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removecomment&amp;".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
Code: [Select]
"comment_headline" => format_text($comment_row[$i]['comment_headline'], 0, $config['wordwrap_comments'], 0, 0),
replace with
Code: [Select]
"comment_headline" => $comment_headline,
        "responses" => $responses,
        "response_to_id" => $response_to_id,
        "lang_post_response" => $lang['post_response'],

2.7 find
Code: [Select]
$comment_text = (isset($HTTP_POST_VARS['comment_text']) && $error) ? format_text(trim(stripslashes($HTTP_POST_VARS['comment_text'])), 2) : "";
add below
Code: [Select]
$response_to = (isset($HTTP_POST_VARS['response_to']) && $error) ? format_text(trim(stripslashes($HTTP_POST_VARS['response_to'])), 2) : "";
2.8 find
Code: [Select]
"comment_text" => $comment_text,
add below
Code: [Select]
"response_to" => $response_to,
      "lang_clear" => $lang['clear'],
      "lang_clear_desc" => $lang['clear_desc'],


3. in the file lang/your_lang/main.php

add
Code: [Select]
//-----------------------------------------------------
//--- 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
Code: [Select]
$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
Code: [Select]
$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
Code: [Select]
{comment_text}
add below
Code: [Select]
{if responses}<br />{responses}<br />{endif responses}
5.1 for the link "post response" use:
Code: [Select]
<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
Code: [Select]
<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
Code: [Select]
<form name="commentform" action="{self}" method="post" onsubmit="postbutton.disabled=true;">
add below
Code: [Select]
<input type="hidden" name="response_to" value="{response_to}" />
6.2 find
Code: [Select]
<input type="text" name="comment_headline" size="30" value="{comment_headline}" class="commentinput" />
after add
Code: [Select]
<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.
Title: Re: Answers in comments
Post by: om6acw on February 01, 2009, 05:44:13 AM
Nice mod alekinna, but I have problem with your responses_install.php its giving me this error

Code: [Select]
Parse error: syntax error, unexpected ')' in /home/XXXXX/XXXXXXX/responses_install.php on line 16
Title: Re: Answers in comments
Post by: V@no on February 01, 2009, 09:44:34 AM
Please re-download the package again. should be fixed now.
Title: Re: Answers in comments
Post by: fermachado on September 25, 2009, 10:19:52 AM
Hi,

Is possible the response to a comment don't count to the number of comments?

Thanks   
 
Title: Re: [MOD] Answers in Comments like on YouTube
Post by: alekseyn1 on November 24, 2009, 04:44:36 PM
МОD Works great!!

http://www.fotodvor.com/details.php?image_id=191
it's a test site )) no not want it indexed.

Thank you very much!
Title: Re: Answers in comments
Post by: alekseyn1 on November 26, 2009, 03:06:57 PM
Guys, it is possible to indent every reply further right? so that it would look like a discussion tree?
Title: Re: [MOD] Answers in Comments like on YouTube
Post by: alekseyn1 on January 11, 2010, 11:50:51 PM
OK guys!

found a little bottleneck/bug:

if two or more users will be writing an answer (by clicking on "Post response" and making a hidden field <input type="hidden" name="response_to" value="{response_to}" /> not null) then only the latest answer will be posted...

a simple workaround is for two simultanious users only... if 3 people will click on "Post response" and then submit it, only two (presumably will be kept.. i did not test it with more than 2 users)...

Ok... here is the solution:

find SECOND instance of the following code in details.php:
Code: [Select]
 if ($response_to) {
and ADD AFTER

Code: [Select]
//check for response collission (only for 2 simultaneous users)
$sql = "SELECT user_name, comment_id, image_id, comment_response, response
FROM ".COMMENTS_TABLE."
WHERE image_id = $id AND comment_id = $response_to
LIMIT 1";
$row = $site_db->query_firstrow($sql);
if ($row['comment_response'] <> 0) {
$response_to = $row['comment_response'];
}
//end check for response collission

I hope somebody will be able to find a solution to fix this for a very busy site in terms of comments like mine....  :roll: :wink:
Title: Re: [MOD] Answers in Comments like on YouTube
Post by: zakaria666 on August 26, 2010, 10:25:39 PM
how does this mod work. Ive installed it and its not what i expected. It simply does not work. When i click response to post, it just makes another post right on top of the one i want to respond to so its exactly like that when i did not install this MOD. is it suppose to be like this.

Please can anyone answer this please