Scoop -- the swiss army chainsaw of content management
Front Page Everything News Code Help! Wishlist Project Scoop Sites Dev Notes Latest CVS changes Development Activities
Scoop Box Exchange - Show Box: rss_export 1.03

Author: coryking [Info]

Description:

RSS Feed for a user

Box Code:

# ------------------------------------------------------------------------------
# Per-User RSS Feed - Scoop Box
# ------------------------------------------------------------------------------
# Copyright (c) 2006, Cory R. King
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without
# limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
#
# ------------------------------------------------------------------------------
# Installation:
# 1) Name this box "rss_export"
# 2) Execute the following SQL statement to install:
#
# INSERT INTO `ops` VALUES ('rss','content_only_page_template','rss_export',1,1,'','feeds','/nickname','');
#
# ------------------------------------------------------------------------------
# Use:
# Link to the feed as such:
# http://www.sitename.com/rss/<username>
#
# ------------------------------------------------------------------------------
# Todo:
#
# - Send proper HTTP headers including the correct mime type
# - Include a plaintext, trimmed description for each story
# - Use $S->get_stories() instead of writing our own query
# - Add date to each story
# - Inject a <link> tag when visiting a user profile so
# IE7, Firefox & Safari know about this feed
# - Get fancy and maybe expand into section feeds and tag feeds
#
# ------------------------------------------------------------------------------
# Tested on Scoop 1.1.8, Released November 28, 2006.
#
use XML::RSS;

my $nick = $S->{DBH}->quote( $S->{CGI}->param('nickname') );

# this checks that the nick is valid
# and gets the UID...
my ($rv, $sth) = $S->db_select({
WHAT=>'nickname, uid',
FROM=>'users',
WHERE=>"nickname=$nick"});

my $user = $sth->fetchrow_hashref();

return "" unless($$user{uid});

# 2.0 is awesome too ya know!
my $rss = new XML::RSS (version => '1.0');

# modify for your own site.
$rss->channel(
title => $S->{UI}->{VARS}->{sitename}.": $$user{nickname}",
link => $S->{UI}->{VARS}->{site_url}."/user/$$user{nickname}",
description => "$$user{nickname}'s last 10 stories",
);

# if you so desired, you could limit this down to just diaries or something...
($rv, $sth) = $S->db_select({
WHAT=>'sid, title',
FROM=>'stories',
WHERE=>"aid=$$user{uid}",
ORDER_BY=>'time DESC',
LIMIT=>'10'
});

while( my $story=$sth->fetchrow_hashref() ) {

$rss->add_item(
title=>$$story{title},
link=>$S->{UI}->{VARS}->{site_url}."/story/$$story{sid}"
);
}

return $rss->as_string();
Display: Sort:
Errr (none / 0) (#1)
by coryking on Tue Nov 28, 2006 at 07:58:15 PM PST

Hmmmm.... Linebreaks are screwy. I'm gonna try one more time here.

--
Cory R. King
xlan.org (scoop hosting)
photographica (pictures)



  • okay by coryking, 11/28/2006 07:59:53 PM PST (none / 0)
Menu
create account
faq
search
report bugs
Scoop Administrators Guide
Scoop Box Exchange

Scoop Site Scroller: Get one yourself!
Smokedot
It's 4:19... do you know where your bong is?

Login
Make a new account
Username:
Password:

Hosted by ScoopHost.com Powered by Scoop
All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest 1999 The Management

create account | faq | search