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.

how to Display UserPhoto in "Menu bar"

how to Display UserPhoto in "Menu bar"

Comments

  • You can add the user photo via your master template using the Smarty tag {photo_link}. You can also use the UserPhoto() function and pass in the session user object.

    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.

  • Here is what I did for my own forum. My theme is php based. That means it has a default.master.php file. I included everything from the Authenticator so you can see where I put the code. I also replaced the inbox with an image. In order for this to work, you must also replace/remove the original link of the user from the menu.

    $Authenticator = Gdn::Authenticator();
                            if ($Session->IsValid()) {
    
                                $CountNotifications = $Session->User->CountNotifications;
                                if (is_numeric($CountNotifications) && $CountNotifications > 0)
                                    $photo .= ' <span>'.$CountNotifications.'</span>';
                                $photo = UserPhoto(Gdn::Session()->User);
    
    $this->Menu->AddLink('User',  $photo,  '/profile/{UserID}/{Username}',array('Garden.SignIn.Allow'), array('class' => 'UserNotifications'));
     $this->Menu->AddLink('User',Img('/themes/VrijVlinder/design/images/inbox.png', array('title' => T('Inbox'),array('class' => 'Inbox'))), 'messages/all',array('Garden.SignIn.Allow'),array('class' => 'UserInbox'));
    $this->Menu->RemoveLink('Conversations',T('Inbox'), '/messages/all', array('class' => 'Inbox'));
    
    $this->Menu->AddLink('SignOut', Img('/themes/VrijVlinder/design/images/off.png', array('title' => T('Sign Out'))),  $Authenticator->SignOutUrl(), FALSE, array('class' => 'NonTab SignOut'));
                            } else {
                                $Attribs = array();
                                if (C('Garden.SignIn.Popup') && strpos(Gdn::Request()->Url(), 'entry') === FALSE)
                                    $Attribs['class'] = 'SignInPopup';
    
                                $this->Menu->AddLink('Entry', Img('/themes/VrijVlinder/design/images/on.png', array('title' => T('Sign In'))), $Authenticator->SignInUrl($this->SelfUrl), FALSE, array('class' => 'NonTab'), $Attribs);
                            }
                            echo $this->Menu->ToString();
    
  • Here is a screen shot of my menu where I replaced all the links with images including the user and the inbox with the code above.

    menu.png 815.1K
  • frindmanfrindman New
    edited March 2014
    <?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-ca">
      <head>
        <?php $this->RenderAsset('Head'); ?>
      </head>
      <body id="<?php echo $BodyIdentifier; ?>" class="<?php echo $this->CssClass; ?>">
        <div id="Frame">
          <div id="Head">
            <div class="Menu">
              <h1><a class="Title" href="<?php echo Url('/'); ?>"><span><?php echo Gdn_Theme::Logo(); ?></span></a></h1>
              <?php
              $Session = Gdn::Session();
              if($this->Menu) {
                $this->Menu->AddLink('Dashboard', T('Dashboard'), '/dashboard/settings', array('Garden.Settings.Manage'));
    
                $Authenticator = Gdn::Authenticator();
                if($Session->IsValid()) {
                  $CountNotifications = $Session->User->CountNotifications;
                  if(is_numeric($CountNotifications) && $CountNotifications > 0)
                    $photo .= ' <span>' . $CountNotifications . '</span>';
                  $photo = UserPhoto(Gdn::Session()->User);
                  $this->Menu->AddLink('User', $photo, '/profile/{UserID}/{Username}', array('Garden.SignIn.Allow'), array('class' => 'UserNotifications'));
                  $this->Menu->AddLink('User', Img('/themes/VrijVlinder/design/images/inbox.png', array('title' => T('Inbox'), array('class' => 'Inbox'))), 'messages/all', array('Garden.SignIn.Allow'), array('class' => 'UserInbox'));
                  $this->Menu->AddLink('SignOut', Img('/themes/VrijVlinder/design/images/off.png', array('title' => T('Sign Out'))), $Authenticator->SignOutUrl(), FALSE, array('class' => 'NonTab SignOut'));
                }
                else {
                  $Attribs = array();
                  if(C('Garden.SignIn.Popup') && strpos(Gdn :: Request()->Url(), 'entry') === FALSE)
                    $this->Menu->AddLink('Entry', Img('/themes/VrijVlinder/design/images/on.png', array('title' => T('Sign In'))), $Authenticator->SignInUrl($this->SelfUrl), FALSE, array('class' => 'NonTab'), $Attribs);
                }
                echo $this->Menu->ToString();
                // $this->Menu->AddLink('Dashboard', T('Users'), '/user/browse', array('Garden.Users.Add', 'Garden.Users.Edit', 'Garden.Users.Delete'));
                $this->Menu->AddLink('Activity', T('Activity'), '/activity');
                if($Session->IsValid()) {
                  $Name = $Session->User->Name;
                  $CountNotifications = $Session->User->CountNotifications;
                  if(is_numeric($CountNotifications) && $CountNotifications > 0)
                    $Name .= ' <span class="Alert">' . $CountNotifications . '</span>';
    
                  if(urlencode($Session->User->Name) == $Session->User->Name)
                    $ProfileSlug = $Session->User->Name;
                  else
                    $ProfileSlug = $Session->UserID . '/' . urlencode($Session->User->Name);
                  $this->Menu->AddLink('User', $Name, '/profile/' . $ProfileSlug, array('Garden.SignIn.Allow'), array('class' => 'UserNotifications'));
                  $this->Menu->AddLink('SignOut', T('Sign Out'), SignOutUrl(), FALSE, array('class' => 'NonTab SignOut'));
                } else {
                  $Attribs = array();
                  if(SignInPopup() && strpos(Gdn::Request()->Url(), 'entry') === FALSE)
                    $Attribs['class'] = 'SignInPopup';
    
                  $this->Menu->AddLink('Entry', T('Sign In'), SignInUrl(Url('')), FALSE, array('class' => 'NonTab'), $Attribs);
                }
                echo $this->Menu->ToString();
              }
              ?>
              <div class="Search"><?php
              $Form = Gdn::Factory('Form');
              $Form->InputPrefix = '';
              echo
              $Form->Open(array('action' => Url('/search'), 'method' => 'get')),
              $Form->TextBox('Search'),
              $Form->Button('Go', array('Name' => '')),
              $Form->Close();
              ?></div>
            </div>
          </div>
          <div id="Body">
            <div id="Content"><?php $this->RenderAsset('Content'); ?></div>
            <div id="Panel"><?php $this->RenderAsset('Panel'); ?></div>
          </div>
          <div id="Foot">
            <?php
            $this->RenderAsset('Foot');
            echo Wrap(Anchor(T('Powered by Vanilla'), C('Garden.VanillaUrl')), 'div');
            ?>
          </div>
        </div>
        <?php $this->FireEvent('AfterBody'); ?>
      </body>
    </html>
    

    Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/a6953647/public_html/applications/dashboard/views/default.master.php on line 27

  • @frindman‌ I believe I accidentally corrected your syntax error when I reformatted your post. I added a ; at the end of line 25 in the above post.

    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.

  • Yea, remember that the urls for those images go to my site you need to either make your own images and add the link there or remove the other links with images.

    Don't just copy the whole code over.** Try to understand what you are copying **.

    All you need from my code is the user link. I only gave you all that other code so you can see where that link goes.

Sign In or Register to comment.