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

Renaming directories?

Discussion in 'XenForo Development Discussions' started by The Forum Heroes, Sep 10, 2011.

  1. The Forum Heroes

    The Forum Heroes Well-Known Member

    How can I change a directory name in XF? I would like to changes /members to something else.
     
  2. ChemicalKicks

    ChemicalKicks Well-Known Member

    No good can come from this *shakes fist*
     
  3. The Forum Heroes

    The Forum Heroes Well-Known Member

  4. James

    James Well-Known Member

    You'd have to rewrite XenForo_Route_Prefix_Members.
     
  5. The Forum Heroes

    The Forum Heroes Well-Known Member

    Thanks James, where do I do that at?
     
  6. Floris

    Floris Guest

    library/xenforo/ has all the files, most elements are quite integrated, but you can look for the /Route/ folders underneath the features/controllers you like to change. dont' forget to customize the route prefix linked to the php callback in the backend.

    I do strongly recommend against customizing the files. It will potentially lead to problem, especially if you're not experienced with coding or this framework.

    I sugget to consider catching all /members/ urls and mod_rewrite them with a ReWrite rule via .htaccess.
     
  7. CJ.Wurtz

    CJ.Wurtz Member

    I had to tackle this one tonight. It didn't require any edits to XF code, although keep in mind I still haven't tested everything out to make sure this was problem free... But here's how I did it:

    *I'll assume you had a working directory for mod files*

    1) I created a file: "MyMod/Listener/LoadRoutePrefix.php"
    2) Added this code to it:
    PHP:
    <?php
    class MyMod_Listener_LoadRoutePrefix
    {
        
    /**
        * Instruct the system that XenForo_ControllerPublic_Member
        * should be extended by Dev_ControllerPublic_Member
        *
        * @param string $class
        * @param array $extend
        */
        
    public static function extendMembersRoute($class, array &$extend)
        {
            if (
    $class == 'XenForo_Route_Prefix_Members')
            {
                
    $extend[] = 'MyMod_Route_Members';
            }
        }
    }
    ?>
    3) I created a file: "MyMod/Route/Members.php"
    4) I added this code to it:
    PHP:
    <?php
    class MyMod_Route_Members extends XFCP_MyMod_Route_Members
    {
        
    /**
        * Match a specific route for an already matched prefix.
        *
        * @see XenForo_Route_Interface::match()
        */
        
    public function match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            
    $action $router->resolveActionWithIntegerParam($routePath$request'user_id');
            return 
    $router->getRouteMatch('XenForo_ControllerPublic_Member'$action'members');
        }

        
    /**
        * Method to build a link to the specified page/action with the provided
        * data and params.
        *
        * @see XenForo_Route_BuilderInterface
        */
        
    public function buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
        {
            
    $outputPrefix "players"// this is what "members" will be renamed to
            
    return parent::buildLink($originalPrefix$outputPrefix$action$extension$data$extraParams);
        }
    }
    ?>
    *Pay attention to the 5th line from the end*

    5) I created a file: "MyMod/Route/Players.php"
    6) I added this code to it:
    PHP:
    <?php
    class MyMod_Route_Players implements XenForo_Route_Interface
    {
        
    /**
        * Match a specific route for an already matched prefix.
        *
        * @see XenForo_Route_Interface::match()
        */
        
    public function match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            
    $action $router->resolveActionWithIntegerParam($routePath$request'user_id');
            return 
    $router->getRouteMatch('XenForo_ControllerPublic_Member'$action'players');
        }

        
    /**
        * Method to build a link to the specified page/action with the provided
        * data and params.
        *
        * @see XenForo_Route_BuilderInterface
        */
        
    public function buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
        {
            if (isset(
    $extraParams['page']))
            {
                if (
    strval($extraParams['page']) !== XenForo_Application::$integerSentinel && $extraParams['page'] <= 1)
                {
                    unset(
    $extraParams['page']);
                }
            }

            return 
    XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix$action$extension$data'user_id''username');
        }
    }
    ?>
    7) I went into the admin panel and added a new listen
    The "Listen to Event" field is set to: "load_class_route_prefix"
    The "Execute Callback" field is set to: "MyMod_Listener_LoadRoutePrefix"::"extendMembersRoute"

    8) I then added a new route
    I set the "Route Prefix" to "players"... this should match whatever you set $outputPrefix to in step #4

    That's it. Basically this will still use the default XF route prefix for "members" except it will change it to "players" (or whatever you set it to), when it builds the links. So assuming everywhere on the forum you are using "{xen:link members}" it should automatically redirect the link. And then when you go to that URL, the code above is a copy of the members route, so you'll need to keep "MyMod/Route/Members.php" up to date with whatever is in "XenForo/Route/Prefix/Members.php" when you upgrade. You can probably just call the parent for the match() method as well in the "Player.php" (or whatever you want to call yours), however I'll be adding a bunch of other options so I need to route mine to a different controller, so I didn't do it that way.

    You will probably still want to add a mod_rewrite as Floris suggested in case any posts on the forum are linking to a members profile with "members" in the URL. However the old "members" URL should still work

    Anyway, I hope that helps, and if anyone sees a problem with my implementation I would appreciate if you point it out. I've only been working with XF for a couple weeks, so I very easily could have missed something.
     
    Digital Doctor likes this.
  8. Digital Doctor

    Digital Doctor Well-Known Member

    If this works well, could you make a new thread and post it.
    Lots of people want to do this.
    LOTS.

    I don't believe the correct word for /members/ is directory, but maybe that is better than the technical name !
    What would the name of it be ?
     
  9. CJ.Wurtz

    CJ.Wurtz Member

    Sure can, but I'm going to wait a little longer to see how well it works out. I just made the change last night, and my board isn't live yet. I'll probably notice if someone is wrong while work on other modifications over the next couple days
     
    Digital Doctor likes this.

Share This Page