Resource icon

XenForo Connector 1.0

No permission to download
um, im a little unclear what this addon is supposed to do. what data does it pull into your website from the message board?
 
I'm trying to use this to pull some posts. I've got all the post data, but cant seem to run the parser on it, I just get the message with its BBCode tags - how would I go about converting it to HTML using XenForo's parser?

Thanks :)
 
Here is a demo for a post array and how I use it; there are other formatters and options available, you will have to dive a bit in the code :)
PHP:
$bbCodeParser = new XenForo_BbCode_Parser(new XenForo_BbCode_Formatter_Base());
 
$bbCodeOptions = array(
  'noFollow' => true,
  'showSignature' => false,
  'states' => array(
    'viewAttachments' => false
  )
);
 
echo XenForo_ViewPublic_Helper_Message::getBbCodeWrapper($post, $bbCodeParser, $bbCodeOptions);
 
Is there a sample to pull off the "X" most recent posts from "Y" forums and then display them in a plain (external to XF) PHP page on the same site? Dynamically, of course, and with links to the posts....
(my posts are visible to guests, so that part is not a problem).
 
Is there a sample to pull off the "X" most recent posts from "Y" forums and then display them in a plain (external to XF) PHP page on the same site? Dynamically, of course, and with links to the posts....
(my posts are visible to guests, so that part is not a problem).

Here's some code I use to do just that on a PyroCMS widget. Basically where I've got $options['xfexclude'] that contains a list of forums ids to exclude, and then obviously $options['xflimit'] is the number of results to return. In my code I've got it returning the query results into an array as this then goes off to my view file, however the function should give you the basic structure for a basic non-xf php page.

PHP:
    public function run($options)
    {
        $excludeForums = array();
        if(!isset($options['xflimit']) || $options['xflimit'] < 1)
        {
            $options['xflimit'] = 10;
        }
     
        if(!empty($options['xfexclude']))
        {
            if(strstr($options['xfexclude'], ','))
            {
                $excludeForums = explode(',', $options['xfexclude']);
            }
            else
            {
                $excludeForums[] = $options['xfexclude'];
            }
        }
 
        $threadModel = XenForo_Model::create('XenForo_Model_Thread');
        $sql = 'SELECT thread.* FROM xf_thread AS thread WHERE node_id NOT IN("'.$options['xfexclude'].'") ORDER BY last_post_date DESC LIMIT '.$options['xflimit'].'';
     
        $where = "NOT IN('".$options['xfexclude']."')";
        $query = $this->db->query($sql);
        $result = $query->result();
        return array('threads' => $result);
    }

If you take a look at the link in my signature, on the homepage near the bottom you'll see it using the data from the above function in a 'widget' box showing the latest threads.
 
Thanks for that!
I see what you are doing, but my coding is pretty rusty - I'll fiddle with it when I have a chance. As mentioned, I just want to insert it in a stand alone php page. I assume I will make another php page to fiddle with this and then include that one in the home page...or something like that.
 
For the sake of example, here's how I do it:

PHP:
$nodeModel = XenForo_Model::create('XenForo_Model_Node'); // Retrieve the default viewable forums
$nodes = $nodeModel->getViewableNodeList();
 
unset($nodes[X], $nodes[Y]); // X, Y are the IDs of publicly viewable forums but I don't want to retrieve threads from them
 
$latestthreads = array();
 
// Here I use XF's own $db connector (Zend_Db), but you can do it another away
$db = XenForo_Application::getDb();
 
$threads = $db->query("
    SELECT thread_id, title, reply_count, post_date
    FROM xf_thread
    WHERE node_id IN (" . implode(',',  array_keys($nodes)) . ")
        AND discussion_state = 'visible'
        AND discussion_open = 1
        AND sticky = 0
    ORDER BY post_date DESC
    LIMIT 10
");
 
while ($thread = $threads->fetch())
{
    $latestthreads[$thread['thread_id']] = array(
        'id' => $thread['thread_id'],
        'title' => $thread['title'],
        'url' => XenForo_Link::buildPublicLink('canonical:threads', $thread),
        'replycount' => $thread['reply_count'],
        'dateline' => $thread['post_date']
    );
}
 
// $latestthreads contains all your threads data
 
Thanks...the only question I have is whether these template examples need to be created where they "know" XF is there - for instance, inside the XF system.

That is, are the references to XF in the code just created php objects, and if not, how do they know XF is even there?
(XenForo_Model, etc.)
 
Thanks...the only question I have is whether these template examples need to be created where they "know" XF is there - for instance, inside the XF system.

That is, are the references to XF in the code just created php objects, and if not, how do they know XF is even there?
(XenForo_Model, etc.)
That's what the connector is for :)
 
Dang, I am rusty.....can't get it to work....

Firstly, is the path to XF setting in the connector from the web root or server root? In other words, if my XF main directory is /talk , is that all I need there? Or do I point deeper into XF or from the server root?

Secondly, is there any easy way of testing to see if the connector works? Just a one or two line php to include it and return that everything is found and connected?

I tried putting the connector in a php file and then including it in another php file using the above code examples (tried each separately) and got no results (redirect or empty screen).
 
Firstly, is the path to XF setting in the connector from the web root or server root? In other words, if my XF main directory is /talk , is that all I need there? Or do I point deeper into XF or from the server root?
When you define XF_ROOT, the path should be from the server root. You can use dirname(__FILE__) or __DIR__ to set the path from the current file. Be careful, don't include any trailing slash.
Secondly, is there any easy way of testing to see if the connector works? Just a one or two line php to include it and return that everything is found and connected?
I guess you can try var_dump($visitor).
 
Okay I don't know whether I am stupid or not really understanding this.

Where abouts do we put the connector code - do we make a new php file and include it somewhere?
All I am attempting to do is like many others get the last couple of forum posts and display them on the front page of my php coded website.
 
Top Bottom