• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Latest posts on your website

or, maybe buildPublicLink:('full:threads

(haven't tested this, so it's only maybe:P )
 
buildPublicLink is meant for only internal xenforo links, not http:// powered ones.


// Remote Link?
$xenfans_pos = strpos($options->xenfans_extra_tabs_one_link, $xenfans_http);
if ($xenfans_pos !== false && $xenfans_pos === 0) { $xenfans_link = $options->xenfans_extra_tabs_one_link; } else { $xenfans_link = XenForo_Link::buildPublicLink($options->xenfans_extra_tabs_one_link); }

and then i use

'href' => $xenfans_link,

later on.
 
I've slightly modified script incorporating some fixes from respected members above:

PHP:
<?php
$forumUrl = '/forum/'; //Forum URL, must end with slash
$limit = 10; // Display this number of last posts
$forumDirectory = realpath(__DIR__.'/../'); // Full path to forum folder
if(!$forumDirectory) {
    die('$forumDirectory is incorrect!');
}

$startTime = microtime(true);

require($forumDirectory. '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($forumDirectory . '/library');

// Initializing application
XenForo_Application::initialize($forumDirectory . '/library', $forumDirectory);
XenForo_Application::set('page_start_time', $startTime);

// Loading dependencies
$xfDependencies = new XenForo_Dependencies_Public();
$xfDependencies->preLoadData();

// Initializing session
XenForo_Session::startPublicSession();

// Reading viewable nodes list
$nodeModel = XenForo_Model::create('XenForo_Model_Node');
$viewableNodes = $nodeModel->getViewableNodeList();
$nodeIds = array_keys($viewableNodes);
$nodeIdsList = implode($nodeIds, ',');

// Requesting last N viewable nodes
$sql_forum = "SELECT `title`, `thread_id`, `view_count`, `reply_count` FROM `xf_thread` WHERE `node_id` IN ($nodeIdsList) AND discussion_state='visible' ORDER BY `last_post_date` DESC LIMIT $limit";
$lastThreads = XenForo_Application::get('db')->fetchAll($sql_forum);

// Here you can insert the code you want

// Displaying content
foreach ($lastThreads as $thread) {
    // Constructing full path to threads
    $threadUrl = $threadUrl = $forumUrl. XenForo_Link::buildPublicLink('threads', $thread);

    // Trimming and escaping
    $threadTitle = XenForo_Template_Helper_Core::helperWordTrim($thread['title'], 50);

    //Displaying
    echo "<a href=\"$threadUrl\">$threadTitle</a> Просмотров: {$thread['view_count']}, Ответов: {$thread['reply_count']}<br /><br />";
}

My changes:
  • Removed GeekPoint_Symfony dependency
  • Name of variables changed and lowerCamelCase'd.
  • discussion_state is now in the query
  • Works in any folder
 
Is there any reason it would make the page I am putting it on go from this...
before.png


To this..

after.png



I just took a small section of the page for smaller pictures, but I think you get the idea. It removes all formatting and also seems to remove some text. Other people don't seem to have this problem so its me probably doing something stupid and I just don't realize it. Any help would be great, thanks :)
PHP:
<?php
//Forum URL, must end with slash
$forumUrl = 'http://forums.worldoftomorrow.net/';
 
// Display this number of last posts
$limit = 10;
 
// Full path to forum folder
$forumDirectory = realpath(__DIR__.'/forum');
 
if(!$forumDirectory) {
    die('$forumDirectory is incorrect!');
}
 
$startTime = microtime(true);
 
require($forumDirectory. '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($forumDirectory . '/library');
 
// Initializing application
XenForo_Application::initialize($forumDirectory . '/library', $forumDirectory);
XenForo_Application::set('page_start_time', $startTime);
 
// Loading dependencies
$xfDependencies = new XenForo_Dependencies_Public();
$xfDependencies->preLoadData();
 
// Initializing session
XenForo_Session::startPublicSession();
 
// Reading viewable nodes list
$nodeModel = XenForo_Model::create('XenForo_Model_Node');
$viewableNodes = $nodeModel->getViewableNodeList();
$nodeIds = array_keys($viewableNodes);
 
// Requesting last N viewable nodes
$sql_forum = "SELECT `title`, `thread_id`, `view_count`, `reply_count` FROM `xf_thread` WHERE `node_id` IN (5) AND discussion_state='visible' ORDER BY `last_post_date` DESC LIMIT $limit";
$lastThreads = XenForo_Application::get('db')->fetchAll($sql_forum);
 
// Here you can insert the code you want
 
// Displaying content
foreach ($lastThreads as $thread) {
    // Constructing full path to threads
    $threadUrl = $threadUrl = $forumUrl. XenForo_Link::buildPublicLink('threads', $thread);
 
    // Trimming and escaping
    $threadTitle = XenForo_Template_Helper_Core::helperWordTrim($thread['title'], 50);
 
    //Displaying
    print "<a href=\"$threadUrl\">$threadTitle</a> Views: {$thread['view_count']}, Replies: {$thread['reply_count']}<br /><br />";
}
 
Ok so I solved this mystery of mine. What is does it basicly shows all threads from a specific node and prints out the content example:

Test news - 12.02.12
Test message, with some bold text
By Fronix


$limit = How many threads to show
$node = from what forum node you want to get all the threads.

PHP:
    function get_news($limit, $node){
        $xfDependencies = new XenForo_Dependencies_Public();
        $xfDependencies->preLoadData();
        // Reading viewable nodes list
        $nodeModel = XenForo_Model::create('XenForo_Model_Node');
        $viewableNodes = $nodeModel->getViewableNodeList();
        $nodeIds = array_keys($viewableNodes);
        $nodeIdsList = implode($nodeIds, ',');
 
        // Requesting last N viewable nodes
        $sql_forum = "SELECT * FROM `xf_thread` WHERE `node_id` = $node AND discussion_state='visible' ORDER BY `last_post_date` DESC LIMIT $limit";
        $lastThreads = XenForo_Application::get('db')->fetchAll($sql_forum);
 
        // Here you can insert the code you want
 
        // Displaying content
        foreach ($lastThreads as $thread) {
            $postModel = XenForo_Model::create('XenForo_Model_Post');
            $post = $postModel->getPostById($thread['first_post_id']);
           
            $bbCodeParser = new XenForo_BbCode_Parser(new XenForo_BbCode_Formatter_Wysiwyg);
            $bbCodeOptions = array(
                'showSignature' => false,
                'states' => array(
                    'viewAttachments' => false
                )
            );
            $threadTitle = $thread['title'];
            $threadDate =  date("d.m.y", $thread['post_date']);
            $author = $thread['username'];
            $theadUrl = XenForo_Application::get('options')->boardUrl . '/' . XenForo_Link::buildPublicLink('threads', $thread);
            $message = XenForo_ViewPublic_Helper_Message::getBbCodeWrapper($post, $bbCodeParser, $bbCodeOptions);
       
        echo "
            <h1><a href=\"$theadUrl\">{$threadTitle} - {$threadDate}</a></h1>
            {$message}
            <small>By {$author}</small><br /><br />
            ";
        }
    }
 
Top Bottom