Welcome to Geeklog, Anonymous Tuesday, January 31 2023 @ 09:19 pm EST

Geeklog Forums

RSS outside of blocks


Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
It's easy in blocks, but what if I want RSS feeds as whole pages? If it's not possible via a story, then what about through PHP usage of Geeklog's own RSS functions through a staticpage?

I saw the solution offered here but I wondered if it can be done directly. Otherwise I'm stuck with the block since if I keep it hidden using permissions (direct or those of its topic), the solution does bypass it but the feed would't get updated.
 Quote

Status: offline

Euan

Forum User
Full Member
Registered: 04/22/02
Posts: 292
You could use this to create a feed in a page - and just subscribe to the local feed.

Euan.
-- Heather Engineering
-- No job too small
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Unlike the former solution, yours is direct (doesn't even rely on a portal block), which is great but isn't there a way to just use Geeklog's already existing RSS functions?

I've taken the middle ground - I updated the former solution to still be indirect but to be able to update the real portal block even when it's hidden.
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
The problem is the RSS stuff assumes it is writing the feed to the block table. You would have to refactor the COM_rdfImport function to two functions. One that gets the data and returns a string, and a second to fulfill the current functionality.

The RSS block stores the last retrieval in the content field. So if you use COM_formatBlock, you take advantage of the caching inherent in the block structure. You can use COM_formatBlock to display a disabled block so the block need not appear on the right or left even though it will sit in the block table.

You could break up COM_rdfImport (from 1.4.1.b2) like this entirely untested example:
Text Formatted Code

function COM_rdfFetch( $rdfurl, $maxheadlines = 0 )
{
    global $_CONF, $_TABLES, $LANG21;

    // Import the feed handling classes:
    require_once( $_CONF['path_system']
                  . '/classes/syndication/parserfactory.class.php' );
    require_once( $_CONF['path_system']
                  . '/classes/syndication/feedparserbase.class.php' );

    // Load the actual feed handlers:
    $factory = new FeedParserFactory( $_CONF['path_system']
                                      . '/classes/syndication/' );
    $factory->userAgent = 'GeekLog/' . VERSION;
    $feed = $factory->reader( $rdfurl, $_CONF['default_charset'] );

    // Aquire a reader:
    if( $feed )
    {
        /* We have located a reader, and populated it with the information from
         * the syndication file. Now we will sort out our display, and update
         * the block.
         */
        if( $maxheadlines == 0 )
        {
            if( !empty( $_CONF['syndication_max_headlines'] ))
            {
                $maxheadlines = $_CONF['syndication_max_headlines'];
            }
            else
            {
                $maxheadlines = count( $feed->articles );
            }
        }

        // format articles for display
        $readmax = min( $maxheadlines, count( $feed->articles ));
        for( $i = 0; $i < $readmax; $i++ )
        {
            if( empty( $feed->articles[$i]['title'] ))
            {
                $feed->articles[$i]['title'] = $LANG21[61];
            }

            $content = '<a href="' . $feed->articles[$i]['link'] . '">'
                     . $feed->articles[$i]['title'] . '</a>';
            $articles[] = $content;
        }

        // build a list
        $content = COM_makeList( $articles, 'list-feed' );
// this next line doesn't save correctly put backslashes where the #'s are
        $content = preg_replace( "/(#015#012)|(#015)|(#012)/", '', $content );
    }
    else
    {
        // failed to aquire info, 0 out the block and log an error
        COM_errorLog( "Unable to aquire feed reader for $rdfurl", 1 );
        COM_errorLog( $factory->errorStatus[0] . ' ' .
                      $factory->errorStatus[1] . ' ' .
                      $factory->errorStatus[2] );
        $content = $LANG21[4];
    }
    return $content;
}

function COM_rdfImport( $bid, $rdfurl, $maxheadlines = 0 )
{
    $update = date( 'Y-m-d H:i:s' );
    $content = COM_rdfFetch( $rdfurl, $maxheadlines );
// I'm sure this could be combined
    $result = DB_change( $_TABLES['blocks'], 'rdfupdated', $update,
                                                 'bid', $bid );
    $result = DB_change( $_TABLES['blocks'], 'content',
                             addslashes( $content ), 'bid', $bid );
}
 

 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Well, while you hacked Geeklog, as I said I've updated Ivy's solution and added support for hidden (by being disabled) portal blocks

My solution requires neither hacking to any file nor adding any new files. You just create your portal block, hide/disable it if you don't want your visitors to see a double feed, and use my PHP code in a staticpage.
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
You were complaining about there not being a built in way. I know you can just call COM_formatBlock and it will work. Originally I was just going to ask why not call COM_formatBlock. This way eliminates the dead block in your blocks page (which you don't have to explain to a block.admin not to touch) and it makes it possible for plugin writers to call COM_rdfFetch without the overhead of a block.

Will it make it into future geeklog code? I guess I should make a feature request to push the process along.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Accidental post. Please delete.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
If it was as easy as simply calling COM_formatBlock, it would have spared me a lot of time. See the solution I wrote and you'd understand. I did all sorts of tricks to make COM_formatBlock work without hacking it and without it loading unneeded stuff.

But I see your point. The paradox with your solution is that it would be great once being an official part of Geeklog. Until then, I rather choose the hack free route (even though that you're right that it takes to create a block and a staticpage for each feed. I still think it's better - especially since how many feeds does one need anyway? - than hacking files - for each and every upgrade that comes out - especially if one has multiple sites).
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
Yeah, the $_USER['noboxes'] thing is annoying.

I put in the feature request and referred it back to this thread. The only problem with my solution is the return has to be cached or else every hit to the staticpage is a hit to the remote website's RSS feed.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Yeah, the $_USER['noboxes'] thing is annoying.

But as you saw, not that hard to bypass even though it could be much easier if COM_formatBlock just respected and used $noboxes directly.
I've reported it as a bug.

I put in the feature request and referred it back to this thread.

Give yourself enough respect to put it as a patch instead. In my eyes, a patch is a bug report/feature request with a detailed fix and not just a "please add/fix this!" comment.

The only problem with my solution is the return has to be cached

The portal block caches too. By definition caching has to be involved if you don't euexpect to re-download the RSS each time.
BTW, where are the last update and the content cached if it's a standalone staticpage?
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Yeah, the $_USER['noboxes'] thing is annoying.

But as you saw, not that hard to bypass even though it could be much easier if COM_formatBlock just respected and used $noboxes directly.
I've reported it as a bug.

I put in the feature request and referred it back to this thread.

Give yourself enough respect to put it as a patch instead. In my eyes, a patch is a bug report/feature request with a detailed fix and not just a "please add/fix this!" comment.

Also, for next time know there's no need to hardcode the forum's ID in the topic's link. Each topic (not to mention post. A "topic's ID" is just the original post's ID) has a unique ID of its own.

The only problem with my solution is the return has to be cached

The portal block caches too. By definition caching has to be involved if you don't expect to re-download the RSS each time.
BTW, in your solution where are the last update and the content cached if it's a standalone staticpage?
 Quote

Status: offline

THEMike

Forum User
Moderator
Registered: 07/25/03
Posts: 141
Location:Sheffield, UK
If you want an RSS feed in a page, this can easily be done with a PHP static page directly using the feed handling classes. The only problem with that approach is that you'd need to fetch the feed on every load. Working round by storing the content in a block is ok I guess, but, really if you want a feed display thing, the correct approach would be a simple plugin with it's own table to cache parsed feeds or their components. Should be pretty simple to write.
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
Quote by: THEMike

If you want an RSS feed in a page, this can easily be done with a PHP static page directly using the feed handling classes. The only problem with that approach is that you'd need to fetch the feed on every load. Working round by storing the content in a block is ok I guess, but, really if you want a feed display thing, the correct approach would be a simple plugin with it's own table to cache parsed feeds or their components. Should be pretty simple to write.

No, a real solution is to decouple RSS feeds from the Block mechanism or to enable blocks on static pages. Having two places to store RSS feeds makes no sense.
 Quote

Status: offline

THEMike

Forum User
Moderator
Registered: 07/25/03
Posts: 141
Location:Sheffield, UK
Geeklog only provides a very basic inbound syndication option with it's rich syndication API. There is no customisation on the format of what's displayed, and it's just portal blocks.

What you are suggesting would require storing the formatted content of a feed when loaded outside the block table, and then some kind of configuration of how the text is formatted up etc.

This would just provide a few basic options, and people would be bound to want to extend this behaviour to do more.

Inline with Geeklog's plugin architecture and the fact that most features that were in core have now been spun off into plugins, which may be moved out of the "core", any changes ought to be implemented as a plugin.

It would be quite simple to hook up to the classes available, stick the content of the feeds some where appropriate (perhaps in a table on a post-by post basis) and provide really nice blocks and pages etc with security on access and merging articles from multiple feeds and so on...
 Quote

All times are EST. The time is now 09:19 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content