• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

i success seperate each add-on's route in subdomain

marioman

Active member
hi,

i have forum in this path

http://www.example.com/forum

download system ( i wrote it with cart using ajax) in this path

http://www.example.com/software
route:software

books library

http://www.example.com/books
route:books

and so on

let's begin

[First]
make forum in supdomain from cpanel
http://forum.example.com/
Document Root /public_html/forum

in config file insert this

PHP:
$config['cookie'] = array(
    'prefix' => 'example_',
    'path' => '/',
    'domain' => '.example.com'
);

done

[second]
edit file library/XenForo/router.php

after
PHP:
$routePath = $this->getRoutePath($request);

add this
PHP:
if(defined('MY_INDEX'))
        {
            $routePath = MY_INDEX . '/' . $routePath;
        }


[third]
created new folder called software in /public_html/software
from cpanel create subdomain for this folder

http://software.example.com/
Document Root /public_html/software

inside software folder create index.php with this content

PHP:
//path to xenforo index.php
$path = '/home/example/public_html/forum/index.php';
 
//constant we used it in listener
define('MY_INDEX', 'software');
include($path);

then copy your .htaccess to this folder

now when you open
http://software.example.com/
it will display http://forum.example.com/software but we get style (css & js ) not working because base dir

[fourth]
in PAGE_CONTAINER template change

HTML:
<base href="[COLOR=#ff0000]{$xenOptions.boardUrl}[/COLOR]" />
        <script><xen:comment>/* Chrome bug and for Google cache */</xen:comment>
            var _b = document.getElementsByTagName('base')[0], _bH = "{xen:jsescape [COLOR=#ff0000]{$xenOptions.boardUrl}[/COLOR]}";
            if (_b && _b.href != _bH) _b.href = _bH;
        </script>

and in boardUrl option put your new forum link
http://forum.example.com

or you can modify this from Listener Template by preg_replace in $contents
 
forget something important

your route software should be get link from your route in all time
from ACP edit your route prefix and make it

Use class to build link: Always

inside your router class Dev_Route_Prefix_Software
make all returned links from function match in full text
 
what if you don't need to change any thing inside router.php ?
there are long way to do that

let's begin

[First]

in you index.php inside folder software don't add old codes but add that code

PHP:
$startTime = microtime(true);
$fileDir = 'home/example/public_html/forum';
define('MY_INDEX', 'software');
 
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
 
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);
 
$fc = new XenForo_FrontController(new Dev_Dependencies_Public());
$fc->run();

which Dev here mean your add on folder
this code same inside xenforo index page with Dependencies_Public changed to get from our class

[second]
in your addon folder Dev
create Dependencies folder contain Public.php

with that code
PHP:
class Dev_Dependencies_Public extends XenForo_Dependencies_Public
{
    /**
    * Routes the request.
    *
    * @see Overwrite XenForo_Dependencies_Abstract::route()
    */
    public function route(Zend_Controller_Request_Http $request)
    {
        $router = new Dev_Router();
        $router->addRule(new XenForo_Route_ResponseSuffix(), 'ResponseSuffix')
              ->addRule(new XenForo_Route_Prefix('public'), 'Prefix');
 
        return $router->match($request);
    }
}

[Third]
inside Dev folder create Router.php file with that contents

PHP:
class Dev_Router extends XenForo_Router
{
    public function getRoutePath(Zend_Controller_Request_Http $request)
    {
        return MY_INDEX . '/' . parent::getRoutePath($request);
    }
}

i hope this lesson useful to you
 
you will get problem with js using this lesson
that's because xenforo using css in php file css.php
$.ajax can't get css from outside php files (if it text it will work)

so we can make css.php inside how ?

let's begin

[First]
copy contents for css.php inside forum to software and do this changes

PHP:
$startTime = microtime(true);
$fileDir = '/home/example/public_html/forum';
define('MY_INDEX', 'software');
 
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
 
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);
 
XenForo_CssOutput::run();

[Second]

in your class Dev_Dependencies_Public ( in post #4 here )
put this function

PHP:
public function createTemplateObject($templateName, array $params = array())
    {
 
        if ($params)
        {
            $params = XenForo_Application::mapMerge($this->_defaultTemplateParams, $params);
        }
        else
        {
            $params = $this->_defaultTemplateParams;
        }
       
        return new Dev_Template_Public($templateName, $params);
    }

[Third]

create Dev_Template_Public class ( dev/template/Public.php)
with this content

PHP:
class Dev_Template_Public extends XenForo_Template_Public
{
    public function getRequiredCssUrl(array $requirements)
    {
        $url = parent::getRequiredCssUrl($requirements);
 
        //option in you Dev addon contain full link in this example http://software.example.com
        $option = MY_INDEX . 'FullLink';
        $url = XenForo_Application::get('options')->$option . '/' . $url;
        return $url;
    }
}

now css will com from your sub domain link (http://software.example.com/css.php?bla)
and ajax will work successfully
 
Top Bottom