forked from chookspace/chookchat
start work on like button, better html sanitisation
This commit is contained in:
@@ -1,23 +1,38 @@
|
||||
#include "post.h"
|
||||
#include <memory>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <maddy/parser.h>
|
||||
|
||||
std::regex tags("<[^<]*>");
|
||||
void replaceAll(std::string& str, const std::string& from, const std::string& to) {
|
||||
size_t start_pos = 0;
|
||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
}
|
||||
|
||||
Post::Post(const std::string& contentin, const std::string& user) : user(user), time(std::time(nullptr)) {
|
||||
Post::Post(std::string contentin, const std::string& user) : user(user), time(std::time(nullptr)) {
|
||||
replaceAll(contentin, "&", "&");
|
||||
replaceAll(contentin, "<", "<");
|
||||
replaceAll(contentin, ">", ">");
|
||||
replaceAll(contentin, "\"", """);
|
||||
replaceAll(contentin, "'", "'");
|
||||
// parse the post content markdown
|
||||
std::stringstream input(std::regex_replace(contentin, tags, ""));
|
||||
std::stringstream input(contentin);
|
||||
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
||||
content = parser->Parse(input);
|
||||
}
|
||||
|
||||
Post::Post(const std::string& contentin, uint64_t user) : userId(user), time(std::time(nullptr)) {
|
||||
Post::Post(std::string contentin, uint64_t user) : userId(user), time(std::time(nullptr)) {
|
||||
replaceAll(contentin, "&", "&");
|
||||
replaceAll(contentin, "<", "<");
|
||||
replaceAll(contentin, ">", ">");
|
||||
replaceAll(contentin, "\"", """);
|
||||
replaceAll(contentin, "'", "'");
|
||||
// parse the post content markdown
|
||||
std::stringstream input(std::regex_replace(contentin, tags, ""));
|
||||
std::stringstream input(contentin);
|
||||
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
||||
content = parser->Parse(input);
|
||||
}
|
||||
@@ -37,6 +52,10 @@ std::string Post::genHtml() const {
|
||||
ss << content;
|
||||
|
||||
ss << "<p class='postinfo'>" << likes << " likes</p>";
|
||||
ss << "<div class='post-buttons'>";
|
||||
ss << "<button onclick='like(" << id << ")'>Like</button>";
|
||||
ss << "<button onclick='" << id << "'>Open</button>";
|
||||
ss << "</div>";
|
||||
|
||||
return ss.str();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user