[dw-free] Fix OPML generation
[commit: http://hg.dwscoalition.org/dw-free/rev/5f59b806fd7a]
http://bugs.dwscoalition.org/show_bug.cgi?id=547
Spiff up the OPML output, giving users more options about what kind of file
to generate.
Patch by
foxfirefey.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=547
Spiff up the OPML output, giving users more options about what kind of file
to generate.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- htdocs/tools/opml.bml
-------------------------------------------------------------------------------- diff -r db130a259900 -r 5f59b806fd7a htdocs/tools/opml.bml --- a/htdocs/tools/opml.bml Sun May 17 15:18:06 2009 +0800 +++ b/htdocs/tools/opml.bml Sun May 17 07:32:24 2009 +0000 @@ -1,46 +1,94 @@ <?_code { use strict; - BML::decl_params(user => qr/^\w{1,15}$/); my $remote = LJ::get_remote(); - if ($remote && $GET{'user'} eq "") { - return BML::redirect("$LJ::SITEROOT/tools/opml.bml?user=$remote->{user}"); + + # if we don't have a current user but somebody is logged in, redirect + # them to their own OPML page + if ( $remote && $GET{user} eq "" ) { + return BML::redirect( "$LJ::SITEROOT/tools/opml.bml?user=$remote->{user}" ); } - return "No 'user' argument" unless $GET{'user'}; + return "No 'user' argument" unless $GET{user}; - my $u = LJ::load_user($GET{'user'}) + my $u = LJ::load_user_or_identity( $GET{user} ) or return "Invalid user."; - BML::set_content_type("text/plain"); + my @uids; + + # different accounts need different userid loads + # will use watched accounts for personal accounts + # and identity accounts + # and members for communities + if( $u->is_person || $u->is_identity ) { + @uids = $u->watched_userids; + } elsif( $u->is_community ) { + @uids = $u->member_userids; + } else { + return "Invalid account type."; + } + + my $us = LJ::load_userids( @uids ); + + BML::set_content_type( "text/plain" ); my $x = "<?" . "xml version='1.0'?> <opml version='1.1'><head> "; my $add = sub { - my ($e, $v) = @_; + my ( $e, $v ) = @_; return unless $v; $x .= "<$e>" . LJ::exml($v) . "</$e>\n"; }; - $add->("title", "$u->{user}'s $LJ::SITENAME reading list"); - $add->("ownerName", $u->{name}); - $add->("ownerEmail", $u->email_visible($remote)); + $add->( "title", "$u->{user}'s $LJ::SITENAME reading list" ); + $add->( "ownerName", $u->{name} ); + $add->( "ownerEmail", $u->email_visible( $remote ) ); $x .= "</head><body>\n"; - my $frs = LJ::get_friends($u); - my @uids = keys %$frs; - my $us = LJ::load_userids(@uids); - foreach my $uid (sort { $a <=> $b } @uids) { - my $fr = $us->{$uid} or next; - my $title = $fr->{name}; - $x .= "<outline text=\"" . LJ::exml($title) . "\" xmlURL=\"" . LJ::exml($fr->journal_base . "/data/rss") . "\" />\n"; + # currently ordered by user ID; there might be a better way to order this + # but unless somebody has a strong preference about it there's no point + foreach my $uid ( sort { $a <=> $b } @uids ) { + my $w = $us->{$uid} or next; + + # identity accounts do not have feeds + next if $w->is_identity; + # if we only want to show personal accounts + next if $GET{show} eq 'P' and $w->is_community; + # if we only want to show communities + next if $GET{show} eq 'C' and $w->is_person; + + my $title; + + # use the username + site abbreviation for each feed's title if we have that + # option set + if( $GET{title} eq "username" ) { + $title = $w->display_username . " (" . $LJ::SITENAMEABBREV . ")"; + } else { + # FIXXME: Should be using a function call instead! But $w->prop( "journaltitle" ) + # returns empty here, though it's used in userinfo.bml + $title = $w->{name}; + } + + my $feed = $w->journal_base; + + if( $GET{feed} eq "atom" ) { + $feed .= "/data/atom"; + } else { + $feed .= "/data/rss"; + } + + if( $GET{auth} eq "digest" ) { + $feed .= "?auth=digest"; + } + + $x .= "<outline text=\"" . LJ::exml($title) . "\" xmlURL=\"" . LJ::exml($feed) . "\" />\n"; } + $x .= "</body></opml>\n"; BML::noparse(); return $x; - } _code?> --------------------------------------------------------------------------------