Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

"New Discussion" button for guests?

hi, i'm running vanilla 2.0.18.10 . how do i display "New Discussion" button for guests? I'm using BrandFriendly Theme, not php based. i've research this for awhile, but found nothing. Thanks.

«1

Comments

  • edited April 2014

    Do you want guests to be able to post ? that is asking for spam
    you can simply add a link to the menu or the panel but they will not be able to post unless they have permissions.

    <a href="post/discussion" target="_blank">New Discussion</a>

  • no, i want them to click on the "new discussion" buton, then it will take them to the login or registration process.

  • Well then you can add the plain link. It will not allow to post and will send to the login

    I put my link in the index and the menu . It all depends where you want to put it.

  • just on top of the Categories

  • edited April 2014

    Ok , well I have a very easy way of doing it and a not so easy...

    the easy one involves creating a message in the dashboard and picking the panel as the place for it. You put the link like the one above. But can't guarantee where it will show up as far as the order of the modules goes.

    The not so easy involves adding jquery to prepend the categories module. Now because you want this for the guests is should not also show for logged in users.

    I suggest the jquery to prepend the guest module. That way when it goes away after login the link will go with it.

  • edited April 2014

    add this to your default.master.tpl to prepend the Guest Box

    {literal}<script type="text/javascript">
     $(document).ready(function() {
    
    $('div.Box.GuestBox').prepend('<a class="BigButton" href="post/discussion" target="_blank">New Discussion</a>');
    });
    </script>{/literal}
    
  • sinnersinner New
    edited April 2014

    i just tried the code you posted, it work, but it keeps printing the button down the list non stop

  • make sure you copy pasted it properly , give me a link to see...

  • peregrineperegrine MVP
    edited April 2014

    oh sinner man - where you gonna run to.

    http://www.youtube.com/watch?v=H6_BWNzThJY

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • The best way to do this would be to override the New Discussion module to disable the permission check.

    Create a basic plugin. Create a modules folder in your plugin's folder (/plugins/HelloWorld/modules if you followed that tutorial). The create a new file called class.newdiscussionmodule.php in that folder and paste the following code:

    <?php if (!defined('APPLICATION')) exit();
    
    /**
     * Garden.Modules
     */
    
    /**
     * Renders the "Start a New Discussion" button.
     */
    class NewDiscussionModule extends Gdn_Module {
    
       public function AssetTarget() {
          return 'Panel';
       }
    
       // Always show the button, regardless of permissions
       public function ToString() {
         return parent::ToString();
       }
    }
    

    Once your plugin is enabled, the new discussion module should now be autoloaded from your plugin's module folder. You can override any module like this.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • edited April 2014

    You can also eco the the plain link . The think here hg, I think he wants it to show for guests but to go away when logged in. He wants it where the Button actually goes in the panel.

    That is why I appended to the guest box. it works for me good. It goes away along with the guest box upon login.

    maybe you can add a check to make sure they are not logged in to show the button. i only done it to check for login so I expect I am wrong below...

     if($Session = Gdn::Session() && IsValid())
        return;
    }
      elseif(AssetTarget()== 'Panel' ){
    
    echo'link';
    }}
    
  • If you want to only show it to guests, just replace your module's ToString() method with this:

    public function ToString() {
       $CanCreateNewDiscussion = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
       if ($CanCreateNewDiscussion) {
          return '';
       }
       else {
         return parent::ToString();
       }
    }
    

    This will only show the new button to guests and hide it to users that can actually make a new discussion. Why you would want this behavior is beyond me, but different strokes for different folks.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Why you would want this behavior is beyond me, but different strokes for different folks.

    This sort of thing has inspired you to make some great plugins ;)

    It is refreshing when you have run out of ideas and someone comes in wanting something that never occurred to you. It is challenging no?

    The reason for wanting this behavior, is so the button does not appear twice in the same place. Basically he wants to use it as a teaser button that send them to log in.

    Once they log in the normal button shows up and the guest one does not.

  • @vrijvlinder said:
    Once they log in the normal button shows up and the guest one does not.

    Ah.. there is the sticking point. The first code I posted is a module that is loaded instead of the original new discussion module. There will never be more than one button shown because I simply replaced the original.

    The biggest difference is that this autoloading (once cached via the ini files) incurs no extra cost on the server side (actually less because I got rid of a function call and a conditional).

    Compare this to a method inserts this link via JS or a render hook, and you can see even more advantages. Inserting content via JS breaks the UX for users browsing with JS disabled. It may also cause bad SEO juju (if you care about that) since the crawler has to parse JS to see this content. Using a render hook is fine, but is essentially using a sledgehammer to insert finish nails. It works, but there are better tools for the job. Also, that sledgehammer is heavy. ;)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • edited April 2014

    Yes , the idea is that you add a button not that you change the way the original works.

    You don't want to remove the permissions from the button. He does not want it to go to post. By simply adding the link and extra one , the link retains it's permissions but will redirect to login if not logged in.

    Maybe the best approach would be to clone the guest module and hard code the link in there. That way it is replaced by the NewDiscussion module automatically.

    I understand the java issue, but if they have java disabled then most things that depend on or use it won't work anyway.

    Another option was to add the link in a message box in the dashboard. One could use css to hide the original or add a config to not show the newdiscussion module. In essence you get rid of the one and use another in it's place which shows all the time.

  • edited April 2014

    This is what mine looks like using my method, also tried the others...

    Pretty much there is 5 ways of doing this or maybe more. One can also add that link to the default.master.tpl in the panel div and hide the original ...

    ndb.png 58.2K
  • Removing the permissions check on the module doesn't remove the permission requirements on the controller it is linked to.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • edited April 2014

    @‌hgtonight Ok here I made a plugin using your specs, it renders the button twice however...

    Neat trick tho...

  • Ok I have figured out why it was rendering twice... I removed a line that calls for a new module, I think that we only need to add module not new module because that is an existing module.

Sign In or Register to comment.