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.
Options

New button between New Discussion and the pagination.

First off, is this a theme modification or a plugin? I'm wanting the "Sign In" button there when guests are browsing the page. Yes, I realize that this button already exists in the right/left (depends on theme) hand column but this is not enough for my client. What would be required to put this button there?

«1

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @mickeybond said:
    First off, is this a theme modification or a plugin?

    That's a tough question! Without much thinking about it, I guess the only real difference between a plugin and a theme (from developer perspective) is that a theme can do view overrides...

    Whenever you make a small visual hack that you think might be useful for someone else, I would recommend to make it a plugin.

    If you have a collection of visual changes, make it a theme.

    What you want to achieve is a simple thing. Vanilla fires events and everytime such an event is fired, you can take action. Events are fired e.g. when database queries are prepared, when the results of such a query is processed, when information is written to the screen etc.
    There is a great helper plugin: eventi. If you download and enable it, you will get a visual hint where you are able to add content. I would recommend you get that plugin and see if you get a little understanding of how it could help. If not, just post a screenshot where you would like to see such a button.

  • Options

    something like this

  • Options
    edited August 2017

    I just installed the Eventi plugin but it won't enable. i'll keep wrestling with it.

  • Options

    It looks like that plugin might be broken for the time being.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    It's a theme thing if all you want to do is add an existing link. Just add the sign in button into your default.master.tpl or if it's a php based master the default.master.php templates.. or to the themehooks

  • Options

    Awesome, I got it added but now it shows even when i'm logged in, any suggestions?

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    This is the php signout link which replaces the sign in one when the user signs in

    $this->Menu->AddLink('SignOut', T('Sign Out'), $Authenticator->SignOutUrl(), FALSE, array('class' => 'NonTab SignOut'));

    This is the sign in link

    $this->Menu->AddLink('Entry', T('Sign In'), $Authenticator->SignInUrl($this->SelfUrl), FALSE, array('class' => 'NonTab'), $Attribs);

    Notice that it checks for authenticating the session and that is how it knows what link to show. When it's a guest it shows as sign in and when user is logged in the link becomes log out.

    You must replicate this action. If you are using a php based theme it can be done in the master, if not you need to add it to the themehooks which act as a theme plugin..it's in php.

    It may be possible that simply adding the class to the link will work but it's a theory.

    <a href="yoursite.com/forum/entry/signin" class="NonTab SignIn" >

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    I'm surprised you managed to put it at that place with inserting it in the default.master.tpl but anyway, the Smarty code you would need is this:

    {if !$User.SignedIn}
          your button here
    {/if}
    
  • Options
    R_JR_J Ex-Fanboy Munich Admin

    By the way, that's the code I would use:

        public function discussionsController_pageControls_handler($sender) {
            if (Gdn::session()->UserID > 0) {
                return;
            }
            echo anchor(
                t('Sign In'),
                signInUrl($sender->SelfUrl),
                'Button Primary'.(signInPopup() ? ' SignInPopup' : ''),
                ['rel' => 'nofollow']
            );
        }
    

    It makes no difference if that is used in a themehooks file or in a plugin.

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    I have to note that I recall several new users complaining about not noticing the standard signin/signout link. While I may have personal opinion on their lack of attention I recognize that this may reflect on usability and I am all for improvement in usability.

    The dilemma I have is that once the users cease to be novice the button is too intrusive...

    I do like @R_J 's plug-in approach which can be further enhanced to allow admin customization or more dynamic approach.

  • Options

    @R_J said:
    I'm surprised you managed to put it at that place with inserting it in the default.master.tpl but anyway, the Smarty code you would need is this:

    {if !$User.SignedIn}
          your button here
    {/if}
    

    I wasn't able to, I ended up putting it in a copy of the discussions/index.php file copied into the theme directory. The image I provided was simply a mockup attempting to show where I wanted to put it. Sorry for the confusion.

  • Options

    @vrijvlinder said:
    This is the php signout link which replaces the sign in one when the user signs in

    $this->Menu->AddLink('SignOut', T('Sign Out'), $Authenticator->SignOutUrl(), FALSE, array('class' => 'NonTab SignOut'));

    This is the sign in link

    $this->Menu->AddLink('Entry', T('Sign In'), $Authenticator->SignInUrl($this->SelfUrl), FALSE, array('class' => 'NonTab'), $Attribs);

    Notice that it checks for authenticating the session and that is how it knows what link to show. When it's a guest it shows as sign in and when user is logged in the link becomes log out.

    You must replicate this action. If you are using a php based theme it can be done in the master, if not you need to add it to the themehooks which act as a theme plugin..it's in php.

    It may be possible that simply adding the class to the link will work but it's a theory.

    <a href="yoursite.com/forum/entry/signin" class="NonTab SignIn" >

    Neither of these seemed to work, adding the class to the link/button had no effect and the other code generated the following error in nginx:

    2017/08/18 08:05:38 [error] 13049#0: *86955 FastCGI sent in stderr: "PHP message: PHP Fatal error: Call to a member function SignInUrl() on a non-object in /home/carolyn/vanilla/themes/bootstrap/views/discussions/index.php on line 28" while reading response header from upstream, client: 192.168.100.114, server: carolyn.vanilla.test.psg, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.socket:", host: "carolyn.vanilla.test.psg", referrer: "https://carolyn.vanilla.test.psg/"

    line 28 being the sample code you provided. Thanks for the suggestion, I feel like I understand a little better about authentication checks.

  • Options

    @R_J said:
    By the way, that's the code I would use:

        public function discussionsController_pageControls_handler($sender) {
            if (Gdn::session()->UserID > 0) {
                return;
            }
            echo anchor(
                t('Sign In'),
                signInUrl($sender->SelfUrl),
                'Button Primary'.(signInPopup() ? ' SignInPopup' : ''),
                ['rel' => 'nofollow']
            );
        }
    

    It makes no difference if that is used in a themehooks file or in a plugin.

    I'm not sure where the themehooks file is to insert this into.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @rbrahmson said:
    The dilemma I have is that once the users cease to be novice the button is too intrusive...

    Most of the forum users who visit a forum so often that the get used to the look, browse it as logged in users and not as guests and so they wouldn't see that button anyway.

    @mickeybond said:
    I'm not sure where the themehooks file is to insert this into.

    Creating your own theme is really easy.
    1. Copy the "mobile" theme folder and give that copy a nice name, maybe "PlumS" :mrgreen:
    2. Only keep the about.php and the class.mobilethemehooks.php
    3. Inspect the about.php, compare it to other about.php files of other themes and make the required changes
    4. Rename the class.mobilethemehooks.php to class.plumsthemehooks.php
    5. Through away everything in the themehooks file except for:

    <?php
    /**
     * Mobile Theme hooks.
     *
     * @copyright 2009-2016 Vanilla Forums Inc.
     * @license http://www.opensource.org/licenses/gpl-2.0.php GNU GPL v2
     * @package Mobile Theme
     * @since 2.0
     */
    
    /**
     * Customizations for the mobile theme.
     */
    class MobileThemeHooks implements Gdn_IPlugin {
    
        /**
         * No setup required.
         */
        public function setup() {
        }
    
    }
    
    

    Now even remove or change those comments, change the class name to PlumSThemeHooks and insert my code from above right before the closing "}"

    Basically that's it. Maybe you have to delete the *.ini files in your cache before you can see the new theme

  • Options
    R_JR_J Ex-Fanboy Munich Admin
  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Personally I prefer learning by studying what someone else has done. You can download some themes and look at what you find there. You will see that there are some contradictions. When in doubt, do as the documentation says or ask.

  • Options

    Do I copy the mobile directory to inside of my bootstrap directory or simply create a copy at the same level?

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    You might not have seen my last post :wink:

    The copy has to be on the same level /themes/PlumS

  • Options
    edited August 2017

    AWESOME! That works perfectly. Thank you so much for your help. So if I had to guess how to turn the sign in button into a sign out button once they were signed in would it be something along the lines of:

    public function discussionsController_pageControls_handler($sender) {
             if (Gdn::session()->UserID > 0) {
                  echo anchor(
                  t('Sign Out'),
                  signOutUrl($sender->SelfUrl),
                  'Button Primary'.(SignOutWrap ? ' link-signout' : ''),
                  ['rel' => 'nofollow']
              );
              }
                  echo anchor(
                  t('Sign In'),
                  signInUrl($sender->SelfUrl),
                  'Button Primary'.(signInPopup() ? ' SignInPopup' : ''),
                  ['rel' => 'nofollow']
              );
          }
    
  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Theoretically yes, but Vanilla has a handy shortcut for that: https://github.com/vanilla/vanilla/blob/release/2.3/library/vendors/SmartyPlugins/function.signinout_link.php

    Replace everything in the public function discussionsController_pageControls_handler($sender) { with this:

    echo Gdn_Theme::link(
        'signinout',
        '',
        '<a href="%url" rel="nofollow" class="%class">%text</a>',
        ['Target' => $sender->SelfUrl]
    );
    
Sign In or Register to comment.