Yet another Add tabs question ;)

Started by smartdeviceresource, January 04, 2010, 01:22:17 AM

Previous topic - Next topic

smartdeviceresource

Ok not really
we sucessfully added the tabs via the Tutourial and they link correctly.

However Active tab (on the two new tabs) does not occur.  Meaning, if I click on home tab, or search tab the current page is highlighted via the tab bar, however if I click on (these are the two we added) Unread Posts or Unread Replies it highlights Home Tab
This is a Core Based theme

// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.
if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated'])
{
$buttons = array(
'home' => array(
'title' => $txt['home'],
'href' => $scripturl,
'show' => true,
'sub_buttons' => array(
),
'is_last' => $context['right_to_left'],
// 'target' => '_blank',
),
                       
'help' => array(
'title' => $txt['help'],
'href' => $scripturl . '?action=help',
'show' => true,
'sub_buttons' => array(
),
),
'search' => array(
'title' => $txt['search'],
'href' => $scripturl . '?action=search',
'show' => $context['allow_search'],
'sub_buttons' => array(
),
),
'newposts' => array(
'title' => 'New Posts',
'href' => $scripturl . '?action=unread',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),
'newreplies' => array(
'title' => 'New Replies',
'href' => $scripturl . '?action=unreadreplies',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),
'admin' => array(
'title' => $txt['admin'],
'href' => $scripturl . '?action=admin',
'show' => $context['allow_admin'],
'sub_buttons' => array(
'featuresettings' => array(
'title' => $txt['modSettings_title'],
'href' => $scripturl . '?action=admin;area=featuresettings',
'show' => allowedTo('admin_forum'),
),
'packages' => array(
'title' => $txt['package'],
'href' => $scripturl . '?action=admin;area=packages',
'show' => allowedTo('admin_forum'),
),
'errorlog' => array(
'title' => $txt['errlog'],
'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
'show' => allowedTo('admin_forum') && !empty($modSettings['enableErrorLogging']),
),
'permissions' => array(
'title' => $txt['edit_permissions'],
'href' => $scripturl . '?action=admin;area=permissions',
'show' => allowedTo('manage_permissions'),
),
),
),
'moderate' => array(
'title' => $txt['moderate'],
'href' => $scripturl . '?action=moderate',
'show' => $context['allow_moderation_center'],
'sub_buttons' => array(
'modlog' => array(
'title' => $txt['modlog_view'],
'href' => $scripturl . '?action=moderate;area=modlog',
'show' => !empty($modSettings['modlog_enabled']),
),
'poststopics' => array(
'title' => $txt['mc_unapproved_poststopics'],
'href' => $scripturl . '?action=moderate;area=postmod;sa=posts',
'show' => $modSettings['postmod_active'],
),
'attachments' => array(
'title' => $txt['mc_unapproved_attachments'],
'href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
'show' => $modSettings['postmod_active'],
),
'reports' => array(
'title' => $txt['mc_reported_posts'],
'href' => $scripturl . '?action=moderate;area=reports',
'show' => true,
),
),
),
'profile' => array(
'title' => $txt['profile'],
'href' => $scripturl . '?action=profile',
'show' => $context['allow_edit_profile'],
'sub_buttons' => array(
'summary' => array(
'title' => $txt['summary'],
'href' => $scripturl . '?action=profile',
'show' => true,
),
'account' => array(
'title' => $txt['account'],
'href' => $scripturl . '?action=profile;area=account',
'show' => allowedTo(array('profile_identity_any', 'profile_identity_own', 'manage_membergroups')),
),
'profile' => array(
'title' => $txt['forumprofile'],
'href' => $scripturl . '?action=profile;area=forumprofile',
'show' => allowedTo(array('profile_extra_any', 'profile_extra_own')),
),
),
),
'pm' => array(
'title' => $txt['pm_short'],
'href' => $scripturl . '?action=pm',
'show' => $context['allow_pm'],
'sub_buttons' => array(
'pm_read' => array(
'title' => $txt['pm_menu_read'],
'href' => $scripturl . '?action=pm',
'show' => allowedTo('pm_read'),
),
'pm_send' => array(
'title' => $txt['pm_menu_send'],
'href' => $scripturl . '?action=pm;sa=send',
'show' => allowedTo('pm_send'),
),
),
),
'calendar' => array(
'title' => $txt['calendar'],
'href' => $scripturl . '?action=calendar',
'show' => $context['allow_calendar'],
'sub_buttons' => array(
'view' => array(
'title' => $txt['calendar_menu'],
'href' => $scripturl . '?action=calendar',
'show' => allowedTo('calendar_post'),
),
'post' => array(
'title' => $txt['calendar_post_event'],
'href' => $scripturl . '?action=calendar;sa=post',
'show' => allowedTo('calendar_post'),
),
),
),
'mlist' => array(
'title' => $txt['members_title'],
'href' => $scripturl . '?action=mlist',
'show' => $context['allow_memberlist'],
'sub_buttons' => array(
'mlist_view' => array(
'title' => $txt['mlist_menu_view'],
'href' => $scripturl . '?action=mlist',
'show' => true,
),
'mlist_search' => array(
'title' => $txt['mlist_search'],
'href' => $scripturl . '?action=mlist;sa=search',
'show' => true,
),
),
),
// [Staff] button
'staff' => array(
'title' => $txt['smfstaff_stafflist'],
'href' => $scripturl . '?action=staff',
'show' => $context['allow_view_stafflist'],
'icon' => '',
),
'login' => array(
'title' => $txt['login'],
'href' => $scripturl . '?action=login',
'show' => $user_info['is_guest'],
'sub_buttons' => array(
),
),
'register' => array(
'title' => $txt['register'],
'href' => $scripturl . '?action=register',
'show' => $user_info['is_guest'],
'sub_buttons' => array(
),
'is_last' => !$context['right_to_left'],
),
'logout' => array(
'title' => $txt['logout'],
'href' => $scripturl . '?action=logout;%1$s=%2$s',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
'is_last' => !$context['right_to_left'],
),
);

// Now we put the buttons in the context so the theme can use them.
$menu_buttons = array();
foreach ($buttons as $act => $button)
if (!empty($button['show']))
{
$button['active_button'] = false;

// Make sure the last button truely is the last button.
if (!empty($button['is_last']))
{
if (isset($last_button))
unset($menu_buttons[$last_button]['is_last']);
$last_button = $act;
}

// Go through the sub buttons if there are any.
if (!empty($button['sub_buttons']))
foreach ($button['sub_buttons'] as $key => $subbutton)
{
if (empty($subbutton['show']))
unset($button['sub_buttons'][$key]);
}

$menu_buttons[$act] = $button;
}

if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
}

$context['menu_buttons'] = $menu_buttons;

// Logging out requires the session id in the url.
if (isset($context['menu_buttons']['logout']))
$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);

// Figure out which action we are doing so we can set the active tab.
// Default to home.
$current_action = 'home';

if (isset($context['menu_buttons'][$context['current_action']]))
$current_action = $context['current_action'];
elseif ($context['current_action'] == 'search2')
$current_action = 'search';
elseif ($context['current_action'] == 'theme')
$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
elseif ($context['current_action'] == 'register2')
$current_action = 'register';
elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
$current_action = 'login';

$context['menu_buttons'][$current_action]['active_button'] = true;

if (!$user_info['is_guest'] && $context['user']['unread_messages'] > 0 && isset($context['menu_buttons']['pm']))
{
$context['menu_buttons']['pm']['alttitle'] = $context['menu_buttons']['pm']['title'] . ' ['. $context['user']['unread_messages'] . ']';
$context['menu_buttons']['pm']['title'] .= ' [<strong>'. $context['user']['unread_messages'] . '</strong>]';
}
}

I am pretty sure I am forgetting to put something in the last part (the Context part) but am unsure what.
website is http://forum.smartdeviceresource.com
after some thought, i've learned to be humble and leave the answering to the experts, until i too am an expert.  sorry to anyone who I've confused, with my answers

SA™

you have to set it the same as the action

eg if the action is

yoursite.com/index.php?action=bla

then the tab will look like this

'bla' => array(
'title' => 'New Posts',
'href' => $scripturl . '?action=bla',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),


here the code for the tabs
'unread' => array(
'title' => 'New Posts',
'href' => $scripturl . '?action=unread',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),
'unreadreplies' => array(
'title' => 'New Replies',
'href' => $scripturl . '?action=unreadreplies',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

smartdeviceresource

#2
ok I see what you are saying
I replaced
'newposts' => array(
'title' => 'New Posts',
'href' => $scripturl . '?action=unread',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),
'newreplies' => array(
'title' => 'New Replies',
'href' => $scripturl . '?action=unreadreplies',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),

with
'unread' => array(
'title' => 'New Posts',
'href' => $scripturl . '?action=unread',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),
'unreadreplies' => array(
'title' => 'New Replies',
'href' => $scripturl . '?action=unreadreplies',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
),

and got
QuoteFatal error: Call to undefined function writeLog() in /homepages/36/d312159748/htdocs/forum/index.php on line 207


EDIT: retried the edits and it worked
This issue Marked solved
after some thought, i've learned to be humble and leave the answering to the experts, until i too am an expert.  sorry to anyone who I've confused, with my answers

SA™

hmm realy? write log writes to who online i think i dont see why you would get that considering this dont even touch that did you go wrong someware?
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

smartdeviceresource

I think I had an extra comma or extra whitespace so that when I (as a user) clicked on unread it caused that error (see what I get for trying to do your edit in Notepad :P )
I went back to the original and just changed the two words and it worked great. again Thank you :)
after some thought, i've learned to be humble and leave the answering to the experts, until i too am an expert.  sorry to anyone who I've confused, with my answers

ilearnmath.net

#5
Thanks for the useful information. I am dealing with a similar problem, except after the question mark I need 'page' rather than 'action'. The links show just fine in the default theme (which is all I need), but once clicked, they do not highlight as active. Instead, the Home Tab is highlighted.

It is not a big issue if I can't have this fixed but if anyone has a quick solution, please do share. The code is below, and the forum is at:

http://www.ilearnmath.net/help/

Thanks a bunch.

'apcalculus' => array(
'title' => 'AP Calculus AB/BC',
'href' => $scripturl . '?page=apcalculus',
'show' => true,
'sub_buttons' => array(
),
),

KensonPlays

Ilearnmath:
What portal are you using? (If any)

Owner of Mesozoic Haven

ilearnmath.net

thanks for getting back to me.  I am currently using SimplePortal, also considering PortaMX.

deansmar

i have exactly the same question as ilearnmath.net, but there does not seem to be an answer in this thread, has this been solved somewere else that i have not found jet ??

i am running a test system with WAMP
SMF version 2 RC 3
the only mod that is installed is Simple Portal
i have made a copy of the SMF Default Theme - Core, which i am modding.

when moving the Help and Search arrays to the Forums Sub arrays, the arrays work fine with out any errors.

the problem is; the "Forum" tab does not stay active?


'forum' => array(
'title' => empty($txt['sp-forum']) ? 'Forum' : $txt['sp-forum'],
'href' => $scripturl . ($modSettings['sp_portal_mode'] == 1 && empty($context['disable_sp']) ? '?action=forum' : ''),
'show' => in_array($modSettings['sp_portal_mode'], array(1, 3)) && empty($context['disable_sp']),
'sub_buttons' => array(
                'help' => array(
          'title' => $txt['help'],
          'href' => $scripturl . '?action=help',
'show' => true,
          ),
                'search' => array(
                'title' => $txt['search'],
                'href' => $scripturl . '?action=search',
          'show' => $context['allow_search'],
),
),
),


i would appreciate any input in this matter..

deansmar

the first part of the problem i have solved my self...  by adding the following code to the Sources\Subs.php at around line 4175 you will find;

Quote
// Figure out which action we are doing so we can set the active tab.
// Default to home.
Add into the If equation this code;

elseif ($context['current_action'] == 'search')
$current_action = 'forum';
elseif ($context['current_action'] == 'help')
$current_action = 'forum';


the problem still remains that any added tab will Default to home if the action is not declared, pity that Simple Portal does not use the action command.

standard SMF: www.xxx/forum/index.php?action=forum

standard SP: www.xxx/forum/index.php?page=page1


       'Company' => array(
        'title' => 'Company Info',
        'href' => $scripturl . '?page=page2',
        'show' => true,
        'sp_page' => true,
        'sub_buttons' => array(
                'page2' => array(
          'title' => 'Company 2',
                'href' => $scripturl . '?page=page2',
                'show' => true,
                'sp_page' => true,           
           ),
                'page1' => array(
          'title' => 'Compan 1',
                'href' => $scripturl . '?page=page1', 
                'show' => true,
                'sp_page' => true,   
                'is_last' => true,       
           ),
      ),
    ),


the array works fine, but because there is no action declared the Tab Company will not become active, and defaults to the Home tab...

can someone point me in the right direction..??

ilearnmath.net

Hi deansmar,
I managed to get mine to work (see it at ilearnmath.net [nofollow]), but don't remember the exact url of the place where I found the fix. In my Subs.php file, below I am pasting the part I changed, in addition to the individual tabs having the added line
'sp_page' => true,

// Figure out which action we are doing so we can set the active tab.
// Default to home.
$current_action = 'home';

   if (isset($context['menu_buttons'][$context['current_action']]) && empty($context['menu_buttons'][$context['current_action']]['sp_page']))
      $current_action = $context['current_action'];


Good luck!

deansmar

there must be something some were else, that didn't do the trick..  8)

deansmar


ilearnmath.net

i believe this may be the the discussion i used:

http://simpleportal.net/index.php?topic=3857.0

do let me know if it works.

deansmar

just by looking at the code it should work very well i'll try tomorrow..

you had given me the right code, but the extra elseif you had forgotten

 
if (isset($context['menu_buttons'][$context['current_action']]) && empty($context['menu_buttons'][$context['current_action']]['sp_page']))     
$current_action = $context['current_action'];   
elseif (empty($context['current_action']) && !empty($_REQUEST['page']) && isset($context['menu_buttons'][$_REQUEST['page']]))     
$current_action = $_REQUEST['page'];


thanks for the pointer

now we have the code all in one place  ;)

deansmar

the code looks good, but its not working...  with my versions of SMF and SP

deansmar

#16
stupid mistake through me.... the above code does work...

when making the Array in Sources\Subs.php the name of the Array has to be the same as the PageID.

Quote
        'History' => array(
        'title' => 'Company Info',
        'href' => $scripturl . '?page=History',
        'show' => true,
        'sp_page' => true,
        'sub_buttons' => array(

        ),

i am now trying to get the Sub_buttons array to work...  ;)  8)

deansmar

after a little bit of research and a lot of reading i think i have found out how to:
when a sub_menu button is chosen from an Added page through SP then the correct button in the main menu is highlighted

Sub_Buttons in an Array, this code has been added to the sources\subs.php some time after this line:

// Figure out which action we are doing so we can set the active tab.

of course the Page-ID has to be the ID of your page and like wise the Array-ID is the name of the main Array not the name of the sub arrays

first idea:
  elseif (isset($_REQUEST['page']) && $_REQUEST['page'] == 'Page-ID')
    $current_action = 'Array-ID';
  elseif (isset($_REQUEST['page']) && $_REQUEST['page'] == 'Page-ID')
    $current_action = 'Array-ID';


Second revamped idea:
  elseif (isset($_REQUEST['page']) && in_array($_REQUEST['page'], array('Page-ID-1', 'Page-ID-2' , 'Page-ID-3' )))        
     $current_action = 'Array-ID';


there is no limited Page-ID's that i know of, i just happen to have two new Tabs in my Main Menu, each of these Tabs has three sub_buttons.

I'll leave this open for someone to make this completely automatic, so one does not have to enter the Page-ID's in the subs.php..  :o

Advertisement: