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

Discussion in 'Development Tutorials [Archive]' started by Member 3639, Dec 5, 2010.

Thread Status:
Not open for further replies.
  1. Member 3639

    Member 3639 Active Member

    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
    // 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';

    XenForo_Autoloader::getInstance()->setupAutoloader($forum_directory '/library');


    $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']);

    $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\">
            <atom:link href=\"
    {$forum_url}{$feed_address}\" rel=\"self\" type=\"application/rss+xml\" />

    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 .= "

    $output .= "

    header("Content-Type: application/rss+xml");
    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

    Attached Files:

    Brian Chance likes this.
  2. ragtek

    ragtek Guest

  3. Member 3639

    Member 3639 Active Member

    Care to share how you checked what nodes the current visiting person is allowed to view?
  4. ragtek

    ragtek Guest

    Of corse.
    // TODO make this optional, so we can output rss, xml,...
    $threadModel $this->_getThreadModel();
    $searchModel $this->_getSearchModel();

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

    $threadKeys array_keys($threadModel->getThreads(
    '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/
  5. Member 3639

    Member 3639 Active Member

    Added permissions support.
  6. John L.

    John L. Well-Known Member

    Hey this is cool, but what if you're using the SEO friendly URLs?
  7. ragtek

    ragtek Guest

  8. Member 3639

    Member 3639 Active Member

    Just a request can this thread be locked, i no longer support it, i would suggest using regteks work :)
  9. Brogan

    Brogan XenForo Moderator Staff Member

    Closed as requested.
Thread Status:
Not open for further replies.

Share This Page