#include "post.h" #include #include #include #include #include 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(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(contentin); std::shared_ptr parser = std::make_shared(); content = parser->Parse(input); } 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(contentin); std::shared_ptr parser = std::make_shared(); content = parser->Parse(input); } std::string Post::genHtml() const { std::stringstream ss; ss << "
\n"; // do time char buf[256]; struct tm ts; ts = *localtime(&time); strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts); ss << "\n"; ss << content; ss << ""; ss << "
"; ss << ""; ss << ""; ss << "
"; return ss.str(); }