XF 2.0 PHP Include?

mneylon

Member
I'm trying to integrate Blockscript with a Xenforo install.
The basic integration is via a PHP include:
Code:
include_once("./full-path-to/blockscript/detector.php");
This would need to be in the header of every page
What's the simplest way to do this??
 
On vBulletin you just included the PHP file in the main hook and it worked without issue:

vbulletin init_startup hook:
Code:
if (file_exists(CWD.'/blockscript/detector.php'))
{
    include_once(CWD.'/blockscript/detector.php');
}

But on Xenforo it appears to be more complicated.

In some situations it works fine, here is an example of an extension that will work for executing Blockscript whenever someone tries to use the ContactUs Form, this works without error:

PHP:
<?php

namespace XenBulletin\Blockscript\Pub\Controller;

use XenBulletin\Blockscript\Helper;

class Misc extends XFCP_Misc
{
    public function actionContact()
    {
        require("./full-path-to/blockscript/detector.php");
        return parent::actionContact();
    }
}

But doing it in a controller_pre_dispatch listener does not work, it will just give 5xx error. Doing it in most actionIndex() extensions will also result in an error.

If anyone has any suggestions, that would be appreciated.
 
Well ... what does detector.php do?

ini_startup on vBulletin was pretty early in the bootstrap process, so app_pub_setup might be a good choice?
 
@AddonFlare helped me solve this issue, got it working on all requests now

if you want to integrate BlockScript just install it and then edit Xenforo's index.php:

PHP:
<?php

$phpVersion = phpversion();
if (version_compare($phpVersion, '7.0.0', '<'))
{
    die("PHP 7.0.0 or newer is required. $phpVersion does not meet this requirement. Please ask your host to upgrade PHP.");
}

$dir = __DIR__;

// works perfect here

if (file_exists($dir . '/blockscript/detector.php'))
{
    include_once($dir . '/blockscript/detector.php');
}

//^^ works perfect here


require($dir . '/src/XF.php');

XF::start($dir);

if (\XF::requestUrlMatchesApi())
{
    \XF::runApp('XF\Api\App');
}
else
{
    \XF::runApp('XF\Pub\App');
}

Use absolute path if you have a different path

To confirm it's working, fire up a VPN or Opera Proxy and then check the blockscript logs and see if it worked

Xenforo probably doesn't recommend editing index.php so your mileage may vary and you may need to re-add it after updates
 
Top Bottom