ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Making Comments on Private Entries not Visible

July 19, 2009 6:25pm

Subscribe [2]
  • #1 / Jul 19, 2009 6:25pm

    Nevermore

    14 posts

    I have a section of code that makes it so anyone not in a set user group cannot see some posts.  I want to make sure that the comments on that post are not visible to the general viewing public either.  I think I just need help with the rearranging the code.

    
    									
  • #2 / Jul 20, 2009 2:57pm

    DRUMZ

    75 posts

    Hi!

    If I’m reading it right, couldn’t you just run this check again before displaying the comments?

    {if ((member_group == "1" OR member_group == "8"))....

    It seems that’s where you check to see if the currently logged in member is in the group allowed to view the posts. I’m assuming those same groups can view the private comments. If so, that same chack again before displaying the comments should work I’d imagine.

    Hope it works…

  • #3 / Jul 20, 2009 3:29pm

    Nevermore

    14 posts

    Hrmm.  I see what you mean.  Let me go see if I break the blog.  :D

  • #4 / Jul 20, 2009 3:36pm

    DRUMZ

    75 posts

    Heh, here’s hopin 😊

  • #5 / Jul 20, 2009 3:39pm

    Nevermore

    14 posts

    Well.  That worked.  But - in the process…
    I broke it.  >_<

    The sidebar is now in the main body of the blog.  CRAP.  >_<

    http://www.quothstheraven.com/index.php/blog/post/um_so/

    Edit:  Okay.  I fixed THAT, but now even *I* can’t see the comments.  Erk.

    
    
    

    Okay.  That’s the change I made.  What’d I screw up?  )=

  • #6 / Jul 20, 2009 3:56pm

    Nevermore

    14 posts

    It seems to think the comments are on a private post and we shouldn’t be reading them.  I’m wondering if the code just doesn’t work with comments.  I had it working before, but it was messy, in that I had the code for the entries and comments in there TWICE.  Once for normalness and once for the private posts….

  • #7 / Jul 20, 2009 4:10pm

    DRUMZ

    75 posts

    First, like the look of the site. 😊

    Second, from what I can see, I believe it’s the “status=“private” check. That value has nothing to reference now that you’re outside of the {exp:weblog:entries} tag.

    what I would suggest, is setting a php variable to “Y” is the entry if private, and the user is in the correct member group. Like so:

    {exp:weblog:entries weblog="{my_weblog}" status="open|Private" orderby="date" sort="desc" limit="1"}
    <?php
    if (("{status}" == "private") && (("{member_group}" == "1") OR ("{member_group}" == "8"))){
    $showcomments = "Y";
    }
    ?>
    ...(rest of entry display code here)

    Then, when it comes to displaying the comments, you simply check for that variable, and if it’s “Y”, you know the person logged in is able to view comments on private entries.

    Like:

    <?php
    if ($showcomments == "Y"){
    ?>
    <div id="comments">
    ...rest of comment display code
    <?php
    }
    else{
    ?>
    
    You cannot view comments on private entries(or whatever you want to say)
    
    <?php
    }
    ?>

    Should work.

  • #8 / Jul 20, 2009 4:13pm

    Nevermore

    14 posts

    How will that affect the non-private stuff?  Will it still show like normal?

  • #9 / Jul 20, 2009 4:18pm

    Nevermore

    14 posts

    Oh.  I see.  Nevermind.  I’m slow.  Sorry.  :😊:

    Okay.  The comments are back, but the ‘you cannot see these comments’ are now showing for everything.  Hrmmm.

    Maybe I’ll just leave that section blank.  Since no one needs to see that anyway.  Why be told twice you can’t see something? XD

    Edit: Damn.  They are back.  NAUGHTY comments.  Let me see if I screwed something up….

    Edit part 2:  Well, I’m at a loss.  :/  I feel dumb.  >_< 
    This is partly why I was trying not to mess with it.  :x

  • #10 / Jul 20, 2009 5:30pm

    DRUMZ

    75 posts

    LOL. So are the comments showing for private messages to anyone? People in those groups or not? May be a php parsing stage thing. I can never tell when something needs to be on input or output. I just click the other if it doesn’t work.

  • #11 / Jul 20, 2009 5:33pm

    Nevermore

    14 posts

    Eh?  Input versus output?  You lost me.
    And - yes.  The comments are showing for everyone at the moment.  It’s like the extra code is being ignored.

  • #12 / Jul 20, 2009 5:35pm

    DRUMZ

    75 posts

    If you go to the template preferences, that’s where you set which templates are allowed to have php code used on them. And there is an option there to have the php parse on input or output. That may be why the php is not running. Php needs to be enabled in order for functions and such to work.

  • #13 / Jul 20, 2009 5:55pm

    Nevermore

    14 posts

    I enabled PHP on that particular template.  I got this error.

    Notice: Undefined variable: showcomments in /home/evanesc/public_html/phoenix/core/core.functions.php(637) : eval()‘d code on line 56

    I did try both ‘input’ and ‘output’.  Hrmmmmm.  I guess I need to define “showcomments” somewhere?

    (PS - I appreciate your help!  <3)

  • #14 / Jul 20, 2009 6:23pm

    DRUMZ

    75 posts

    Ahh. For some reason, $showcomments isn’t being set to “Y” up above, it may not like the particular syntax. I also didn’t have you set it to “N” if the person can’t see the comments. Let’s start there and at least see if the error goes away.

    Up where you set $showcomments to “Y”, make the code say this:

    {exp:weblog:entries weblog="{my_weblog}" status="open|Private" orderby="date" sort="desc" limit="1"}
    <?php
    if (("{status}" == "private") && (("{member_group}" == "1") OR ("{member_group}" == "8"))){
    $showcomments = "Y";
    }
    else{
    $showcomments = "N";
    }
    ?>
    ...(rest of entry display code here)

    That should ad least make the variable have something in it when it gets checked later on. If the error goes away, and the comments are still visible to all, then it’s in the syntax of the if statement and we’ll go from there.

    Also, are members of group 1 or 8 the only ones allowed to see comments of private posts? If so, the code doesn’t even need to check to see if the message is private when setting $showcomments to “Y”. It just needs to check for the member groups.

    If that’s the case, then make it this:

    {exp:weblog:entries weblog="{my_weblog}" status="open|Private" orderby="date" sort="desc" limit="1"}
    <?php
    if ("{member_group}" == "1" OR "{member_group}" == "8"){
    $showcomments = "Y";
    }
    else{
    $showcomments = "N";
    }
    ?>
    ...(rest of entry display code here)

     

    And glad to help 😊

  • #15 / Jul 20, 2009 6:30pm

    DRUMZ

    75 posts

    Also, I’d suggest editing your post up there that has your full directory path. Don’t necessarily want that out in the open.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases