1
0

Dynamic: Add DynamicContentIncludePage to allow including pages

Este cometimento está contido em:
Albert S. 2022-03-27 21:36:53 +02:00
ascendente 7bb7600d39
cometimento 1ae5495e61
7 ficheiros modificados com 42 adições e 12 eliminações

Ver ficheiro

@ -11,9 +11,15 @@ class DynamicContent
Database *database; Database *database;
UrlProvider *urlProvider; UrlProvider *urlProvider;
std::string argument;
public: public:
DynamicContent(Template &templ, Database &database, UrlProvider &urlProvider); DynamicContent(Template &templ, Database &database, UrlProvider &urlProvider);
virtual std::string render() = 0; virtual std::string render() = 0;
virtual void setArgument(std::string argument)
{
this->argument = argument;
}
virtual ~DynamicContent() virtual ~DynamicContent()
{ {
} }

Ver ficheiro

@ -0,0 +1,14 @@
#include "dynamiccontentincludepage.h"
#include "../parser.h"
std::string DynamicContentIncludePage::render()
{
auto revisionDao = this->database->createRevisionDao();
auto rev = revisionDao->getCurrentForPage(this->argument);
if(rev)
{
Parser parser;
auto result = parser.parse(*this->database->createPageDao(), *this->urlProvider, rev->content);
return result;
}
return {};
}

Ver ficheiro

@ -0,0 +1,12 @@
#ifndef DYNAMICCONTENTINCLUDEPAGE_H
#define DYNAMICCONTENTINCLUDEPAGE_H
#include "dynamiccontent.h"
class DynamicContentIncludePage : public DynamicContent
{
public:
using DynamicContent::DynamicContent;
std::string render();
};
#endif // DYNAMICCONTENTINCLUDEPAGE_H

Ver ficheiro

@ -1,11 +1,6 @@
#include <chrono> #include <chrono>
#include "dynamiccontentpostlist.h" #include "dynamiccontentpostlist.h"
void DynamicContentPostList::setCategory(std::string catname)
{
this->catname = catname;
}
std::string DynamicContentPostList::render() std::string DynamicContentPostList::render()
{ {
auto categoryDao = this->database->createCategoryDao(); auto categoryDao = this->database->createCategoryDao();
@ -13,7 +8,7 @@ std::string DynamicContentPostList::render()
auto revisionDao = this->database->createRevisionDao(); auto revisionDao = this->database->createRevisionDao();
QueryOption option; QueryOption option;
option.includeInvisible = false; option.includeInvisible = false;
auto members = categoryDao->fetchMembers(this->catname, option); auto members = categoryDao->fetchMembers(this->argument, option);
std::vector<std::pair<std::string, time_t>> pageList; std::vector<std::pair<std::string, time_t>> pageList;
for(std::string &member : members) for(std::string &member : members)
{ {

Ver ficheiro

@ -4,12 +4,8 @@
#include "dynamiccontent.h" #include "dynamiccontent.h"
class DynamicContentPostList : public DynamicContent class DynamicContentPostList : public DynamicContent
{ {
private:
std::string catname;
public: public:
using DynamicContent::DynamicContent; using DynamicContent::DynamicContent;
void setCategory(std::string catname);
std::string render() override; std::string render() override;
}; };

Ver ficheiro

@ -24,6 +24,7 @@ SOFTWARE.
#include "../parser.h" #include "../parser.h"
#include "../htmllink.h" #include "../htmllink.h"
#include "../dynamic/dynamiccontentpostlist.h" #include "../dynamic/dynamiccontentpostlist.h"
#include "../dynamic/dynamiccontentincludepage.h"
bool HandlerPageView::canAccess(std::string page) bool HandlerPageView::canAccess(std::string page)
{ {
return effectivePermissions(page).canRead(); return effectivePermissions(page).canRead();
@ -142,9 +143,15 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
if(key == "dynamic:postlist") if(key == "dynamic:postlist")
{ {
std::shared_ptr<DynamicContentPostList> postlist = createDynamic<DynamicContentPostList>(); std::shared_ptr<DynamicContentPostList> postlist = createDynamic<DynamicContentPostList>();
postlist->setCategory(std::string(value)); postlist->setArgument(std::string(value));
return postlist->render(); return postlist->render();
} }
if(key == "dynamic:includepage")
{
std::shared_ptr<DynamicContentIncludePage> includePage = createDynamic<DynamicContentIncludePage>();
includePage->setArgument(std::string(value));
return includePage->render();
}
return std::string{}; return std::string{};
}; };
if(revisionid > 0) if(revisionid > 0)

Ver ficheiro

@ -122,7 +122,7 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
std::string result; std::string result;
// we don't care about commands, but we nevertheless replace them with empty strings // we don't care about commands, but we nevertheless replace them with empty strings
std::regex tagfinder( std::regex tagfinder(
R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect|cmd:pagetitle|category|dynamic:postlist)*?\]((\s|\S)*?)\[/\1])"); R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect|cmd:pagetitle|category|dynamic:postlist|dynamic:includepage)*?\]((\s|\S)*?)\[/\1])");
result = utils::regex_callback_replacer( result = utils::regex_callback_replacer(
tagfinder, content, tagfinder, content,
[&](std::smatch &match) [&](std::smatch &match)