HandlerPageView: Use RevisionRenderer
Dieser Commit ist enthalten in:
Ursprung
2b1c3c71b7
Commit
ecd45a61c8
@ -27,6 +27,7 @@ SOFTWARE.
|
||||
#include "../dynamic/dynamiccontentincludepage.h"
|
||||
#include "../dynamic/dynamiccontentsetvar.h"
|
||||
#include "../dynamic/dynamiccontentgetvar.h"
|
||||
#include "../revisionrenderer.h"
|
||||
|
||||
bool HandlerPageView::canAccess(std::string page)
|
||||
{
|
||||
@ -133,65 +134,20 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
||||
return errorResponse("Database error", "While trying to fetch revision, a database error occured");
|
||||
}
|
||||
|
||||
TemplatePage page = this->templ->getPage(templatepartname);
|
||||
|
||||
Parser parser;
|
||||
Response result;
|
||||
result.setStatus(200);
|
||||
std::string indexcontent;
|
||||
std::string parsedcontent;
|
||||
|
||||
std::map<std::string, std::string> dynamicVarsMap;
|
||||
std::function<std::string(std::string_view, std::string_view)> dynamicParseCallback =
|
||||
[&](std::string_view key, std::string_view value) -> std::string
|
||||
{
|
||||
if(key == "dynamic:postlist")
|
||||
{
|
||||
std::shared_ptr<DynamicContentPostList> postlist = createDynamic<DynamicContentPostList>();
|
||||
postlist->setArgument(std::string(value));
|
||||
return postlist->render();
|
||||
}
|
||||
if(key == "dynamic:includepage")
|
||||
{
|
||||
if((effectivePermissions(std::string(value)).canRead()))
|
||||
{
|
||||
std::shared_ptr<DynamicContentIncludePage> includePage = createDynamic<DynamicContentIncludePage>();
|
||||
includePage->setArgument(std::string(value));
|
||||
return parser.parseDynamics(includePage->render(), dynamicParseCallback);
|
||||
}
|
||||
}
|
||||
if(key == "dynamic:setvar")
|
||||
{
|
||||
std::shared_ptr<DynamicContentSetVar> setVar = createDynamic<DynamicContentSetVar>();
|
||||
setVar->setMap(dynamicVarsMap);
|
||||
setVar->setArgument(std::string(value));
|
||||
return setVar->render();
|
||||
}
|
||||
if(key == "dynamic:getvar")
|
||||
{
|
||||
std::shared_ptr<DynamicContentGetVar> getVar = createDynamic<DynamicContentGetVar>();
|
||||
getVar->setMap(dynamicVarsMap);
|
||||
getVar->setArgument(std::string(value));
|
||||
return getVar->render();
|
||||
}
|
||||
return std::string{};
|
||||
};
|
||||
RevisionRenderer revisionRenderer { *this->templ, *this->database, *this->urlProvider };
|
||||
|
||||
auto firstRevision = revisionDao->getRevisionForPage(pagename, 1);
|
||||
if(!firstRevision)
|
||||
{
|
||||
return errorResponse("Error", "Could not get first revision for page, which is odd. Solar flares?");
|
||||
}
|
||||
|
||||
std::string customtitle = parser.extractCommand("pagetitle", revision->content);
|
||||
std::string parsedcontent = revisionRenderer.renderContent(revision.value(), customtitle);
|
||||
/* TODO: Dynamic includes not considered, probably fine in practise */
|
||||
std::string indexcontent = createIndexContent(parser, revision->content);
|
||||
|
||||
dynamicVarsMap["createdon"] = utils::toISODate(firstRevision.value().timestamp);
|
||||
dynamicVarsMap["pagetitle"] = customtitle;
|
||||
|
||||
std::string resolvedContent = parser.parseDynamics(revision->content, dynamicParseCallback);
|
||||
indexcontent = createIndexContent(parser, resolvedContent);
|
||||
parsedcontent = parser.parse(pageDao, *this->urlProvider, resolvedContent);
|
||||
std::string revisionstr = std::to_string(revision->revision);
|
||||
TemplatePage page = this->templ->getPage(templatepartname);
|
||||
page.setVar("content", parsedcontent);
|
||||
page.setVar("index", indexcontent);
|
||||
page.setVar("editedby", revision->author);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren