13 #include <boost/filesystem.hpp>
17 #include <uuid/uuid.h>
19 #include <Wt/WDateTime>
20 #include <Wt/WEnvironment>
22 #include <gdcore/gdCore.h>
24 #include <gdwtcore/gdWTextDelegate.h>
30 #include <WsModule/WsModule.h>
35 #define WSMODLATESTNEWS "wsmodlatestnews"
36 #define NB_NEWS "nb_news"
42 : WContainerWidget(parent)
44 addStyleClass(
"WsRSS");
52 WContainerWidget::load();
57 WDateTime dt(WDateTime::currentDateTime());
58 std::string sDateTime = dt.toString(
"yyyy-MM-dd hh:mm:ss").narrow();
62 std::string serverDesc = asString(
option(
"serverDesc")).toUTF8();
63 std::string serverTitle = asString(
option(
"serverTitle")).toUTF8();
64 std::string rssFile = asString(
option(
"rssFile")).toUTF8();
65 std::string path2RSS = user->
getRootPath() + rssFile;
66 FILE* xmlFile = fopen(path2RSS.c_str(),
"w+");
67 if ( !xmlFile )
return;
68 fprintf(xmlFile,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
69 fprintf(xmlFile,
"<rss version=\"2.0\">\n");
70 fprintf(xmlFile,
" <channel>\n");
71 fprintf(xmlFile,
" <title>%s</title>\n", serverTitle.c_str());
72 fprintf(xmlFile,
" <description>%s</description>\n", serverDesc.c_str());
73 fprintf(xmlFile,
" <lastBuildDate>%s</lastBuildDate>\n", sDateTime.c_str());
74 fprintf(xmlFile,
" <link>%s</link>\n", sServerUrl.c_str());
75 std::string rootPath = asString(
option(
"rootPath")).narrow();
76 boost::algorithm::replace_all(rootPath,
"&",
"&");
78 if ( rootPath.size() < 1 )
82 root = root.get()->eatPath(rootPath);
85 LOG(
ERROR) <<
"WsRSS::setTable cannot get root !";
89 int rowsCount = asNumber(
option(
"rowsCount"));
90 std::vector<NodePtr> news = searchRSS.
getRSS(rowsCount);
109 for (
int i = 0; i < news.size(); ++i) {
111 news[i].
get()->getPath().extension().
string() ==
".fhtml" ||
112 news[i].
get()->getPath().extension().
string() ==
".pdf" ||
113 news[i].
get()->getPath().extension().
string() ==
".rpg" ||
114 news[i].
get()->getPath().extension().
string() ==
".zip"
117 if ( news[i].
get()->getProperties().get()->get(
"global",
"in_view",
"true") ==
"false" )
continue;
118 boost::filesystem::path wsRes = news[i]->getPath();
120 while (wsRes.string() !=
"/") {
121 wsRes = wsRes.parent_path();
122 if ( wsRes.filename().string() ==
"ws.res" ) {
126 if ( wsRes.filename().string() ==
"ws" ) {
132 if ( bRes )
continue;
133 fprintf(xmlFile,
" <item>\n");
134 WDateTime dt(WDateTime::currentDateTime());
135 std::string sTitle = news[i].get()->getDisplayName(
true);
136 std::string sDesc = news[i].get()->getProperties().get()->get(
"global",
"short_description",
"");
137 std::string sPubDate = news[i].get()->getProperties().get()->get(
"global",
"publish_date", boost::lexical_cast<std::string>(dt.toTime_t()));
138 dt.setTime_t(boost::lexical_cast<time_t>(sPubDate));
139 sPubDate = dt.toString(
"yyyy-MM-dd hh:mm:ss").narrow();
141 std::string sLink = sServerUrl + news[i]->getPath().string();
144 boost::algorithm::replace_all(sLink,
"&",
"&");
146 uuid_t uuidGenerated;
147 uuid_generate_random(uuidGenerated);
148 uuid_unparse(uuidGenerated, uuidBuff);
149 std::string sGuid = news[i]->getProperties().get()->get(
"global",
"guid", uuidBuff);
150 fprintf(xmlFile,
" <title><![CDATA[%s]]></title>\n", sTitle.c_str());
151 fprintf(xmlFile,
" <description><![CDATA[%s]]></description>\n", sDesc.c_str());
152 fprintf(xmlFile,
" <pubDate>%s</pubDate>\n", sPubDate.c_str());
153 fprintf(xmlFile,
" <link>%s</link>\n", sLink.c_str());
154 fprintf(xmlFile,
" <guid>%s</guid>\n", sGuid.c_str());
155 fprintf(xmlFile,
" </item>\n");
157 fprintf(xmlFile,
" </channel>\n");
158 fprintf(xmlFile,
"</rss>\n");
boost::shared_ptr< WsAbstractNode > NodePtr
static WsApplication * wsInstance()
Facility function to access the application object.
Interface that provides differents methods for accessing the FsTree as well as other features...
const boost::any & option(const std::string &attribute) const
Get an options value.
std::string get(const std::string §ion, const std::string &id, const std::string &def)
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
static WsGlobalProperties * instance()
NodePtr getAccessRoot()
return the root node of the access tree starting from the root