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

Custom Message for Users

I have a database of secret code words for each user on my forum. I would like to be able to display each user's code word at the top of the forum when they log in. How can I do this? By the way, I am using the Bootstrap theme.

I know how to connect to the database with PHP and MySQL. I'm mostly asking where can I put the PHP so it displays the code words?

Comments

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    You would create a module,or add it via jquery but module is the best way to go.

    Please look at plugins that add content to the pages, forumdonate is a basic plugin to show you how to add content to areas of the form.

    a module acts like a widget if you will.

    You can also use pockets plugin or the messages system .

  • Options

    @vrijvlinder said:
    You would create a module,or add it via jquery but module is the best way to go.

    Please look at plugins that add content to the pages, forumdonate is a basic plugin to show you how to add content to areas of the form.

    a module acts like a widget if you will.

    You can also use pockets plugin or the messages system .

    I think I'm just gonna use the custom pages plugin (mostly because I have no idea what I just looked at XD). Do you know how I can retrieve who is currently logged in? For example, if username "Bob" was logged in and viewing the custom page, I would need to display Bob's code word.

  • Options

    Never mind I figured it out:

    $Session = Gdn::Session();
    if ($Session->IsValid()) {
      $userid = $Session->UserID;
      $Name = $Session->User->Name;
      echo $Name;
    }
    
  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    yea you can also look at online now or who's online plugins .

    I would think that to give each a code word would be the same as making a special role for each and use role badges or role signatures , or role title .

    Also profile extender adds custom fields and you can modify anything to suit your needs...

    maybe what you need is a nickname plugin ...

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    You should create a plugin or a themehook. The only other solution would be changing the theme you are using or changing core files and you should avoid that. Download and activate that plugin: http://vanillaforums.org/addon/eventi-plugin. It will help you find out the “places” that you can position your custom output at.

    In order to let it appear there, you’ll need to hook an event. I don’t think that the below shows the code word the way you intended to, but it could give you a start (code is not tested):

    public function EntryController_AfterSignIn_Handler($Sender) {
       $Session = Gdn::Session();
       $User = Gdn::Session()->User;
       $UserName =  $User->Name;
    
       $Database = Gdn::Database();
       $Sql = $Database->SQL();
    
       $QueryString = "SELECT SecretKeyWord FROM YourTable WHERE UserName = '{$UserName}'";
       $Result = $Sql->Query($QueryString) ->FirstRow();
    
       $Sender->InformMessage(
          Sprite('Check', 'InformSprite').T('Your secret key word is '.$Result->SecretKeyWord),
          'Dismissable AutoDismiss HasSprite'
       );
    }
    

    And here’s a short note about what to do with that code: http://vanillaforums.org/docs/theme-hooks

    Important part is that you do not have to fiddle around with mysql code if your table is in the same db as vanilla.

Sign In or Register to comment.