diff --git a/handlers/handlerpageview.cpp b/handlers/handlerpageview.cpp index 98411b2..082f80f 100644 --- a/handlers/handlerpageview.cpp +++ b/handlers/handlerpageview.cpp @@ -25,6 +25,9 @@ SOFTWARE. #include "../htmllink.h" #include "../dynamic/dynamiccontentpostlist.h" #include "../dynamic/dynamiccontentincludepage.h" +#include "../dynamic/dynamiccontentsetvar.h" +#include "../dynamic/dynamiccontentgetvar.h" + bool HandlerPageView::canAccess(std::string page) { return effectivePermissions(page).canRead(); @@ -137,8 +140,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename, std::string indexcontent; std::string parsedcontent; - bool keepParsing = true; - + std::map dynamicVarsMap; std::function dynamicParseCallback = [&](std::string_view key, std::string_view value) -> std::string { @@ -150,16 +152,34 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename, } if(key == "dynamic:includepage") { - std::shared_ptr includePage = createDynamic(); - includePage->setArgument(std::string(value)); - return parser.parse(pageDao, *this->urlProvider, includePage->render(), dynamicParseCallback); + if((effectivePermissions(std::string(value)).canRead())) + { + std::shared_ptr includePage = createDynamic(); + includePage->setArgument(std::string(value)); + return parser.parseDynamics(includePage->render(), dynamicParseCallback); + } + } + if(key == "dynamic:setvar") + { + std::shared_ptr setVar = createDynamic(); + setVar->setMap(dynamicVarsMap); + setVar->setArgument(std::string(value)); + return setVar->render(); + } + if(key == "dynamic:getvar") + { + std::shared_ptr getVar = createDynamic(); + getVar->setMap(dynamicVarsMap); + getVar->setArgument(std::string(value)); + return getVar->render(); } return std::string{}; }; + std::string resolvedContent = parser.parseDynamics(revision->content, dynamicParseCallback); if(revisionid > 0) { - indexcontent = createIndexContent(parser, revision->content); - parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content, dynamicParseCallback); + indexcontent = createIndexContent(parser, resolvedContent); + parsedcontent = parser.parse(pageDao, *this->urlProvider, resolvedContent); } else { @@ -173,7 +193,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename, } else { - indexcontent = createIndexContent(parser, revision->content); + indexcontent = createIndexContent(parser, resolvedContent); this->cache->put(cachekeyindexcontent, indexcontent); } if(cachedparsedcontent) @@ -182,7 +202,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename, } else { - parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content, dynamicParseCallback); + parsedcontent = parser.parse(pageDao, *this->urlProvider, resolvedContent); this->cache->put(cachekeyparsedcontent, parsedcontent); } }