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

Adding links to the visitor tab

Discussion in 'XenForo Development Discussions' started by ragtek, Jul 14, 2011.

  1. ragtek

    ragtek Guest

    How do you add own links to the visitor tab (template hook navigator_visitor_tab_links1)?

    i'm using str_replace (had to change it now to preg_replace) to search </ul> and replace it with mine code...
    PHP:
    if ($name == 'navigation_visitor_tab_links1') {
    if (
    Ragtek_Invite_Helper::perm('canUse')) {
    $search '</ul>';
    $replace $template->create('ragtek_invite_visitortab') .'</ul>';
    $contents str_replace($search$replace$contents);
    }
    }
    Is this ok?

    Problem is, that there is at least 1 add-on which adds a own <ul> list there.

    So if my add-on runs AFTER this, it will find 2 ul lists, and insert the link 2 times. (so i had to run preg_replace instead of str_replace, but isn't inserting a second ul list false because then you have at least 3 ul lists which aren't in the right position??
     
  2. ragtek

    ragtek Guest

  3. Lawrence

    Lawrence Well-Known Member

    Using substr_replace($contents, $replace, 0, 0) will insert your data once, right before the first instance of what you are searching for, so you do not need to add .'</ul>' to the end of $replace.
     
  4. ragtek

    ragtek Guest

    I'm doing it with preg_replace which is already replace it once and stop it, BUt i want to know what's the right way for this.
     
  5. Kier

    Kier XenForo Developer Staff Member

    A well-behaved add-on should replace the token so that other add-ons can str_replace on the same token.
     
    ragtek likes this.
  6. Syndol

    Syndol Guest

    Are you suggesting that it is preferable for each add-on to use str_replace in order to insert a link to the list.
    Surely moving the hook inside the <ul> tags and allowing add-ons to simply add a list item <li> would be much preferred.
     
    James and ragtek like this.
  7. Kier

    Kier XenForo Developer Staff Member

    Yes you're right. I'm really not sure why we did it that way...
     
    Walter and James like this.
  8. ragtek

    ragtek Guest

    <what about "html comments" like in the sidebar?*g*
    then we could use them and place our link where we want:)

    (but to be honest, i'm really hopping that you'll implement something like tms soon)
     
    Yoskaldyr likes this.
  9. ragtek

    ragtek Guest

    Quick Note:

    This was changed in xf 1.1
    If anybody wants to include now something into the account menu, you can do this without the need of str_replace or anything else
    Code:
    
    <li>link</li>
    
    PHP:
    <xen:hook name="navigation_visitor_tab_links1">
                        <
    li><a href="{xen:link account/personal-details}">{xen:phrase personal_details}</a></li>
                        <
    xen:if is="{$canEditSignature}"><li><a href="{xen:link account/signature}">{xen:phrase signature}</a></li></xen:if>
                        <
    li><a href="{xen:link account/contact-details}">{xen:phrase contact_details}</a></li>
                        <
    li><a href="{xen:link account/privacy}">{xen:phrase privacy}</a></li>
                        <
    li><a href="{xen:link account/preferences}">{xen:phrase preferences}</a></li>
                        <
    li><a href="{xen:link account/alert-preferences}">{xen:phrase alert_preferences}</a></li>
                        <
    xen:if is="{$canUploadAvatar}"><li><a href="{xen:link account/avatar}" class="OverlayTrigger" data-cacheOverlay="true">{xen:phrase avatar}</a></li></xen:if>
                        <
    xen:if is="{$xenOptions.facebookAppId}"><li><a href="{xen:link account/facebook}">{xen:phrase facebook_integration}</a></li></xen:if>
                        <
    li><a href="{xen:link account/security}">{xen:phrase password}</a></li>
                    </
    xen:hook>
                    </
    ul>
                    <
    ul class="col2 blockLinksList">
                    <
    xen:hook name="navigation_visitor_tab_links2">
                        <
    li><a href="{xen:link account/news-feed}">{xen:phrase your_news_feed}</a></li>
                        <
    li><a href="{xen:link account/alerts}">{xen:phrase your_alerts}</a></li>
                        <
    li><a href="{xen:link watched/threads}">{xen:phrase watched_threads}</a></li>
                        <
    li><a href="{xen:link account/likes}">{xen:phrase likes_youve_received}</a></li>
                        <
    li><a href="{xen:link search/member, '', 'user_id={$visitor.user_id}'}">{xen:phrase your_content}</a></li>
                        <
    li><a href="{xen:link account/following}">{xen:phrase people_you_follow}</a></li>
                        <
    li><a href="{xen:link account/ignored}">{xen:phrase people_you_ignore}</a></li>
                        <
    xen:if is="{$xenCache.userUpgradeCount}"><li><a href="{xen:link account/upgrades}">{xen:phrase account_upgrades}</a></li></xen:if>
                    </
    xen:hook>
    [/code]
     
    Fuhrmann likes this.

Share This Page