• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
  • 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.

Global RSS Feed

Status
Not open for further replies.

Member 3639

Active member
#1
Well i needed one and to stop people badgering the staff to make one (seriously) i am deciding to share mine plus a few edits to make it easier for general use (mine has a few different bits to it).

You will need this brilliant helper class by Shadab https://gist.github.com/722240
Simply download it and upload the file to "/library/GeekPoint/Symfony.php" (you will need to make the directory GeekPoint).

Put this code at the very top of the file
PHP:
<?php
// global rss feed v0.2 by liamdawe

$startTime = microtime(true);

// edit this to the directory your forum is in
$forum_directory = '/home/website/forum/';

// edit this to whatever folder your forum is in
$forum_url = 'http://www.website.com/chill/';

// edit to this feeds filename
$feed_address = 'forum_rss.php';

// change to the amount of posts you want displayed
$limit = 7;

// the title of your feed
$feed_title = 'Global RSS Feed by Liam Dawe';

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

GeekPoint_Symfony::initializeXenforo($forum_directory, $startTime);

$nodeModel = XenForo_Model::create('XenForo_Model_Node');
$nodes = $nodeModel->getViewableNodeList();

$nodes_get = array_keys($nodes);

$node_id_list = implode($nodes_get, ',');


// get the config info
include($forum_directory . 'library/config.php');

mysql_connect($config['db']['host'], $config['db']['username'], $config['db']['password']);
mysql_select_db($config['db']['dbname']);

$sql = "SELECT * FROM `xf_thread` WHERE `node_id` IN ($node_id_list) ORDER BY `last_post_date` DESC LIMIT {$limit}";
$query = mysql_query($sql);

while ($line = mysql_fetch_assoc($query))
{
    $return[] = $line;
}

$now = date("D, d M Y H:i:s O");

$output = "<?xml version=\"1.0\"?>
<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">
    <channel>
        <title>{$feed_title}</title>
        <link>{$forum_url}{$feed_address}</link>
        <atom:link href=\"{$forum_url}{$feed_address}\" rel=\"self\" type=\"application/rss+xml\" />
        <language>en-us</language>
        <description></description>
        <pubDate>$now</pubDate>
        <lastBuildDate>$now</lastBuildDate>";

foreach ($return as $line)
{
    $date = date("D, d M Y H:i:s O", $line['last_post_date']);

    // remove random characters from the url
    $url_title = str_replace(' ', '-', $line['title']);
    $url_title = str_replace('.', '', $url_title);
    $url_title = str_replace('?', '', $url_title);
    $url_title = str_replace('/', '-', $url_title);
    $url_title = str_replace('\\', '-', $url_title);
    $url_title = str_replace('"', '', $url_title);

    $url = "{$forum_url}index.php?threads/{$url_title}.{$line['thread_id']}/";

    $output .= "
        <item>
            <title>{$line['title']}</title>
            <link>{$url}</link>
            <pubDate>{$date}</pubDate>
            <guid>{$url}</guid>
        </item>";
}

$output .= "
    </channel>
</rss>";

header("Content-Type: application/rss+xml");
echo $output;
?>
Updates:
06/12/2010 - It now takes into account what forums the visitor is allowed to view.

Demo from my board (not using that exact code but does the same job): http://www.gamingonlinux.info/forum_rss.php
 

Attachments

R

ragtek

Guest
#4
Of corse.
PHP:
// TODO make this optional, so we can output rss, xml,...
        $this->_routeMatch->setResponseType('rss');
        $threadModel = $this->_getThreadModel();
        $searchModel = $this->_getSearchModel();

        $fetchOptions = array(
                            'order' => 'last_post_date',
                            'orderDirection' => 'desc',
                            'limit' => 50
		);

        $threadKeys = array_keys($threadModel->getThreads(
        	array(
            	'deleted' => false,
            	'moderated' => false
            ), $fetchOptions
        ));
        $results = array();
        foreach ($threadKeys AS $threadId){
        	$results[] = array('content_type' => 'thread', 'content_id' => $threadId);
        }

        $results = $searchModel->getViewableSearchResults($results);
        $results = $searchModel->getSearchResultsForDisplay($results);
But that's IMHO extremly ugly and unnecessery (reads ALL and sort them out... :( )

I hope that i can find i better way
started also thread because of this: http://xenforo.com/community/threads/node-permissions-of-current-user.8875/
 
Status
Not open for further replies.