Author Topic: Directing user to comment when comment is made (Request MOD)  (Read 13305 times)

0 Members and 1 Guest are viewing this topic.

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Directing user to comment when comment is made (Request MOD)
« on: September 07, 2010, 04:26:41 AM »
Thank you 4images support staff for helping me with alot of problems ive had. Especially Vano, remembrant and mewazni.

This is probebly the most easiest MOD anyone will ever request  :lol: :lol: :lol: :lol: :lol: at least i hope so. Ive been searching google to try and find out how to do this but i totally suckkkkk and cannot even find a solution. My problem is redirecting the user to the comment once the comment is made. Ok for example. Vano has helped me to put the comments as ASC and not DESC so any new comment will be shown at the top and not the bottom. But this means the user has to scroll down to the comment box to make a comment ( lets say theres 100 comments) it will take the user a hell of a long time to scroll to the comment box. And when they do get to the comments box then they will type in there header, comment and then verification code, hit the submit button and then have to scroll all the way up to again to view there comment.
 
I know what you might say, use the paging for coments. Believe me i have, but it hates me and creates so much problems for me. So the request is if the user hits the button submit that they are redirected back to the top of the comment page to where there comment is left. I hope ive made my self clear. Sometimes i just go on and on. lol  :lol:

Thanks  :mrgreen: :mrgreen:

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Directing user to comment when comment is made (Request MOD)
« Reply #1 on: September 07, 2010, 05:50:47 AM »
Are you using AJAX comments?
If not, then in details.php find:
      redirect(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode "").(($page 1) ? "&page=".$page ""));

Replace it with:
      redirect(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode "").(($page 1) ? "&page=".$page "")."#comment".$commentid);
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Re: Directing user to comment when comment is made (Request MOD)
« Reply #2 on: September 07, 2010, 01:59:52 PM »
@VANO,

God bless you for your reply. I am using ajax comments sir  :( would this not work then?

thanx

***************************************** UPdate **************************
I am using version 1.7.7 and i cannot seem to find the below code in details.php and im also using ajaxcomments.php and i cannot find the code in that too

Code: [Select]
      redirect(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode : "").(($page > 1) ? "&page=".$page : ""));
**************************************************************************
« Last Edit: September 07, 2010, 02:16:10 PM by zakaria666 »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Directing user to comment when comment is made (Request MOD)
« Reply #3 on: September 07, 2010, 03:24:40 PM »
* V@no confused as ajax comments doesn't refresh the page, the poster stays at the comment form after posting comment...

anyhow, in details.php find:
      update_comment_count($id$user_info['user_id']);

insert below:
      $site_template->register_vars("comment_id_new"$commentid);

in case you "really" using ajax comments, you'll need insert at the same place in ajaxcomments.php this:
      $return['eval'] = "window.location.hash='#comment" $commentid "';";

in details.html template below {comments} tag insert this:
Code: [Select]
{if comment_id_new}
<script language="javascript">
window.location.hash = '#comment{comment_id_new}';
</script>
{endif comment_id_new}
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Re: Directing user to comment when comment is made (Request MOD)
« Reply #4 on: September 07, 2010, 03:49:59 PM »
@Vano

Thank u so much man  :) I owe you something like 1000 beers already  :mrgreen:

I did what you said but mmmmm i dont know it doesnt seem to work or maybe ive just misunderstand your instructions.

Inside details.php I found...
Code: [Select]
update_comment_count($id, $user_info['user_id']);
and inserted below that...
Code: [Select]
     $site_template->register_vars("comment_id_new", $commentid);
and in ajaxcomments.php i found...
Code: [Select]
     update_comment_count($id, $user_info['user_id']);
and inserted below that...
Code: [Select]
$return['eval'] = "window.location.hash='#comment" . $commentid . "';";


If the above way regarding the ajax comments is correct then ive done exactly what you have said sir, but it doesnt seem to work. Comments get saved but it does not ridirect me back to the top of the comments so that user can view there comments, infact it page refreshes and redirects me to the bottom of the page. (note** comments get saved ASC not DESC)

