XF 2.0 Is it possible to make own pages (PHP) with XenForo2?

Anhava

Member
Hello,

I would like to make statistics page (no XF-related) for XenForo using GET API functions? I'm pretty sure it's possible but can someone explain me how? Spent couple hours searching that and didnt find anything. In XF2 is possible to make Pages like portals etc. but how I can make page using php, python or curl?

It's long time when I last made forums or websites and it have been changed alot. I have one script which is statitic and made with AngularJS. Is there anyway to put those Controllers to XF (I have ToolsController file?

PHP:
   /**
    * Katsotaan Bitcoin-osoitteen saldo (checking balance for btc address) (btc-osoite)
    **/
    public function testiAddrVerifyCheckVerify()
    {
        $address = Request::get('address');
        try{
        $url = file_get_contents('https://blockchain.info/address/'.$address.'?limit=0&format=json');
        $data = json_decode($url, true);
         if(isset($data['address'])){
            $balance = $data['final_balance'] / 100000000;
            Flashy::message('Balanssi : '.$balance);
         }
         else {
            Flashy::error('This is a not valid input');
         }
        }
        catch(\Exception $e){
                        Flashy::error('This is a not valid input');
        }
        return redirect('tools/balance');
    }
That is from script what I'm meaning. Can I add required Tools Controllers and use those codes in XF2? XF does not include flashy but that's just for inform user success/error logs.

Should I keep learning more XF Docs or is this even close how it should be? :D

Redirect should change etc. to correct ones ofc, but how I can make page(s) for this kind of stuff?
 

LPH

Well-known member
The answer is yes. It’s very possible to connect PHP pages and XenForo 2. The key to bridging is to build a connector file then work from there.

In XF2, three lines are required. Create a file named connectXenForo2.php and add the following contents.

PHP:
<?php

/** @var  $fileDir */
$fileDir = '/Absolute/Path/To/xf2';

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

XF::start($fileDir);
Now create a file named user.php

PHP:
<?php

require_once '../connectXenForo2.php';
require_once '../connectDump.php';

$finder = \XF::finder('XF:User');
$user = $finder->where('user_id', 1)->fetchOne();

dd($user);
And the array is returned. BEAUTIFUL.

PS. My connectDump.php

PHP:
<?php

/**
* Filename: connectDump.php
*
* Return information about a variable.
* Include this file to the top of phptest files.
*
* Usage: dd($nameOfVariable);
*/

function dd($variable) {

if ( is_array( $variable ) ) {

echo '<pre>';
print_r($variable);
echo '</pre>';

return true;
}

return var_dump($variable);
}
Maybe this should be cleaned up and written up as a tutorial — @Chris D @Mike
 
Top