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

Improve $xf_path array to auto-discover XF location

Discussion in 'General PHP and MySQL Discussions' started by LPH, Jan 31, 2014.

  1. LPH

    LPH Well-Known Member

    I'm trying to write some code that auto-discovers the location of XF from an external page. This code works on my server but the number of locations for installing could be far greater. How could I improve this array to get a greater probability to get the correct path location?

           $xf_paths = array(
              'community' ,
               'forum' );
           foreach ( $xf_paths as $xf_path ) {
               $startTime = microtime(true);
                if( $this->fileDir = ABSPATH . $xf_path ) {
                    if( !class_exists("XenForo_Autoloader" ) ) {
                        require($this->fileDir . '/library/XenForo/Autoloader.php');
                        XenForo_Autoloader::getInstance()->setupAutoloader($this->fileDir . '/library');
                        XenForo_Application::initialize($this->fileDir . '/library', $this->fileDir);
                        echo XenForo_Application::getInstance()->getRootDir();
    Again - this works on my server because the XF is installed domain.com/community. It should get someone who installed it in /forums or /forum ...

    What other possibilities are there?

    Maybe you have a better suggestion instead of the array ...

    Thank you in advance.

    Update: I realize that this code leaves things hanging if the $xf_paths is not correct and needs to be updated to return a message for the user to input the location. I'm still working on improving that too.
    seojoseph likes this.

Share This Page