Moving greeting/user info

Started by Cesarre, November 08, 2016, 07:34:46 PM

Previous topic - Next topic

Cesarre

I recently installed the Sunset 2.0  theme and so far I'm really digging it. However there is one aspect that I'm not happy with, which is the fact that the user info is smack dab right on the banner. My knowledge is limited, but what I'd like to do is set up the user/greeting info in a way similar to how Crip did it with the BlackRainV3 theme by throwing it in a collapsible section of the forum index (pic related, the first one) and sticking it under the menu strip. I find it to be really unintrusive, plus i think it just looks better from an aesthetic standpoint.

I just spent a good hour or so trying to track down the code for the header section, but I finally found it in index.template.php

Now I'm wondering what to do from here, where I oughta stick this puppy to get what I want.

the bit from Sunset 2.0

function template_body_above()
{
   global $context, $settings, $options, $scripturl, $txt, $modSettings;

   // The logo, user information, news, and menu.
   echo '
   <table cellspacing="0" cellpadding="1" border="0" align="center" width="950" class="top">
      <tr>
            <td valign="middle" height="261" align="left">';

   if (empty($settings['header_logo_url']))
      echo '
               <h1>', $context['page_title'] != "$context[forum_name] - Index" ? "$context[forum_name] - " : '', $context['page_title'], '</h1>';
   else
      echo '
               <img src="', $settings['header_logo_url'], '" style="margin: 4px;" alt="', $context['page_title'] != "$context[forum_name] - Index" ? "$context[forum_name] - " : '', $context['page_title'], '" />';

   echo '
            </td>
         <td valign="middle" align="right"><p>';

   // If the user is logged in, display stuff like their name, new messages, etc.
   if ($context['user']['is_logged'])
   {
      echo '
            ', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>', $context['allow_pm'] ? ', ' . $txt['msg_alert_you_have'] . ' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' . ($context['user']['messages'] != 1 ? $txt['msg_alert_messages'] : $txt['message_lowercase']) . '</a>' . $txt['newmessages4'] . ' ' . $context['user']['unread_messages'] . ' ' . ($context['user']['unread_messages'] == 1 ? $txt['newmessages0'] : $txt['newmessages1']) : '', '<br /><a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
                        <a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a>';

      // Are there any members waiting for approval?
      if (!empty($context['unapproved_members']))
         echo '<br />
            ', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=admin;area=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'];
      // Is the forum in maintenance mode?
      if ($context['in_maintenance'] && $context['user']['is_admin'])
         echo '<br />
            <b>', $txt['maintain_mode_on'], '</b>';

      if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
         echo '<br />
            <a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a>';
   }
   // Otherwise they're a guest - so politely ask them to register or login.
   else
      echo '
            ', sprintf($txt['welcome_guest'], $txt['guest_title']);


   echo '
            <br />', $context['current_time'], '
         </p></td>
      </tr>
      <tr class="windowbg2">
         <td colspan="2" valign="middle" align="center" class="tborder" style="border-width: 1px 0 0 0; font-size: smaller;">';

   // Show the menu here, according to the menu sub template.
   template_menu();

   echo '
         </td>
      </tr>';


And here's the bit from Crip's theme.

function template_body_above()
{
   global $context, $settings, $options, $scripturl, $txt, $modSettings;

   echo '
<div class="content_wrap" id="mainframe"', !empty($settings['forum_width']) ? ' style="width: ' . $settings['forum_width'] . '"' : '', '>
   <div id="ob1">
       <div id="ib1">
         <table width="100%" cellpadding="0" cellspacing="0" border="0" id="content" class="content_wrap">
         <tr>
          <td align="center"><a href="'.$scripturl.'" title="', $context['forum_name'], '"><img src="', $settings['images_url'], '/logo.png" style="margin: 2px; width: 100%" alt="', $context['forum_name'], '" /></a>
      </td>
   </tr>
</table>
   <div class="tborder">
    <div class="content">
      <div class="catbg">
         
         </h1>
      </div>';

   // Display user name and time.
   echo '
      <ul id="greeting_section" class="reset titlebg2">
         <li id="time" class="smalltext floatright">
            ', $context['current_time'], '
            <img id="upshrink" src="', $settings['images_url'], '/upshrink.gif" alt="*" title="', $txt['upshrink_description'], '" align="bottom" style="display: none;" />
         </li>';

   if ($context['user']['is_logged'])
      echo '
         <li id="name">', $txt['hello_member_ndt'], ' <em>', $context['user']['name'], '</em></li>';
   else
      echo '
         <li id="name">', $txt['hello_guest'], ' <em>', $txt['guest'], '</em></li>';

   echo '
      </ul>';

   if ($context['user']['is_logged'] || !empty($context['show_login_bar']))
      echo '
      <div id="user_section" class="bordercolor"', empty($options['collapse_header']) ? '' : ' style="display: none;"', '>
         <div class="windowbg2 clearfix">';

   if (!empty($context['user']['avatar']))
      echo '
            <div id="myavatar">', $context['user']['avatar']['image'], '</div>';

   // If the user is logged in, display stuff like their name, new messages, etc.
   if ($context['user']['is_logged'])
   {
      echo '
            <ul class="reset">
               <li><a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a></li>
               <li><a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a></li>';

      // Is the forum in maintenance mode?
      if ($context['in_maintenance'] && $context['user']['is_admin'])
         echo '
               <li class="notice">', $txt['maintain_mode_on'], '</li>';

      // Are there any members waiting for approval?
      if (!empty($context['unapproved_members']))
         echo '
               <li>', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=admin;area=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'], '</li>';

      // Show the total time logged in?
      if (!empty($context['user']['total_time_logged_in']))
      {
         echo '
               <li>', $txt['totalTimeLogged1'];

         // If days is just zero, don't bother to show it.
         if ($context['user']['total_time_logged_in']['days'] > 0)
            echo $context['user']['total_time_logged_in']['days'] . $txt['totalTimeLogged2'];

         // Same with hours - only show it if it's above zero.
         if ($context['user']['total_time_logged_in']['hours'] > 0)
            echo $context['user']['total_time_logged_in']['hours'] . $txt['totalTimeLogged3'];

         // But, let's always show minutes - Time wasted here: 0 minutes ;).
         echo $context['user']['total_time_logged_in']['minutes'], $txt['totalTimeLogged4'], '
               </li>';
      }

      if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
         echo '
               <li><a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a></li>';
      echo '
            </ul>';
   }
   // Otherwise they're a guest - this time ask them to either register or login - lazy bums...
   elseif (!empty($context['show_login_bar']))
   {
      echo '
            <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
            <form class="windowbg" id="guest_form" action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '" ', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
               ', $txt['login_or_register'], '<br />
               <input type="text" name="user" size="10" class="input_text" />
               <input type="password" name="passwrd" size="10" class="input_password" />
               <select name="cookielength">
                  <option value="60">', $txt['one_hour'], '</option>
                  <option value="1440">', $txt['one_day'], '</option>
                  <option value="10080">', $txt['one_week'], '</option>
                  <option value="43200">', $txt['one_month'], '</option>
                  <option value="-1" selected="selected">', $txt['forever'], '</option>
               </select>
               <input type="submit" value="', $txt['login'], '" class="button_submit" /><br />
               ', $txt['quick_login_dec'];

      if (!empty($modSettings['enableOpenID']))
         echo '
               <br />
               <input type="text" name="openid_identifier" id="openid_url" size="25" class="input_text openid_login" />';

      echo '
               <input type="hidden" name="hash_passwrd" value="" />
            </form>';
   }

   if ($context['user']['is_logged'] || !empty($context['show_login_bar']))
      echo '
         </div>
      </div>';

   echo '
      <div id="news_section" class="titlebg2 clearfix"', empty($options['collapse_header']) ? '' : ' style="display: none;"', '>
         <form class="floatright" id="search_form" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
            <a href="', $scripturl, '?action=search;advanced" title="', $txt['search_advanced'], '"><img id="advsearch" src="'.$settings['images_url'].'/filter.png" align="middle" alt="', $txt['search_advanced'], '" /></a>
            <input type="submit" name="submit" value="', $txt['search'], '" style="width: 11ex; border: 1px dotted #ceb54b; background: #242424; color: white;" class="button_submit" />
            <input type="hidden" name="advanced" value="0" />';

   // Search within current topic?
   if (!empty($context['current_topic']))
      echo '
            <input type="hidden" name="topic" value="', $context['current_topic'], '" />';
      // If we're on a certain board, limit it to this board ;).
   elseif (!empty($context['current_board']))
      echo '
            <input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';

   echo '
         </form>';

   // Show a random news item? (or you could pick one from news_lines...)
   if (!empty($settings['enable_news']))
      echo '
         <div id="random_news"><h3>', $txt['news'], ':</h3><p>', $context['random_news_line'], '</p></div>';

   echo '
      </div>
   </div>';

   // Define the upper_section toggle in JavaScript.
   echo '
   <script type="text/javascript"><!-- // --><![CDATA[
      var oMainHeaderToggle = new smc_Toggle({
         bToggleEnabled: true,
         bCurrentlyCollapsed: ', empty($options['collapse_header']) ? 'false' : 'true', ',
         aSwappableContainers: [
            \'user_section\',
            \'news_section\'
         ],
         aSwapImages: [
            {
               sId: \'upshrink\',
               srcExpanded: smf_images_url + \'/upshrink.gif\',
               altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
               srcCollapsed: smf_images_url + \'/upshrink2.gif\',
               altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
            }
         ],
         oThemeOptions: {
            bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
            sOptionName: \'collapse_header\',
            sSessionVar: ', JavaScriptEscape($context['session_var']), ',
            sSessionId: ', JavaScriptEscape($context['session_id']), '
         },
         oCookieOptions: {
            bUseCookie: ', $context['user']['is_guest'] ? 'true' : 'false', ',
            sCookieName: \'upshrink\'
         }
      });
   // ]]></script>';

   // Show the menu here, according to the menu sub template.
   echo '
    <div id="toolbar">
   ',template_menu(),'
    </div>';


