/usr/lib/Wt/examples/blog/BlogRSSFeed.C is in witty-examples 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | /*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <Wt/Http/Response>
#include <Wt/Utils>
#include "BlogRSSFeed.h"
#include "model/BlogSession.h"
#include "model/User.h"
#include "model/Post.h"
#include "model/Comment.h"
#include "model/Tag.h"
#include "model/Token.h"
namespace dbo = Wt::Dbo;
BlogRSSFeed::BlogRSSFeed(const std::string& sqliteDb,
const std::string& title,
const std::string& url,
const std::string& description)
: session_(new BlogSession(sqliteDb)),
title_(title),
url_(url),
description_(description)
{ }
BlogRSSFeed::~BlogRSSFeed()
{
delete session_;
}
void BlogRSSFeed::handleRequest(const Wt::Http::Request &request,
Wt::Http::Response &response)
{
response.setMimeType("application/rss+xml");
std::string url = url_;
if (url.empty()) {
url = request.urlScheme() + "://" + request.serverName();
if (!request.serverPort().empty() && request.serverPort() != "80")
url += ":" + request.serverPort();
url += request.path();
// remove '/feed/'
url.erase(url.length() - 6);
}
response.out() <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<rss version=\"2.0\">\n"
" <channel>\n"
" <title>" << Wt::Utils::htmlEncode(title_) << "</title>\n"
" <link>" << Wt::Utils::htmlEncode(url) << "</link>\n"
" <description>" << Wt::Utils::htmlEncode(description_)
<< "</description>\n";
dbo::Transaction t(*session_);
Posts posts = session_->find<Post>
("where state = ? "
"order by date desc "
"limit 10").bind(Post::Published);
for (Posts::const_iterator i = posts.begin(); i != posts.end(); ++i) {
dbo::ptr<Post> post = *i;
std::string permaLink = url + "/" + post->permaLink();
response.out() <<
" <item>\n"
" <title>" << Wt::Utils::htmlEncode(post->title.toUTF8()) << "</title>\n"
" <pubDate>" << post->date.toString("ddd, d MMM yyyy hh:mm:ss UTC")
<< "</pubDate>\n"
" <guid isPermaLink=\"true\">" << Wt::Utils::htmlEncode(permaLink)
<< "</guid>\n";
std::string description = post->briefHtml.toUTF8();
if (!post->bodySrc.empty())
description +=
"<p><a href=\"" + permaLink + "\">Read the rest...</a></p>";
response.out() <<
" <description><![CDATA[" << description << "]]></description>\n"
" </item>\n";
}
response.out() <<
" </channel>\n"
"</rss>\n";
t.commit();
}
|