Compare commits
No commits in common. "61e84a98c7141661427c9a72367301da8a84779e" and "f08e235d0329b34db961f5e44029e795038ae1d0" have entirely different histories.
61e84a98c7
...
f08e235d03
1
cache/mapcache.h
vendored
1
cache/mapcache.h
vendored
@ -4,7 +4,6 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/* Thread-Safe Key-Value store */
|
/* Thread-Safe Key-Value store */
|
||||||
template <class T> class MapCache
|
template <class T> class MapCache
|
||||||
|
@ -102,27 +102,23 @@ std::vector<Page> CategoryDaoSqlite::fetchMembers(std::string name, QueryOption
|
|||||||
|
|
||||||
SqliteQueryOption queryOption{o};
|
SqliteQueryOption queryOption{o};
|
||||||
std::string queryoptions =
|
std::string queryoptions =
|
||||||
queryOption.setOrderByColumn("name").setListedColumnName("page.listed").setPrependWhere(false).build();
|
queryOption.setOrderByColumn("name").setVisibleColumnName("page.visible").setPrependWhere(false).build();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto query =
|
auto query = *db << "SELECT page.id, page.name AS name, page.title, page.lastrevision, page.visible FROM "
|
||||||
*db
|
|
||||||
<< "SELECT page.id, page.name AS name, page.title, page.lastrevision, page.listed, page.feedlisted FROM "
|
|
||||||
"categorymember INNER JOIN page ON page.id = "
|
"categorymember INNER JOIN page ON page.id = "
|
||||||
"categorymember.page WHERE category = (SELECT id FROM category WHERE name = ? ) AND " +
|
"categorymember.page WHERE category = (SELECT id FROM category WHERE name = ? ) AND " +
|
||||||
queryoptions
|
queryoptions
|
||||||
<< name;
|
<< name;
|
||||||
query >> [&](unsigned int id, std::string name, std::string title, unsigned int lastrevision, bool listed,
|
query >> [&](unsigned int id, std::string name, std::string title, unsigned int lastrevision, bool visible)
|
||||||
bool feedlisted)
|
|
||||||
{
|
{
|
||||||
Page p;
|
Page p;
|
||||||
p.name = name;
|
p.name = name;
|
||||||
p.pageid = id;
|
p.pageid = id;
|
||||||
p.title = title;
|
p.title = title;
|
||||||
p.current_revision = lastrevision;
|
p.current_revision = lastrevision;
|
||||||
p.listed = listed;
|
p.listed = visible;
|
||||||
p.feedlisted = feedlisted;
|
|
||||||
result.push_back(p);
|
result.push_back(p);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,6 @@ class PageDao
|
|||||||
virtual void setCategories(std::string pagename, const std::vector<std::string> &catnames) = 0;
|
virtual void setCategories(std::string pagename, const std::vector<std::string> &catnames) = 0;
|
||||||
virtual std::vector<SearchResult> search(std::string query, QueryOption option) = 0;
|
virtual std::vector<SearchResult> search(std::string query, QueryOption option) = 0;
|
||||||
|
|
||||||
virtual std::vector<std::string> getChildren(std::string pagename) = 0;
|
|
||||||
|
|
||||||
virtual ~PageDao()
|
virtual ~PageDao()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -57,12 +57,8 @@ std::optional<Page> PageDaoSqlite::findByTitle(std::string title)
|
|||||||
Page result;
|
Page result;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto ps =
|
auto ps = *db << "SELECT id, name, title, lastrevision, visible FROM page WHERE title = ?";
|
||||||
*db
|
ps << title >> std::tie(result.pageid, result.name, result.title, result.current_revision, result.listed);
|
||||||
<< "SELECT id, name, title, lastrevision, listed, feedlisted, (SELECT name FROM page WHERE id = parent) "
|
|
||||||
"FROM page WHERE title = ?";
|
|
||||||
ps << title >> std::tie(result.pageid, result.name, result.title, result.current_revision, result.listed,
|
|
||||||
result.feedlisted, result.parentpage);
|
|
||||||
}
|
}
|
||||||
catch(const sqlite::errors::no_rows &e)
|
catch(const sqlite::errors::no_rows &e)
|
||||||
{
|
{
|
||||||
@ -82,13 +78,9 @@ std::optional<Page> PageDaoSqlite::find(unsigned int id)
|
|||||||
result.pageid = id;
|
result.pageid = id;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto ps =
|
auto ps = *db << "SELECT name, title, lastrevision, visible FROM page WHERE id = ?";
|
||||||
*db
|
|
||||||
<< "SELECT name, title, lastrevision, listed, feedlisted, (SELECT name FROM page WHERE id = parent) FROM "
|
|
||||||
"page WHERE id = ?";
|
|
||||||
|
|
||||||
ps << id >> std::tie(result.name, result.title, result.current_revision, result.listed, result.feedlisted,
|
ps << id >> std::tie(result.name, result.title, result.current_revision, result.listed);
|
||||||
result.parentpage);
|
|
||||||
}
|
}
|
||||||
catch(const sqlite::errors::no_rows &e)
|
catch(const sqlite::errors::no_rows &e)
|
||||||
{
|
{
|
||||||
@ -126,10 +118,10 @@ void PageDaoSqlite::save(const Page &page)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
*db << "INSERT OR REPLACE INTO page (id, name, title, lastrevision, listed, feedlisted, parent) VALUES((SELECT "
|
*db << "INSERT OR REPLACE INTO page (id, name, title, lastrevision, visible) VALUES((SELECT id FROM page WHERE "
|
||||||
"id FROM page WHERE name = ? OR id = ?), ?, ?, ?, ?, ?, (SELECT id FROM page WHERE name = ?))"
|
"name = "
|
||||||
<< page.name << page.pageid << page.name << page.title << page.current_revision << page.listed
|
"? OR id = ?), ?, ?, ?, ?)"
|
||||||
<< page.feedlisted << page.parentpage;
|
<< page.name << page.pageid << page.name << page.title << page.current_revision << page.listed;
|
||||||
}
|
}
|
||||||
catch(sqlite::sqlite_exception &e)
|
catch(sqlite::sqlite_exception &e)
|
||||||
{
|
{
|
||||||
@ -145,23 +137,19 @@ std::vector<Page> PageDaoSqlite::getPageList(QueryOption option)
|
|||||||
{
|
{
|
||||||
std::string queryOption = SqliteQueryOption(option)
|
std::string queryOption = SqliteQueryOption(option)
|
||||||
.setOrderByColumn("lower(name)")
|
.setOrderByColumn("lower(name)")
|
||||||
.setListedColumnName("listed")
|
.setVisibleColumnName("visible")
|
||||||
.setPrependWhere(true)
|
.setPrependWhere(true)
|
||||||
.build();
|
.build();
|
||||||
std::string query = "SELECT id, name, title, lastrevision, listed, feedlisted, (SELECT name FROM page WHERE "
|
std::string query = "SELECT id, name, title, lastrevision, visible FROM page " + queryOption;
|
||||||
"id = parent) FROM page " +
|
*db << query >>
|
||||||
queryOption;
|
[&](unsigned int pageid, std::string name, std::string title, unsigned int current_revision, bool visible)
|
||||||
*db << query >> [&](unsigned int pageid, std::string name, std::string title, unsigned int current_revision,
|
|
||||||
bool listed, bool feedlisted, std::string parent)
|
|
||||||
{
|
{
|
||||||
Page tmp;
|
Page tmp;
|
||||||
tmp.pageid = pageid;
|
tmp.pageid = pageid;
|
||||||
tmp.name = name;
|
tmp.name = name;
|
||||||
tmp.title = title;
|
tmp.title = title;
|
||||||
tmp.current_revision = current_revision;
|
tmp.current_revision = current_revision;
|
||||||
tmp.listed = listed;
|
tmp.listed = visible;
|
||||||
tmp.feedlisted = feedlisted;
|
|
||||||
tmp.parentpage = parent;
|
|
||||||
result.push_back(tmp);
|
result.push_back(tmp);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -274,11 +262,3 @@ int PageDaoSqlite::fetchPageId(std::string pagename)
|
|||||||
auto binder = *db << "SELECT id FROM page WHERE name = ?" << pagename;
|
auto binder = *db << "SELECT id FROM page WHERE name = ?" << pagename;
|
||||||
return execInt(binder);
|
return execInt(binder);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> PageDaoSqlite::getChildren(std::string pagename)
|
|
||||||
{
|
|
||||||
std::vector<std::string> result;
|
|
||||||
auto query = *db << "SELECT name FROM page WHERE parent = (SELECT id FROM page WHERE name = ?)" << pagename;
|
|
||||||
query >> [&](std::string page) { result.push_back(page); };
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
@ -28,8 +28,6 @@ class PageDaoSqlite : public PageDao, protected SqliteDao
|
|||||||
int fetchPageId(std::string pagename);
|
int fetchPageId(std::string pagename);
|
||||||
std::vector<SearchResult> search(std::string query, QueryOption option) override;
|
std::vector<SearchResult> search(std::string query, QueryOption option) override;
|
||||||
void setCategories(std::string pagename, const std::vector<std::string> &catnames) override;
|
void setCategories(std::string pagename, const std::vector<std::string> &catnames) override;
|
||||||
std::vector<std::string> getChildren(std::string pagename) override;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PAGEDAOSQLITE_H
|
#endif // PAGEDAOSQLITE_H
|
||||||
|
@ -13,7 +13,7 @@ class QueryOption
|
|||||||
unsigned int offset = 0;
|
unsigned int offset = 0;
|
||||||
unsigned int limit = 0;
|
unsigned int limit = 0;
|
||||||
SORT_ORDER order = ASCENDING;
|
SORT_ORDER order = ASCENDING;
|
||||||
bool includeUnlisted = true;
|
bool includeInvisible = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QUERYOPTION_H
|
#endif // QUERYOPTION_H
|
||||||
|
@ -52,7 +52,7 @@ std::vector<Revision> RevisionDaoSqlite::getAllRevisions(QueryOption &options)
|
|||||||
{
|
{
|
||||||
SqliteQueryOption queryOption{options};
|
SqliteQueryOption queryOption{options};
|
||||||
std::string queryOptionSql = queryOption.setPrependWhere(true)
|
std::string queryOptionSql = queryOption.setPrependWhere(true)
|
||||||
.setListedColumnName("page.listed")
|
.setVisibleColumnName("page.visible")
|
||||||
.setOrderByColumn("creationtime")
|
.setOrderByColumn("creationtime")
|
||||||
.build();
|
.build();
|
||||||
auto query =
|
auto query =
|
||||||
@ -61,8 +61,7 @@ std::vector<Revision> RevisionDaoSqlite::getAllRevisions(QueryOption &options)
|
|||||||
"page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id " +
|
"page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id " +
|
||||||
queryOptionSql;
|
queryOptionSql;
|
||||||
query >> [&](std::string author, std::string comment, std::string content, time_t creationtime,
|
query >> [&](std::string author, std::string comment, std::string content, time_t creationtime,
|
||||||
std::string page, unsigned int revisionid)
|
std::string page, unsigned int revisionid) {
|
||||||
{
|
|
||||||
Revision r;
|
Revision r;
|
||||||
r.author = author;
|
r.author = author;
|
||||||
r.comment = comment;
|
r.comment = comment;
|
||||||
@ -92,7 +91,7 @@ std::vector<Revision> RevisionDaoSqlite::getAllRevisionsForPage(std::string page
|
|||||||
{
|
{
|
||||||
SqliteQueryOption queryOption{option};
|
SqliteQueryOption queryOption{option};
|
||||||
std::string queryOptionSql = queryOption.setPrependWhere(false)
|
std::string queryOptionSql = queryOption.setPrependWhere(false)
|
||||||
.setListedColumnName("page.listed")
|
.setVisibleColumnName("page.visible")
|
||||||
.setOrderByColumn("creationtime")
|
.setOrderByColumn("creationtime")
|
||||||
.build();
|
.build();
|
||||||
auto query = *db << "SELECT (SELECT username FROM user WHERE id = author), comment, content, "
|
auto query = *db << "SELECT (SELECT username FROM user WHERE id = author), comment, content, "
|
||||||
@ -102,8 +101,7 @@ std::vector<Revision> RevisionDaoSqlite::getAllRevisionsForPage(std::string page
|
|||||||
<< pagename;
|
<< pagename;
|
||||||
|
|
||||||
query >> [&](std::string author, std::string comment, std::string content, time_t creationtime,
|
query >> [&](std::string author, std::string comment, std::string content, time_t creationtime,
|
||||||
std::string page, unsigned int revisionid)
|
std::string page, unsigned int revisionid) {
|
||||||
{
|
|
||||||
Revision r;
|
Revision r;
|
||||||
r.author = author;
|
r.author = author;
|
||||||
r.comment = comment;
|
r.comment = comment;
|
||||||
@ -131,8 +129,7 @@ std::optional<Revision> RevisionDaoSqlite::getCurrentForPage(std::string pagenam
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto query = *db << "SELECT (SELECT username FROM user WHERE id = author), comment, content, "
|
auto query = *db << "SELECT (SELECT username FROM user WHERE id = author), comment, content, "
|
||||||
"strftime('%s',creationtime), page.name, revisionid FROM revision INNER JOIN page ON "
|
"strftime('%s',creationtime), page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id WHERE page.name = ? AND page.lastrevision = revision.revisionid";
|
||||||
"revision.page = page.id WHERE page.name = ? AND page.lastrevision = revision.revisionid";
|
|
||||||
query << pagename;
|
query << pagename;
|
||||||
query >>
|
query >>
|
||||||
std::tie(result.author, result.comment, result.content, result.timestamp, result.page, result.revision);
|
std::tie(result.author, result.comment, result.content, result.timestamp, result.page, result.revision);
|
||||||
@ -157,8 +154,7 @@ std::optional<Revision> RevisionDaoSqlite::getRevisionForPage(std::string pagena
|
|||||||
auto query =
|
auto query =
|
||||||
*db
|
*db
|
||||||
<< "SELECT (SELECT username FROM user WHERE id = author), comment, content, strftime('%s',creationtime), "
|
<< "SELECT (SELECT username FROM user WHERE id = author), comment, content, strftime('%s',creationtime), "
|
||||||
"page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id WHERE page.name = ? AND "
|
"page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id WHERE page.name = ? AND revisionid = ? ";
|
||||||
"revisionid = ? ";
|
|
||||||
query << pagename << revision;
|
query << pagename << revision;
|
||||||
query >>
|
query >>
|
||||||
std::tie(result.author, result.comment, result.content, result.timestamp, result.page, result.revision);
|
std::tie(result.author, result.comment, result.content, result.timestamp, result.page, result.revision);
|
||||||
|
@ -31,9 +31,9 @@ SqliteQueryOption &SqliteQueryOption::setOrderByColumn(std::string name)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SqliteQueryOption &SqliteQueryOption::setListedColumnName(std::string name)
|
SqliteQueryOption &SqliteQueryOption::setVisibleColumnName(std::string name)
|
||||||
{
|
{
|
||||||
this->listedColumnName = name;
|
this->visibleColumnName = name;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,9 +50,9 @@ std::string SqliteQueryOption::build()
|
|||||||
{
|
{
|
||||||
result += "WHERE ";
|
result += "WHERE ";
|
||||||
}
|
}
|
||||||
if(!o.includeUnlisted && !this->listedColumnName.empty())
|
if(!o.includeInvisible && !this->visibleColumnName.empty())
|
||||||
{
|
{
|
||||||
result += this->listedColumnName + " = 1";
|
result += this->visibleColumnName + " = 1";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ class SqliteQueryOption
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
QueryOption o;
|
QueryOption o;
|
||||||
std::string listedColumnName;
|
std::string visibleColumnName;
|
||||||
std::string orderByColumnName;
|
std::string orderByColumnName;
|
||||||
|
|
||||||
bool prependWhere;
|
bool prependWhere;
|
||||||
@ -17,7 +17,7 @@ class SqliteQueryOption
|
|||||||
|
|
||||||
SqliteQueryOption &setOrderByColumn(std::string name);
|
SqliteQueryOption &setOrderByColumn(std::string name);
|
||||||
|
|
||||||
SqliteQueryOption &setListedColumnName(std::string name);
|
SqliteQueryOption &setVisibleColumnName(std::string name);
|
||||||
|
|
||||||
SqliteQueryOption &setPrependWhere(bool b);
|
SqliteQueryOption &setPrependWhere(bool b);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ std::string DynamicContentPostList::render()
|
|||||||
auto permissionDao = this->database->createPermissionsDao();
|
auto permissionDao = this->database->createPermissionsDao();
|
||||||
|
|
||||||
QueryOption option;
|
QueryOption option;
|
||||||
option.includeUnlisted = false;
|
option.includeInvisible = false;
|
||||||
auto members = categoryDao->fetchMembers(this->argument, 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(const Page &member : members)
|
for(const Page &member : members)
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
#include <chrono>
|
|
||||||
#include "dynamicpostrenderer.h"
|
|
||||||
#include "../parser.h"
|
|
||||||
#include "../utils.h"
|
|
||||||
|
|
||||||
void DynamicPostRenderer::setArgument(std::string argument)
|
|
||||||
{
|
|
||||||
auto splitted = utils::split(argument, '|');
|
|
||||||
this->category = splitted[0];
|
|
||||||
if(splitted.size() >= 2)
|
|
||||||
{
|
|
||||||
this->templatepartname = splitted[1];
|
|
||||||
}
|
|
||||||
if(splitted.size() >= 3)
|
|
||||||
{
|
|
||||||
this->customlinkurl = splitted[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string DynamicPostRenderer::linkToPage(std::string page)
|
|
||||||
{
|
|
||||||
if(this->customlinkurl.empty())
|
|
||||||
{
|
|
||||||
return this->urlProvider->page(page);
|
|
||||||
}
|
|
||||||
return utils::strreplace(this->customlinkurl, "{page}", page);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string DynamicPostRenderer::render()
|
|
||||||
{
|
|
||||||
auto categoryDao = this->database->createCategoryDao();
|
|
||||||
auto pageDao = this->database->createPageDao();
|
|
||||||
auto revisionDao = this->database->createRevisionDao();
|
|
||||||
auto permissionDao = this->database->createPermissionsDao();
|
|
||||||
|
|
||||||
QueryOption option;
|
|
||||||
option.includeUnlisted = true;
|
|
||||||
auto members = categoryDao->fetchMembers(this->category, option);
|
|
||||||
std::vector<std::pair<std::string, time_t>> pageList;
|
|
||||||
for(const Page &member : members)
|
|
||||||
{
|
|
||||||
Permissions perms = permissionDao->find(member.name, this->userSession->user.login)
|
|
||||||
.value_or(this->userSession->user.permissions);
|
|
||||||
if(perms.canRead())
|
|
||||||
{
|
|
||||||
auto revision = revisionDao->getRevisionForPage(member.name, 1);
|
|
||||||
pageList.push_back({member.name, revision->timestamp});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::sort(pageList.begin(), pageList.end(),
|
|
||||||
[](std::pair<std::string, time_t> &a, std::pair<std::string, time_t> &b) { return a.second > b.second; });
|
|
||||||
|
|
||||||
std::string entry = this->templ->loadResolvedPart(this->templatepartname);
|
|
||||||
std::stringstream stream;
|
|
||||||
for(auto &pair : pageList)
|
|
||||||
{
|
|
||||||
std::optional<Revision> revision = revisionDao->getCurrentForPage(pair.first);
|
|
||||||
if(revision)
|
|
||||||
{
|
|
||||||
std::string link = linkToPage(pair.first);
|
|
||||||
Parser parser;
|
|
||||||
|
|
||||||
std::string date = utils::toISODateTime(revision->timestamp);
|
|
||||||
Varreplacer replacer{"{"};
|
|
||||||
replacer.addKeyValue("url", link);
|
|
||||||
replacer.addKeyValue("date", date);
|
|
||||||
replacer.addKeyValue("content", parser.parse(*pageDao, *this->urlProvider,
|
|
||||||
parser.extractFirstTag("content", revision->content)));
|
|
||||||
stream << replacer.parse(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stream.str();
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#ifndef DYNAMICPOSTRENDERER_H
|
|
||||||
#define DYNAMICPOSTRENDERER_H
|
|
||||||
#include "dynamiccontent.h"
|
|
||||||
class DynamicPostRenderer : public DynamicContent
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::string category;
|
|
||||||
std::string customlinkurl;
|
|
||||||
std::string templatepartname = "dynamic/categoryrendererentry";
|
|
||||||
|
|
||||||
public:
|
|
||||||
using DynamicContent::DynamicContent;
|
|
||||||
std::string render() override;
|
|
||||||
void setArgument(std::string argument) override;
|
|
||||||
std::string linkToPage(std::string page);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DYNAMICPOSTRENDERER_H
|
|
@ -53,7 +53,7 @@ std::string Handler::createPageTitle(std::string title)
|
|||||||
QueryOption Handler::queryOption(const Request &r, SORT_ORDER defaultSort) const
|
QueryOption Handler::queryOption(const Request &r, SORT_ORDER defaultSort) const
|
||||||
{
|
{
|
||||||
QueryOption result;
|
QueryOption result;
|
||||||
result.includeUnlisted = false;
|
result.includeInvisible = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result.limit = utils::toUInt(r.get("limit"));
|
result.limit = utils::toUInt(r.get("limit"));
|
||||||
|
@ -9,7 +9,7 @@ std::vector<HandlerFeedGenerator::EntryRevisionPair> HandlerFeedGenerator::fetch
|
|||||||
|
|
||||||
std::vector<EntryRevisionPair> result;
|
std::vector<EntryRevisionPair> result;
|
||||||
QueryOption option;
|
QueryOption option;
|
||||||
option.includeUnlisted = true;
|
option.includeInvisible = false;
|
||||||
// option.limit = 20;
|
// option.limit = 20;
|
||||||
|
|
||||||
auto comppage = [](const Page &a, const Page &b) { return a.name < b.name; };
|
auto comppage = [](const Page &a, const Page &b) { return a.name < b.name; };
|
||||||
@ -33,8 +33,6 @@ std::vector<HandlerFeedGenerator::EntryRevisionPair> HandlerFeedGenerator::fetch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(const Page &member : members)
|
for(const Page &member : members)
|
||||||
{
|
|
||||||
if(member.feedlisted)
|
|
||||||
{
|
{
|
||||||
Permissions perms = permissionDao->find(member.name, this->userSession->user.login)
|
Permissions perms = permissionDao->find(member.name, this->userSession->user.login)
|
||||||
.value_or(this->userSession->user.permissions);
|
.value_or(this->userSession->user.permissions);
|
||||||
@ -44,7 +42,6 @@ std::vector<HandlerFeedGenerator::EntryRevisionPair> HandlerFeedGenerator::fetch
|
|||||||
result.push_back({member, revision});
|
result.push_back({member, revision});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
std::sort(result.begin(), result.end(),
|
std::sort(result.begin(), result.end(),
|
||||||
[](EntryRevisionPair &a, EntryRevisionPair &b) { return a.second.timestamp > b.second.timestamp; });
|
[](EntryRevisionPair &a, EntryRevisionPair &b) { return a.second.timestamp > b.second.timestamp; });
|
||||||
|
|
||||||
|
@ -76,27 +76,10 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename,
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
this->database->beginTransaction();
|
this->database->beginTransaction();
|
||||||
|
|
||||||
std::string visiblecmd = parser.extractCommand("visible", newContent);
|
std::string visiblecmd = parser.extractCommand("visible", newContent);
|
||||||
std::string listedcmd = parser.extractCommand("listed", newContent);
|
|
||||||
/* Backwarts compatibility */
|
|
||||||
if(listedcmd.empty())
|
|
||||||
{
|
|
||||||
listedcmd = visiblecmd;
|
|
||||||
}
|
|
||||||
std::string feedlistedcmd = parser.extractCommand("feedlisted", newContent);
|
|
||||||
|
|
||||||
std::string rename = parser.extractCommand("rename", newContent);
|
std::string rename = parser.extractCommand("rename", newContent);
|
||||||
std::string customtitle = parser.extractCommand("pagetitle", newContent);
|
std::string customtitle = parser.extractCommand("pagetitle", newContent);
|
||||||
std::string parentpage = parser.extractCommand("parentpage", newContent);
|
|
||||||
std::vector<std::string> perms = parser.extractCommands("permissions", newContent);
|
std::vector<std::string> perms = parser.extractCommands("permissions", newContent);
|
||||||
|
|
||||||
if(parentpage != "" && !pageDao.find(parentpage))
|
|
||||||
{
|
|
||||||
return this->errorResponse("Invalid parent",
|
|
||||||
"Specified parent page " + parentpage + " does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
Page page;
|
Page page;
|
||||||
std::optional<Page> currentPage = pageDao.find(pagename);
|
std::optional<Page> currentPage = pageDao.find(pagename);
|
||||||
if(currentPage)
|
if(currentPage)
|
||||||
@ -148,11 +131,9 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
page.current_revision = current_revision;
|
page.current_revision = current_revision;
|
||||||
page.listed = !(listedcmd == "0");
|
page.listed = !(visiblecmd == "0");
|
||||||
page.feedlisted = !(feedlistedcmd == "0");
|
|
||||||
page.name = pagename;
|
page.name = pagename;
|
||||||
page.title = customtitle;
|
page.title = customtitle;
|
||||||
page.parentpage = parentpage;
|
|
||||||
if(page.title.empty())
|
if(page.title.empty())
|
||||||
{
|
{
|
||||||
page.title = page.name;
|
page.title = page.name;
|
||||||
|
@ -15,7 +15,6 @@ class IParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual std::string extractFirstTag(std::string tagname, const std::string &content) const = 0;
|
|
||||||
virtual std::string extractCommand(std::string cmdname, const std::string &content) const = 0;
|
virtual std::string extractCommand(std::string cmdname, const std::string &content) const = 0;
|
||||||
virtual std::vector<std::string> extractCommands(std::string cmdname, const std::string &content) const = 0;
|
virtual std::vector<std::string> extractCommands(std::string cmdname, const std::string &content) const = 0;
|
||||||
|
|
||||||
|
2
page.h
2
page.h
@ -8,9 +8,7 @@ class Page
|
|||||||
Page();
|
Page();
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string parentpage;
|
|
||||||
bool listed;
|
bool listed;
|
||||||
bool feedlisted;
|
|
||||||
unsigned int current_revision;
|
unsigned int current_revision;
|
||||||
unsigned int pageid;
|
unsigned int pageid;
|
||||||
};
|
};
|
||||||
|
20
parser.cpp
20
parser.cpp
@ -63,10 +63,11 @@ std::vector<std::string> Parser::extractCategories(const std::string &content) c
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Parser::extractFirstTag(std::string tagname, const std::string &content) const
|
std::string Parser::extractCommand(std::string cmdname, const std::string &content) const
|
||||||
{
|
{
|
||||||
std::string cmd = "[" + tagname + "]";
|
std::string cmd = "[cmd:" + cmdname + "]";
|
||||||
std::string cmdend = "[/" + tagname + "]";
|
std::string cmdend = "[/cmd:" + cmdname + "]";
|
||||||
|
|
||||||
std::string_view view = content;
|
std::string_view view = content;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
if((pos = view.find(cmd)) != std::string::npos)
|
if((pos = view.find(cmd)) != std::string::npos)
|
||||||
@ -82,12 +83,6 @@ std::string Parser::extractFirstTag(std::string tagname, const std::string &cont
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Parser::extractCommand(std::string cmdname, const std::string &content) const
|
|
||||||
{
|
|
||||||
|
|
||||||
return extractFirstTag("cmd:" + cmdname, content);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> Parser::extractCommands(std::string cmdname, const std::string &content) const
|
std::vector<std::string> Parser::extractCommands(std::string cmdname, const std::string &content) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
@ -175,7 +170,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|s|li||ul|ol|code|blockquote|img|link|wikilink|h\d|cmd:visible|cmd:listed|cmd:feedlisted|cmd:rename|cmd:redirect|cmd:pagetitle|cmd:allowinclude|cmd:permissions|cmd:parentpage|content|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1])");
|
R"(\[(b|i|u|s|li||ul|ol|code|blockquote|img|link|wikilink|h\d|cmd:visible|cmd:rename|cmd:redirect|cmd:pagetitle|cmd:allowinclude|cmd:permissions|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1])");
|
||||||
result = utils::regex_callback_replacer(
|
result = utils::regex_callback_replacer(
|
||||||
tagfinder, content,
|
tagfinder, content,
|
||||||
[&](std::smatch &match)
|
[&](std::smatch &match)
|
||||||
@ -187,11 +182,6 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
|
|||||||
{
|
{
|
||||||
content = parse(pagedao, provider, content, callback);
|
content = parse(pagedao, provider, content, callback);
|
||||||
}
|
}
|
||||||
/* [content] just helps extracting the actual content of a page, pretty much noop otherwise */
|
|
||||||
if(tag == "content")
|
|
||||||
{
|
|
||||||
return parse(pagedao, provider, content, callback);
|
|
||||||
}
|
|
||||||
if(std::find(std::begin(justreplace), std::end(justreplace), tag) != std::end(justreplace))
|
if(std::find(std::begin(justreplace), std::end(justreplace), tag) != std::end(justreplace))
|
||||||
{
|
{
|
||||||
return "<" + tag + ">" + content + "</" + tag + ">";
|
return "<" + tag + ">" + content + "</" + tag + ">";
|
||||||
|
1
parser.h
1
parser.h
@ -9,7 +9,6 @@ class Parser : public IParser
|
|||||||
std::string processImage(std::smatch &match) const;
|
std::string processImage(std::smatch &match) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string extractFirstTag(std::string tagname, const std::string &content) const override;
|
|
||||||
std::string extractCommand(std::string cmdname, const std::string &content) const override;
|
std::string extractCommand(std::string cmdname, const std::string &content) const override;
|
||||||
std::vector<std::string> extractCommands(std::string cmdname, const std::string &content) const override;
|
std::vector<std::string> extractCommands(std::string cmdname, const std::string &content) const override;
|
||||||
std::vector<Headline> extractHeadlines(const std::string &content) const override;
|
std::vector<Headline> extractHeadlines(const std::string &content) const override;
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
#include "revisionrenderer.h"
|
#include "revisionrenderer.h"
|
||||||
#include "templatepage.h"
|
#include "templatepage.h"
|
||||||
#include "dynamic/dynamiccontentpostlist.h"
|
#include "dynamic/dynamiccontentpostlist.h"
|
||||||
#include "dynamic/dynamiccontentincludepage.h"
|
#include "dynamic/dynamiccontentincludepage.h"
|
||||||
#include "dynamic/dynamiccontentgetvar.h"
|
#include "dynamic/dynamiccontentgetvar.h"
|
||||||
#include "dynamic/dynamiccontentsetvar.h"
|
#include "dynamic/dynamiccontentsetvar.h"
|
||||||
#include "dynamic/dynamicpostrenderer.h"
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "htmllink.h"
|
#include "htmllink.h"
|
||||||
|
|
||||||
@ -20,8 +19,7 @@ std::string RevisionRenderer::dynamicCallback(std::string_view key, std::string_
|
|||||||
{
|
{
|
||||||
auto includePage = this->dynamicContentFactory.createDynamicContent<DynamicContentIncludePage>();
|
auto includePage = this->dynamicContentFactory.createDynamicContent<DynamicContentIncludePage>();
|
||||||
includePage->setArgument(std::string(value));
|
includePage->setArgument(std::string(value));
|
||||||
return parser.parseDynamics(includePage->render(), std::bind(&RevisionRenderer::dynamicCallback, this,
|
return parser.parseDynamics(includePage->render(), std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
std::placeholders::_1, std::placeholders::_2));
|
|
||||||
}
|
}
|
||||||
if(key == "dynamic:setvar")
|
if(key == "dynamic:setvar")
|
||||||
{
|
{
|
||||||
@ -37,12 +35,6 @@ std::string RevisionRenderer::dynamicCallback(std::string_view key, std::string_
|
|||||||
getVar->setArgument(std::string(value));
|
getVar->setArgument(std::string(value));
|
||||||
return getVar->render();
|
return getVar->render();
|
||||||
}
|
}
|
||||||
if(key == "dynamic:postrenderer")
|
|
||||||
{
|
|
||||||
auto renderer = this->dynamicContentFactory.createDynamicContent<DynamicPostRenderer>();
|
|
||||||
renderer->setArgument(std::string(value));
|
|
||||||
return renderer->render();
|
|
||||||
}
|
|
||||||
return std::string{};
|
return std::string{};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,8 +44,7 @@ std::string RevisionRenderer::renderContent(std::string content)
|
|||||||
dynamicVarsMap["createdon"] = utils::toISODate(time(NULL));
|
dynamicVarsMap["createdon"] = utils::toISODate(time(NULL));
|
||||||
dynamicVarsMap["modifydatetime"] = utils::toISODateTime(time(NULL));
|
dynamicVarsMap["modifydatetime"] = utils::toISODateTime(time(NULL));
|
||||||
|
|
||||||
std::string resolvedContent = parser.parseDynamics(
|
std::string resolvedContent = parser.parseDynamics(content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));
|
|
||||||
|
|
||||||
return parser.parse(*this->db->createPageDao(), *this->urlProvider, resolvedContent);
|
return parser.parse(*this->db->createPageDao(), *this->urlProvider, resolvedContent);
|
||||||
}
|
}
|
||||||
@ -67,12 +58,12 @@ std::string RevisionRenderer::renderContent(const Revision &r, std::string_view
|
|||||||
throw std::runtime_error("Could not get first revision for page, which is odd. Solar flares?");
|
throw std::runtime_error("Could not get first revision for page, which is odd. Solar flares?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dynamicVarsMap["createdon"] = utils::toISODate(firstRevision.value().timestamp);
|
dynamicVarsMap["createdon"] = utils::toISODate(firstRevision.value().timestamp);
|
||||||
dynamicVarsMap["pagetitle"] = customTitle;
|
dynamicVarsMap["pagetitle"] = customTitle;
|
||||||
dynamicVarsMap["modifydatetime"] = utils::toISODateTime(r.timestamp);
|
dynamicVarsMap["modifydatetime"] = utils::toISODateTime(r.timestamp);
|
||||||
|
|
||||||
std::string resolvedContent = parser.parseDynamics(
|
std::string resolvedContent = parser.parseDynamics(r.content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
r.content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));
|
|
||||||
|
|
||||||
return parser.parse(*this->db->createPageDao(), *this->urlProvider, resolvedContent);
|
return parser.parse(*this->db->createPageDao(), *this->urlProvider, resolvedContent);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
CREATE TABLE page(id INTEGER PRIMARY KEY, name varchar(256), title varchar(1024), lastrevision integer, listed integer DEFAULT 1, parent integer REFERENCES page(id), feedlisted integer DEFAULT 1);
|
CREATE TABLE page(id INTEGER PRIMARY KEY, name varchar(256), title varchar(1024), lastrevision integer, visible integer DEFAULT 1);
|
||||||
CREATE TABLE user(id INTEGER PRIMARY KEY,username varchar(64),
|
CREATE TABLE user(id INTEGER PRIMARY KEY,username varchar(64),
|
||||||
password blob, salt blob, permissions integer, enabled integer DEFAULT 1);
|
password blob, salt blob, permissions integer, enabled integer DEFAULT 1);
|
||||||
CREATE TABLE session(id INTEGER PRIMARY KEY, csrf_token varchar(32),
|
CREATE TABLE session(id INTEGER PRIMARY KEY, csrf_token varchar(32),
|
||||||
|
11
template.cpp
11
template.cpp
@ -18,7 +18,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <filesystem>
|
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
#include "varreplacer.h"
|
#include "varreplacer.h"
|
||||||
#include "urlprovider.h"
|
#include "urlprovider.h"
|
||||||
@ -48,15 +47,9 @@ TemplatePage Template::getPage(const std::string &pagename)
|
|||||||
|
|
||||||
std::string Template::getPartPath(std::string_view partname)
|
std::string Template::getPartPath(std::string_view partname)
|
||||||
{
|
{
|
||||||
auto absolute_path = std::filesystem::canonical(std::filesystem::path{this->templatepath} / partname);
|
// TODO: utils::concatPath? C++17 paths?
|
||||||
std::string result = absolute_path.string();
|
return this->templatepath + "/" + std::string(partname);
|
||||||
if(result.starts_with(this->templatepath))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Template::loadPartContent(std::string_view partname)
|
std::string Template::loadPartContent(std::string_view partname)
|
||||||
{
|
{
|
||||||
std::string partpath = getPartPath(partname);
|
std::string partpath = getPartPath(partname);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user