Anyone here good at coding Xenforo Hooks and stuff?

kbarg

New Member
Customer
Messages
5
I have an old Xenforo 1.5 script that displays the posts from a certain forum to, appear on my main websites index page as essientially site news.

I was curious if anyone would be willing to help me update my script so I can upgrade that forum to XF 2.1 and then buy a new Xenfocus theme for it :)

@Ehren I am not trying to violate any of your rules so please tell me if I am.

PHP:
<?php


// set forum path
$fileDir = '/home/example/public_html/forums';

// set webRoot
$webRoot = 'http://www.example.com/forums/';

// include forum ID here
$includeForum = '2';

// set number of rows to display
$limit = 5;

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
XenForo_Application::initialize($fileDir . '/library', $fileDir);

//########################################
// start recent posts
//########################################

// get database
$db = XenForo_Application::get('db');

// run query
$recentPosts = $db->fetchAll("
SELECT xf_thread.thread_id,
xf_thread.title,
xf_thread.post_date,
xf_node.node_id,
xf_node.title AS nodeTitle,
xf_post.message,
xf_user.avatar_date,
xf_user.user_id,
xf_user.username,
xf_user.avatar_date,
xf_user.gravatar
FROM xf_thread
INNER JOIN xf_node ON xf_node.node_id = xf_thread.node_id
INNER JOIN xf_user ON xf_user.user_id = xf_thread.user_id
INNER JOIN xf_post ON xf_post.post_id = xf_thread.first_post_id
WHERE xf_thread.discussion_type <> 'redirect'
AND xf_node.node_id = " . $includeForum . "
ORDER BY xf_thread.first_post_id DESC
LIMIT " . $limit . "
");

// declare variables
$recentPostsNew = array();
$i = 0;

// add to multidimensional array
foreach ($recentPosts as $k => $v)
{
    // prepare array
    $forumArray = array('forum' => array(
        'node_id' => $v['node_id'],
        'title' => $v['nodeTitle']
    ));

    // prepare array
    $userArray = array('user' => array(
        'user_id' => $v['user_id'],
        'username' => $v['username'],
        'avatar_date' => $v['avatar_date'],
        'gravatar' => $v['gravatar']
    ));

    // merge arrays
    $recentPostsNew[] = array_merge($recentPosts[$i], $forumArray, $userArray);

    $i = $i + 1;
}

// rename variable
$recentPosts = $recentPostsNew;
$html = "";

foreach ($recentPosts AS $thread)
{
    $html = $html . '<div class="column" style="width:400px;"><div class="large">' . PHP_EOL;

     $threadUrl = XenForo_Link::buildPublicLink('canonical:threads', $thread);

    // display thread title
    $html = $html . $thread['title'] . PHP_EOL;
    $html = $html . '</div>' . PHP_EOL;


    $username = XenForo_Link::buildPublicLink('canonical:username', $thread['user']);
    // display username
    $html = $html . '<div class="column_subheader">' . PHP_EOL;
    $html = $html . $formattedDate = date("F d, Y", $thread['post_date']) . ' | '  . 'Posted by ' . $thread['username'] . PHP_EOL;
    $html = $html . '</div>' . PHP_EOL;

    $html = $html . '<div class="dark">' . PHP_EOL;
    $html = $html . str_replace ([ '[parsehtml]' , '[/parsehtml]'], '' , $thread['message']) . PHP_EOL;
    $html = $html . '</div>' . PHP_EOL;


    $html = $html . '<div class="seperator"></div>' . PHP_EOL;
       $html = $html . '</div>' . PHP_EOL;

}


echo $html;

?>
 
Top