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

Xenforo BB Parser on PHP Page (Tags and Smilies URL Issue)

Cooper

Active member
#1
I'm using the xenforo BB parser on a page outside the forum - it works well for the most part, but struggles with tags and smilies.

The issue seems to be the URL; I've tried a chdir in my PHP to no avail.

Example: http://irdriver.com/news/irdriver-scoop-new-alfajeep-test-mule-spotter.561

upload_2013-10-25_10-37-43.png

HTML:
<a href="http://irdriver.com/news/members/4/" class="username" data-user="4, Darragh">Darragh</a>
Shows /news directory instead of /forum so the link is broken

HTML:
<imgsrc="styles/default/xenforo/clear.png" class="mceSmilieSprite mceSmilie1" alt=":)" title="Smile :)"/>
As the current directory isn't 'forum' this doesn't show (I realise I may have other issues with the sprite class but can sort that).

Any help on getting into the right directory (as chdir doesn't seem to play ball) would be greatly appreciated.

Thanks
Andrew.
 

Cooper

Active member
#5
This is my code to talk to xenforo (originally came from here, works fine):

PHP:
$startTime = microtime(true);
$fileDir = '/domain.com/forum';

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);

$dependencies = new XenForo_Dependencies_Public();
$dependencies->preLoadData();

XenForo_Session::startPublicSession();

$visitor = XenForo_Visitor::getInstance();

$userid = $visitor->getUserId();
$username = $visitor->get('username');
$isadminuser = $visitor->get('is_admin');
$isbanneduser = $visitor->get('is_banned');
$useremail = $visitor->get('email');
$usergroup = $visitor->get('secondary_group_ids');
if(strstr($usergroup,"6")) {$canpublish=true;}  else {$canpublish=false;}
//error_reporting(0);

//parse bb code
$formatter = XenForo_BbCode_Formatter_Base::create();
$parser = new XenForo_BbCode_Parser($formatter);
Edited out path for security but it is the absolute path to my forum directory

This is the script that shows the post text:

PHP:
        if(!$replies = $mysqli->query("SELECT * FROM xf_post,xf_user WHERE xf_post.user_id=xf_user.user_id AND thread_id='$threadid' AND position<>'0' AND message_state='visible' ORDER BY post_date LIMIT 10"))
        {
            die('There was an error running the query [' . $db->error . ']');
        }
       
        while($post=$replies->fetch_assoc())
        {
            echo"<div class='postinfo'>
                <div class='postavatar'>";
           
            if(strlen($post['avatar_date'])>2){
            echo"
            <img src='http://irdriver.com/forum/data/avatars/s/0/" . $post['user_id'] . ".jpg?" . $post['avatar_date'] . "'>
            ";
            }
            echo"</div>
            ";
            echo"
            <div class='postby'><a href='../forum/members/" . $post['user_id'] . "'>" . $post['username'] . "</a> " . date("H:i | d M, Y ",$post['post_date']) . "</div>";
           
                //use xenforo parser
            $post_text = $parser->render($post['message']);
           
            echo"
            <div class='post'>$post_text</div>
            </div>
            ";
        }

As mentioned in my first post, when the parser does this: $parser->render($post['message']); it prints the wrong directory for the smilies etc (it drops /forum).

Any thoughts/tips appreciated. Tried chdir to no avail