thanks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Directing user to comment when comment is made (Request MOD)
« Reply #5 on: September 07, 2010, 06:30:12 PM »
did you added code into details.html template?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Re: Directing user to comment when comment is made (Request MOD)
« Reply #6 on: September 07, 2010, 06:34:29 PM »
Yes sir i added the code also to details.html right under {comments}   :( :(

It doesnt work. It just push the page right to the bottom instead of ridirecting it to the top of where the comment is placed.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Directing user to comment when comment is made (Request MOD)
« Reply #7 on: September 07, 2010, 06:54:12 PM »
do you see #commentNN hash in the url?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Re: Directing user to comment when comment is made (Request MOD)
« Reply #8 on: September 07, 2010, 07:01:00 PM »
Quote
do you see #commentNN hash in the url?

^^ this is the url i have /details.php?image_id=31#comment41

So i think so, there is a hash inisde of it or maybe this isnt it, because i cannot see no NN

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Directing user to comment when comment is made (Request MOD)
« Reply #9 on: September 07, 2010, 08:09:09 PM »
that is correct. the browser scrolls down to an anchor with name="comment41"
That tag is supposed to be in comment_bit.html in default template it looks something like this (I don't have access to the 4images source to be exact):
Code: [Select]
<a name="comment{comment_id}"></a>if you don't have something like this, then you'll need add one. just look in the unmodified details.html template for the correct formated line.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Re: Directing user to comment when comment is made (Request MOD)
« Reply #10 on: September 07, 2010, 09:14:34 PM »
yes yes i remember this...

i found it
Code: [Select]
<a name="comment{comment_id}"></a>

and its at the top of the comment_bit.html, i already have this code. What should i do now sir, thank u so so much for your help


sorry did u mean find that code inside comment_bit.html and add this code inside of details.html??

inside of details.html i found something that looks similar it is this...
Code: [Select]
<a name="comments"></a>
« Last Edit: September 07, 2010, 09:42:46 PM by zakaria666 »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Directing user to comment when comment is made (Request MOD)
« Reply #11 on: September 08, 2010, 01:02:52 AM »
No, don't need to add anything else, the code I've posted and the fact that you have hash in the url after posting a comment is a sign of everything is correct, it should scroll down to the new comment.
Unless of course I didn't understand your request or you got confused with something (again (whis)) :lol:;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Re: Directing user to comment when comment is made (Request MOD)
« Reply #12 on: September 11, 2010, 02:05:42 AM »
I just viewed a topic where u had helped a member called benny http://www.4homepages.de/forum/index.php?topic=5830.msg150986#msg150986 and he asked u to help him make it so  that his comments are first so dont start from the bottom. I think this is where the confusion was. Ive kept on saying ASC and u was thinking i wasnt it at the bottom. So it was my fault.

Ive noticed that not even youtube has this functionality (which is a shock).

Excuse my aweful drawing presentation.

From the crap below drawing u can see i wrote inside of the top rectangle with words inside it, it is the new comment a user has posted. So just imagine that 100x in length. So the users will have to scroll down as u can see again and post a comment, then scroll all the way up and then down again and then up. So the code u have kindly given me just scrolls the page down fully and does not redirect the user back to the top of the new comment posted.




if this cannot be achieved just ignore this thread or just give me a smily face lol, i will just need to change a few things around inside of the comment seection.

take care man.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Directing user to comment when comment is made (Request MOD)
« Reply #13 on: September 11, 2010, 04:49:03 AM »
It turned out to be reCAPTCHA issue. It automatically focuses on it's input field when refreshed.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Re: Directing user to comment when comment is made (Request MOD)
« Reply #14 on: September 11, 2010, 01:17:53 PM »
 :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:

You are the man vano,

I have good news and i have bad news.

1) Good news is the code you sent me below to put inside of js/ajaxcomments.js works amazinglyyyyyy but only for internet explorar browser and firefox browser lol, so thts the bad news it doesnt seem to work in all major browsers. I tried it in chrome but it gets pushed to the bottom but i have never understood browsers. Why does it work in IE and firefox but not google chrome??

Thanks alot man,

Code: [Select]
/*
comment_bit.html

cr{comment_id}          = <div> for rating number
crd{comment_id}         = <div> for votes number
cimglg{comment_id}      = <a href=""> for image "good"
cimglb{comment_id}      = <a href=""> for image "bad"
cimgg{comment_id}       = <img> for image "good"
cimgb{comment_id}       = <img> for image "bad"
cih{comment_id}         = <img> for image "very bad" (plus.png/minus.png)
cilh{comment_id}        = <a href=""> for image "very bad" (plus.png/minus.png)
commentbox{comment_id}  = <div> for single comment
cmsg{comment_id}        = title="" for an element where a tooltip message will be used.
*/


var Page;
var PerPage;
var RecaptchaBackup = {};
function ajaxCommentsResponse(param, text)
{
  var rsp = ajaxTagsFilter(text, ['error', 'msg', 'comment', 'page', 'perpage', 'paging', 'pagingstats', 'type', 'clear', 'eval']); //accepted tags
  rsp['error'] = parseInt(rsp['error']);
  rsp['type'] = parseInt(rsp['type']);
  rsp['page'] = parseInt(rsp['page']);
  rsp['perpage'] = parseInt(rsp['perpage']);
  rsp['clear'] = parseInt(rsp['clear']);
  if (rsp['page'] !== '')
    Page = rsp['page'];
  if (rsp['perpage'] !== '')
    PerPage = rsp['perpage'];
  var commentformmsg = ajaxGetObject('commentformmsg');
  var commentstable = ajaxGetObject('commentstable');

  var paging = ajaxGetObject('paging');
  var paging2 = ajaxGetObject('paging2');
  var pagingtable = ajaxGetObject('pagingtable');
  var pagingtable2 = ajaxGetObject('pagingtable2');
  var pagingstats = ajaxGetObject('pagingstats');

  if (rsp['clear'])
  {
    if (typeof param[4].comment_headline != "undefined")
      param[4].comment_headline.value = "";
    if (typeof param[4].comment_text != "undefined")
      param[4].comment_text.value = "";
  }
  if (rsp['clear'] || rsp['error'])
  {
    if (ajaxGetObject('captcha_image'))
    {
      new_captcha_image(false);
    }
    if (ajaxGetObject("captcha_input"))
    {
      ajaxGetObject("captcha_input").value = "";
    }
    if (typeof(Recaptcha) != "undefined")
    {
      if (typeof(RecaptchaBackup.focus_response_field) == "undefined")
        RecaptchaBackup.focus_response_field = Recaptcha.focus_response_field;

      Recaptcha.focus_response_field = function(){};
      Recaptcha.reload();
    }
  }
  if (commentformmsg && rsp['msg'])
  {
    commentformmsg.innerHTML = rsp['msg']+"<br /><br />";
  }
  if (rsp['paging'])
  {
    if (rsp['paging'] != "null")
    {
      if (paging)
      {
        paging.innerHTML = rsp['paging'];
      }
      if (pagingtable)
      {
        pagingtable.style.display = "inline";
      }
      if (paging2)
      {
        paging2.innerHTML = rsp['paging'];
      }
      if (pagingtable2)
      {
        pagingtable2.style.display = "inline";
      }
    }
  }
  else
  {
    if (pagingtable)
    {
      pagingtable.style.display = "none";
    }
    if (pagingtable2)
    {
      pagingtable2.style.display = "none";
    }
  }
  if (pagingstats && rsp['pagingstats'])
  {
    pagingstats.innerHTML = rsp['pagingstats'];
  }
  if (commentstable && rsp['comment'])
  {
    var t = commentstable.innerHTML;
    var i = t.lastIndexOf("<!--COMMENTEND-->");
    var e = t.substr(i);
    if (rsp['type'])
    {
      i = t.indexOf("<!--COMMENTSTART-->");
      var s = t.substr(0,i+19);
    }
    else
    {
      i = t.lastIndexOf("<!--COMMENTSTART-->");
      var s = t.substr(0,i+19);
    }
    commentstable.innerHTML = s + rsp['comment'] + e;
    ajaxCommentBG = (ajaxCommentBG++ > 1) ? 1 : 2;
  }
  if (rsp['eval'])
  {
    eval(rsp['eval']);
  }
}
function ajaxCommentSubmit(obj, Url)
{
  var Query = ajaxGetFormQuery(obj,['page', Page]);
  var Url = ajaxCommentsUrl + (ajaxCommentsUrl.indexOf("?") != -1 ? '&' : '?') + "js&commentbg=" + ajaxCommentBG + "&" + Url.substring(Url.search("\\?")+1);
  return !ajaxSend([ajaxCommentsResponse,Url,"POST",Query,obj]);
}
//comment vote related:
function aCTog(cid)
{
  var ct = ajaxGetObject("commentbox"+cid);
  var obj = ajaxGetObject("cih"+cid);
 
  if (obj.src.search("plus.png") != -1)
  {
    obj.src = obj.src.replace("/plus.png", "/minus.png");
      ct.style.display="block";
  }
  else
  {
    obj.src = obj.src.replace("/minus.png", "/plus.png");
      ct.style.display="none";
  }
  return false;
}
function ajaxCommentVoteResponse(param, text)
{
  var obj = param[4];
  var cid = param[5];
  var rsp = ajaxTagsFilter(text, ['error', 'rating', 'votes', 'status', 'msg', 'eval']); //accepted tags
  rsp['rating'] = parseInt(rsp['rating']);
  rsp['votes'] = parseInt(rsp['votes']);
  rsp['error'] = parseInt(rsp['error']);
  rsp['status'] = parseInt(rsp['status']);

  var cr                = ajaxGetObject('cr'+cid); //rating number
  var crd               = ajaxGetObject('crd'+cid); //votes number
  var cimglg            = ajaxGetObject('cimglg'+cid); //link to "good"
  var cimglb            = ajaxGetObject('cimglb'+cid); //link to "bad"
  var cimgg             = ajaxGetObject('cimgg'+cid); //image "good"
  var cimgb             = ajaxGetObject('cimgb'+cid); //image "bad"
  var cih               = ajaxGetObject('cih'+cid); //image for hidden (very bad) comment
  var cilh              = ajaxGetObject('cilh'+cid); //link image for hidden (very bad) comment
  var commentbox        = ajaxGetObject('commentbox'+cid); //the comment text box
  var cmsg              = ajaxGetObject('cmsg'+cid); //vote message for on mouse over tooltip'

  var commentratingmsg  = ajaxGetObject('commentratingmsg'); //vote message box
  if (!rsp['error'])
  {
    if (cr) //rating number
    {
      cr.innerHTML = (rsp['rating'] > 0 ? "+" : "")+rsp['rating'];
      cr.className = "comment_rating"+(rsp['rating'] > 0 ? 1 : (rsp['rating'] < 0 ? 2 : 0));
    }
    if (crd) //votes number
    {
      crd.innerHTML = rsp['votes'];
    }
  }
  else
  {
    //error vote
  }
  if (rsp['status'])
  {
    if (cimglg) //link to "good"
    {
      cimglg.removeAttribute("href");
      cimglg.removeAttribute("onclick");
      cimglg.onclick = function(){};
    }
    if (cimglb) //link to "bad"
    {
      cimglb.removeAttribute("href");
      cimglb.removeAttribute("onclick");
      cimglb.onclick = function(){};
    }
    if (cimgg) //image "good"
    {
      cimgg.src=cimgg.src.replace("good.png", "good_off.png");
    }
    if (cimgb) //image "bad"
    {
      cimgb.src=cimgb.src.replace("bad.png", "bad_off.png");
    }

    if (cih) //image for hidden (very bad) comment
    {

      if (rsp['rating'] <= ajaxCommentRatingHide) //hide message
      {
        if (cilh)
        {
          cilh.style.display="inline";
        }
        if (commentbox) //the comment text
        {
          if (cih.src.search("plus.png") != -1)
          {
            commentbox.style.display="none";
          }
        }
      }
      else
      {
        if (cilh)
        {
          cilh.style.display="none";
        }
        if (commentbox) //the comment text
        {
          if (commentbox.style.display == "none")
          {
            commentbox.style.display="block";
          }
        }
      }
    }
  }
  if (commentratingmsg && rsp['msg'])
  {
    commentratingmsg.innerHTML = rsp['msg'];
  }
  if (cmsg && rsp['msg'])
  {
    cmsg.title = rsp['msg'].replace(/(<br(\s+\/)?>|\r\n|\n)/ig, " ").replace(/<\/?[^>]+(>|$)/g, "");
  }
  if (rsp['eval'])
  {
    eval(rsp['eval']);
  }
}
function aCVote(obj,cid,r)
{
  var Url = ajaxCommentsUrl + (ajaxCommentsUrl.indexOf("?") != -1 ? '&' : '?') + 'js&action=ratingset&' + URL_ID + '=' + cid + '&mode=' + r;
 return !ajaxSend([ajaxCommentVoteResponse,Url,"GET",null,obj,cid,r]);
}




function CommentsPage(obj)
{
  var href = obj.getAttribute("href");
  var Query = href.substr(href.indexOf("?")+1);
  var Url = ajaxCommentsUrl + (ajaxCommentsUrl.indexOf("?") != -1 ? '&' : '?') + 'js&action=commentget&' + Query;
  return !ajaxSend([ajaxCommentsResponse, Url, "GET", null, obj]);
}

function CommentsPerPage(obj)
{
  var Query = ajaxGetFormQuery(obj);
//  var Query = ajaxGetFormQuery(obj,['page', Page]); // use this line if you want stay on the same page number
  var Url = ajaxCommentsUrl + (ajaxCommentsUrl.indexOf("?") != -1 ? '&' : '?') + 'js&action=commentget&' + (obj.getAttribute('action').indexOf("?") != -1 ? obj.getAttribute('action').substring(obj.getAttribute('action').search("\\?")+1) : '');
  return !ajaxSend([ajaxCommentsResponse, Url, "POST", Query, obj]);
}