Skip to content

Commit

Permalink
ui: /directory.opml
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Jun 9, 2012
1 parent 6ca0cd4 commit e71f726
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/ui/include/ui.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
-define(MIME_RSS, <<"application/rss+xml">>).
-define(MIME_ATOM, <<"application/atom+xml">>).
-define(MIME_JSON, <<"application/json">>).

-define(MIME_OPML, <<"text/x-opml">>).
8 changes: 8 additions & 0 deletions apps/ui/src/ui_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ handle_request2(#req{method = 'GET',
} = Req) ->
html_ok(ui_template:render_directory(validate_session(Req)));

handle_request2(#req{method = 'GET',
path = [<<"directory.opml">>]
}) ->
Body = ui_template:export_directory_opml(),
{ok, 200,
[{<<"Content-Type">>, ?MIME_OPML}], [],
Body};

%% API
handle_request2(#req{method = 'GET',
path = [<<"by-enclosure.json">>],
Expand Down
39 changes: 36 additions & 3 deletions apps/ui/src/ui_template.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
render_activate/3, render_reactivate/1,
render_help/2,
render_front/1,
render_new/1, render_top/2, render_directory/1,
render_new/1, render_top/2,
render_directory/1, export_directory_opml/0,
render_user/2,
render_user_feed/3, export_feed/3,
export_downloads/3, export_downloads/4]).
Expand Down Expand Up @@ -877,12 +878,44 @@ render_directory(Req) ->

page_2column(
Opts,
[],
[{h2, <<"Directory of Torrentified Podcasters">>}],
[{link, [{rel, "alternate"},
{type, ?MIME_OPML},
{href, [ui_link:base(), "/directory.opml"]}], []}],
[{h2, <<"Directory of Torrentified Podcasters">>},
{dl, [{class, "feedslist"}],
[{dt, <<"Feeds:">>},
{dd, {a, [{href, "/directory.opml"}], <<"OPML">>}}
]}
],
lists:map(fun render_directory_item/1, Directory1),
lists:map(fun render_directory_item/1, Directory2)
).

export_directory_opml() ->
Directory = model_feeds:get_directory(),
OPML =
{opml, [{version, "2.0"}],
[{head,
[{title, "Bitlove.org directory"},
{ownerId, "http://bitlove.org/directory"}
]},
{body,
[{outline, [{text, Title}
],
[{outline, [{text, FeedTitle},
{type, "rss"},
{htmlUrl, <<(ui_link:base())/binary, (ui_link:link_user_feed(User, Slug))/binary>>},
{xmlUrl, <<(ui_link:base())/binary, (ui_link:link_user_feed_xml(User, Slug))/binary>>}
], []}
|| {Slug, FeedTitle} <- Feeds
]}
|| {User, Title, _Image, Feeds} <- Directory
]}
]},
[<<"<?xml version='1.0' encoding='UTF-8'?>\n">>,
html:to_iolist(OPML)].


%% Feeds, Recent Episodes
render_user(#req{session_user = SessionUser} = Req, UserName) ->
IsSelf = SessionUser == UserName,
Expand Down

0 comments on commit e71f726

Please sign in to comment.