I think I see the function I need to use, but I'm not sure where/how to incorporate it into the Sunset2.0 template. Anybody willing to give a hand?

[edit] code tags for code not quote tags --Illori

Antechinus

1/ Get rid of this from the current template:


         <td valign="middle" align="right"><p>';

   // If the user is logged in, display stuff like their name, new messages, etc.
   if ($context['user']['is_logged'])
   {
      echo '
            ', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>', $context['allow_pm'] ? ', ' . $txt['msg_alert_you_have'] . ' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' . ($context['user']['messages'] != 1 ? $txt['msg_alert_messages'] : $txt['message_lowercase']) . '</a>' . $txt['newmessages4'] . ' ' . $context['user']['unread_messages'] . ' ' . ($context['user']['unread_messages'] == 1 ? $txt['newmessages0'] : $txt['newmessages1']) : '', '<br /><a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
                        <a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a>';

      // Are there any members waiting for approval?
      if (!empty($context['unapproved_members']))
         echo '<br />
            ', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=admin;area=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'];
      // Is the forum in maintenance mode?
      if ($context['in_maintenance'] && $context['user']['is_admin'])
         echo '<br />
            <b>', $txt['maintain_mode_on'], '</b>';

      if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
         echo '<br />
            <a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a>';
   }
   // Otherwise they're a guest - so politely ask them to register or login.
   else
      echo '
            ', sprintf($txt['welcome_guest'], $txt['guest_title']);


   echo '
            <br />', $context['current_time'], '
         </p></td>


2/ Would need to see the rest of the template to sort the rest.

3/ Shoot the theme author for using tables for layout. :P

Advertisement: