1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Implemented In addition to $extraTabs, lets have a $homeTabs

Discussion in 'Closed Suggestions' started by Jaxel, Nov 5, 2010.

  1. Jaxel

    Jaxel Well-Known Member

    Okay... so a while back, Kier said he would look into the feasibility of making the "Home" button a real tab... well I've already done the work! Its actually pretty simple and I recommend it gets added to XenForo's base code...

    EDIT TEMPLATE: navigation
    find:
    Code:
    		<!-- home -->
    		<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase home}</a></li>
    replace with:
    Code:
    		<!-- home tabs -->
    		<xen:if is="{$homeTabs}">
    		<xen:foreach loop="$homeTabs" key="$homeTabId" value="$homeTab">
    			<xen:if is="{$homeTab.linksTemplate}">
    				<li class="navTab $extraTabId {xen:if $homeTab.selected, 'selected', 'Popup PopupControl PopupClosed'}">
    				<a href="{$homeTab.href}" class="navLink">{$homeTab.title}</a>
    				<a href="{$homeTab.href}" class="SplitCtrl" rel="Menu"></a>
    				<div class="{xen:if {$homeTab.selected}, 'tabLinks', 'Menu JsOnly tabMenu'}">
    					<div class="primaryContent menuHeader">
    						<h3>{$homeTab.title}</h3>
    						<div class="muted">{xen:phrase quick_links}</div>
    					</div>
    					{xen:raw $homeTab.linksTemplate}
    				</div>
    			</li>
    			<xen:else />
    				<li class="navTab PopupClosed"><a href="{$homeTab.href}" class="navLink">{$homeTab.title}</a></li>
    			</xen:if>
    		</xen:foreach>
    		<xen:else />
    			<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase home}</a></li>
    		</xen:if>
    As you can see, this new replacement looks for a variable $homeTabs... if the variable doesn't exist, then it reverts to the classic Home tab that we have with the current version of XenForo. Once thats done... all we need to do is tell XenForo how to handle the $homeTabs variable...

    EDIT FILE: /library/XenForo/Dependencies/Public.php
    find: (in protected function _getNavigationContainerParams)
    Code:
    		$extraTabs = array();
    		XenForo_CodeEvent::fire('navigation_tabs', array(&$extraTabs, $selectedTabId));
    
    		if (!empty($extraTabs[$selectedTabId]))
    		{
    			$selectedTab = $extraTabs[$selectedTabId];
    		}
    		else if (!empty($tabs[$selectedTabId]))
    		{
    			$selectedTab = $tabs[$selectedTabId];
    		}
    		else
    		{
    			$selectedTabId = '';
    			$selectedTab = false;
    		}
    
    		$options = XenForo_Application::get('options');
    
    		if ($options->homePageUrl)
    		{
    			$homeLink = $options->homePageUrl;
    			$logoLink = ($options->logoLink ? $homeLink : XenForo_Link::buildPublicLink('full:index'));
    		}
    		else
    		{
    			$homeLink = XenForo_Link::buildPublicLink('full:index');
    			$logoLink = $homeLink;
    		}
    
    		return array(
    			'tabs' => $tabs,
    			'extraTabs' => $extraTabs,
    			'selectedTab' => $selectedTab,
    			'selectedTabId' => $selectedTabId,
    			'homeLink' => $homeLink,
    			'logoLink' => $logoLink,
    		);
    replace with:
    Code:
    		$homeTabs = array();
    		$extraTabs = array();
    		XenForo_CodeEvent::fire('navigation_tabs', array(&$homeTabs, &$extraTabs, $selectedTabId));
    
    		if (!empty($extraTabs[$selectedTabId]))
    		{
    			$selectedTab = $extraTabs[$selectedTabId];
    		}
    		else if (!empty($homeTabs[$selectedTabId]))
    		{
    			$selectedTab = $homeTabs[$selectedTabId];
    		}
    		else if (!empty($tabs[$selectedTabId]))
    		{
    			$selectedTab = $tabs[$selectedTabId];
    		}
    		else
    		{
    			$selectedTabId = '';
    			$selectedTab = false;
    		}
    
    		$options = XenForo_Application::get('options');
    
    		if ($options->homePageUrl)
    		{
    			$homeLink = $options->homePageUrl;
    			$logoLink = ($options->logoLink ? $homeLink : XenForo_Link::buildPublicLink('full:index'));
    		}
    		else
    		{
    			$homeLink = XenForo_Link::buildPublicLink('full:index');
    			$logoLink = $homeLink;
    		}
    
    		return array(
    			'tabs' => $tabs,
    			'homeTabs' => $homeTabs,
    			'extraTabs' => $extraTabs,
    			'selectedTab' => $selectedTab,
    			'selectedTabId' => $selectedTabId,
    			'homeLink' => $homeLink,
    			'logoLink' => $logoLink,
    		);
    You'll notice: XenForo_CodeEvent::fire('navigation_tabs', array(&$homeTabs, &$extraTabs, $selectedTabId));
    has a new reference called "$homeTabs"... this is an update to the Code Event Listener, and thusly mod writers will have to update their navtab listener classes with this new variable. Yes, this is troublesome, but at the moment there are not that many mods released yet, so the transition should be relatively simple. The sooner this change of mine is included into the base XenForo installation , the easier the transition will be...

    EDIT FILE: /library/XenForo/ViewRenderer/HtmlPublic.php
    find: (in public function renderContainer)
    Code:
    		if (!empty($params['extraTabs']))
    		{
    			foreach ($params['extraTabs'] AS &$extraTab)
    			{
    				if (!empty($extraTab['linksTemplate']))
    				{
    					$extraTab['linksTemplate'] = $this->createTemplateObject($extraTab['linksTemplate'], $extraTab);
    				}
    			}
    		}
    add below:
    Code:
    		if (!empty($params['homeTabs']))
    		{
    			foreach ($params['homeTabs'] AS &$homeTab)
    			{
    				if (!empty($homeTab['linksTemplate']))
    				{
    					$homeTab['linksTemplate'] = $this->createTemplateObject($homeTab['linksTemplate'], $homeTab);
    				}
    			}
    		}


    THATS IT! Now, a mod need only add a tab to $homeTabs instead of $extraTabs if they want to replace the home link! Now that the work is already done... there is no reason this addition shouldn't be made to XenForo. Plus I made this solution as elegant as I could, and it conforms to the XenForo coding style.
     
    turtile, NolF, anotheralias and 7 others like this.
  2. Jaxel

    Jaxel Well-Known Member

    Pope Vipe and Laric like this.
  3. Digital Doctor

    Digital Doctor Well-Known Member

  4. Mythotical

    Mythotical Well-Known Member

    Thanks Jaxel, just what I needed, couldn't figure it out but then again I got sidetracked from finding the solution.
     
  5. DoctorWatsOn

    DoctorWatsOn Well-Known Member

    Oh, this is looking like what I need, I'll have a play later. :)
     
  6. Digital Doctor

    Digital Doctor Well-Known Member

    Great work Jaxel.
     
  7. Jaxel

    Jaxel Well-Known Member

    Unfortunately, it looks like Kier and Mike chose not to add this feature to Beta 3...
     
    Digital Doctor likes this.
  8. Jaxel

    Jaxel Well-Known Member

    Hey... can I get some sort of confirmation on whether or not this type of feature will be added to XenForo? I've been holding off releasing updates to my mods until this specific issue is sorted out. If its not gonna happen, just say so please.
     
  9. Mike

    Mike XenForo Developer Staff Member

    It's something to consider, but there are various other things on our plate right now. I couldn't make a commitment either way. I wouldn't hold up releasing your stuff solely because of this; you're missing out on valuable other info by doing that.
     
  10. Jaxel

    Jaxel Well-Known Member

    Well until something like this is put in... it makes a portal mod even more impossible. What sort of valuable other info would I we be missing by including this patch?
     
  11. Mike

    Mike XenForo Developer Staff Member

    I just meant losing out on ability to get feedback on your own mod, notwithstanding a template edit.
     
  12. Jaxel

    Jaxel Well-Known Member

    Ah...

    I know I'm being a bit forward here, and I do understand you guys have a lot on your plate. But really this patch isn't a complicated issue; its just 2 very quick file edits, and a template edit. It causes zero issues with the base XF package. The only issues it creates are with existing user written modifications which use the navtab system; in that the navtabs code event now takes (&$homeTabs, &$extraTabs, $selectedTabId) instead of just (&$extraTabs, $selectedTabId).

    Its the type of edit that can be done very easily in under a minute; and it defaults the current homeTab if no custom homeTabs are defined. As I said before, since the only issue is with existing user written mods, the sooner something like this gets taken care of, the better. There are still relatively few user written mods, and their authors are very active; it would be very easy for them to patch up their own mods very quick; and all they need to do is add a single string to their parameters.
     
  13. Digital Doctor

    Digital Doctor Well-Known Member

    Seems, an ounce of prevention is worth a pound of cure.
    The longer it takes to hack a real Home Tab, the more problems that will ensue.
    Adding a Home Tab seems low risk / high reward.
     
    laztrix likes this.
  14. jadmperry

    jadmperry Well-Known Member

    Sorry if I am late to the game....it looks to me like the above template change is different in Beta 3? Is there an update to this based on B3?
     
  15. Peggy

    Peggy Well-Known Member

    o/t

    * wonders why it is that the first time I read the title to this thread I read SextraTabs and ShomeTabs? *

    end o/t
     
    DoctorWatsOn and Chimpie like this.
  16. anotheralias

    anotheralias Well-Known Member

    I don't get why we can't just put a link to whatever we want in the home tab and change the name of the link to whatever we like? Seriously, we have to go through all that just to make the Home tab link to something else? That's an even steeper learning curve than Flash ... are you kidding me?

    If someone is willing to do Mods that will save me from that kind of hell, please... make it easy for them to create Mods. Give them whatever they want!
     
  17. DoctorWatsOn

    DoctorWatsOn Well-Known Member

    Is that a new name for viagra?
     
  18. Floris

    Floris Guest

    Excellent job! :D

    I rather have a drag/drop top menu manager in the admin.php > header > menu.
     
  19. Decent60

    Decent60 Well-Known Member

    If you want to change the Home tab to something completely different, that is completely easy:
    AdminCP => Options => Basic Board Information:
    Code:
    Home Page URL
    
    This is the URL to your home page, outside of the board. If this is left blank, links to 'Home' will point to the forum index.
    
    AdminCP => Appearances => Phrases:
    Change Home to whatever word you would like
    -----------------------------------------------------------------------
    Now truly, I'm not a coder, so I really don't see much of a difference in calling it either $homeTabs or $extraTabs, unless there is a complete style difference.
     
    anotheralias likes this.
  20. NolF

    NolF Active Member

    Jaxel I sincerely hope this changes make it to the gold. It will allow enormous flexibility to moders and to have a real portal.

    I'm wondering with that code, what happens if another modification also makes use of the $homeTabs? It looks like it would show both. How does the code decide which one is first? And more eimportantly, wouldn't it be problematic for later having the forums at /forum? if /index is being fought between two+ mods?
     

Share This Page