Commit 55b42a18 authored by jan.koester's avatar jan.koester
Browse files

test

parent 8dd6cea9
Loading
Loading
Loading
Loading
+23 −13
Changes for plugins/content/content.cpp: 23 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -511,9 +511,9 @@ namespace blogi {
                throw exp;
            }

            // Verify post exists
            // Verify post exists and get slug
            dbpp::SQL vsql; dbpp::DBResult vres;
            vsql << "SELECT id FROM content WHERE id=" << cid << " LIMIT 1;";
            vsql << "SELECT id,slug FROM content WHERE id=" << cid << " LIMIT 1;";
            if(Args->database[tid]->exec(vsql, vres) < 1){
                libhttppp::HTTPException exp;
                exp[libhttppp::HTTPException::Error] << "Post not found!";
@@ -666,7 +666,7 @@ namespace blogi {
                condat << "<div id=\"content\"><p class=\"comment_pending\">"
                       << tr(_lang,"Comment submitted. It will appear after moderation.") << "</p></div>";
            }
            condat << "<a class=\"back_content\" href=\"" << Args->config->buildurl("content/read/") << cid << "\">"
            condat << "<a class=\"back_content\" href=\"" << Args->config->buildurl("content/read/") << vres[0][1] << "\">"
                   << tr(_lang,"Back to post") << "</a>";

            libhtmlpp::HtmlElement *main = page.getElementbyID("main");
@@ -701,17 +701,17 @@ namespace blogi {
                       << tr(_lang,"Invalid verification link.") << "</p></div>";
            } else {
                dbpp::SQL vsql; dbpp::DBResult vres;
                vsql << "SELECT id,content_id FROM comments WHERE verify_token='" << dbpp::SQL::escaped(sbuf, token.c_str()) << "' AND email_verified=false LIMIT 1;";
                vsql << "SELECT comments.id,comments.content_id,content.slug FROM comments JOIN content ON content.id=comments.content_id WHERE comments.verify_token='" << dbpp::SQL::escaped(sbuf, token.c_str()) << "' AND comments.email_verified=false LIMIT 1;";
                int vcount = Args->database[tid]->exec(vsql, vres);
                if(vcount > 0){
                    int cmtId = atoi(vres[0][0]);
                    int contentId = atoi(vres[0][1]);
                    std::string contentSlug = vres[0][2];
                    dbpp::SQL usql; dbpp::DBResult ures;
                    usql << "UPDATE comments SET email_verified=true, verify_token=NULL WHERE id=" << cmtId << ";";
                    Args->database[tid]->exec(usql, ures);
                    condat << "<div id=\"content\"><p class=\"comment_success\">"
                           << tr(_lang,"Email verified! Your comment will be published after moderation.") << "</p></div>"
                           << "<a class=\"back_content\" href=\"" << Args->config->buildurl("content/read/") << contentId << "\">" << tr(_lang,"Back to post") << "</a>";
                           << "<a class=\"back_content\" href=\"" << Args->config->buildurl("content/read/") << contentSlug << "\">" << tr(_lang,"Back to post") << "</a>";
                } else {
                    condat << "<div id=\"content\"><p class=\"comment_error\">"
                           << tr(_lang,"Verification link is invalid or has already been used.") << "</p></div>";
@@ -818,8 +818,10 @@ namespace blogi {
                } catch (const libhttppp::HTTPException& excep) {
                    throw excep;
                }
                sql << "INSERT INTO content (title,descrition,text,author,created) VALUES ('" <<
                std::string slug = makeSlug(title.data());
                sql << "INSERT INTO content (title,slug,descrition,text,author,created) VALUES ('" <<
                dbpp::SQL::escaped(sbuf,title.data()) << "','" <<
                dbpp::SQL::escaped(sbuf,slug.c_str()) << "','" <<
                dbpp::SQL::escaped(sbuf,description.data()) <<"','" <<
                dbpp::SQL::escaped(sbuf,text.data()) <<"','"<< author <<"','" << time_str.c_str() << "') RETURNING id;";

@@ -871,7 +873,7 @@ namespace blogi {
                }

                std::stringstream ccurl;
                ccurl << Args->config->getprefix() << "/content/read/" << content_id;
                ccurl << Args->config->getprefix() << "/content/read/" << slug;

                libhttppp::HttpResponse resp;
                resp.setState(HTTP307);
@@ -1159,9 +1161,11 @@ namespace blogi {
                }

                if (!text.empty() && !title.empty() && !descrition.empty()) {
                    std::string slug = makeSlug(title.c_str());
                    dbpp::SQL sqltext;
                    sqltext << "UPDATE content SET title='" <<
                    dbpp::SQL::escaped(sbuf,title.c_str()) << "',descrition='" <<
                    dbpp::SQL::escaped(sbuf,title.c_str()) << "',slug='" <<
                    dbpp::SQL::escaped(sbuf,slug.c_str()) << "',descrition='" <<
                    dbpp::SQL::escaped(sbuf,descrition.c_str()) << "',text='" <<
                    dbpp::SQL::escaped(sbuf,text.c_str())  << "' where id='" << cid << "';";

@@ -1469,7 +1473,9 @@ namespace blogi {
                        if(saving && !newTitle.empty()){
                            std::vector<char> sbuf;
                            dbpp::SQL usql; dbpp::DBResult ures;
                            std::string slug = makeSlug(newTitle.c_str());
                            usql << "UPDATE content SET title='" << dbpp::SQL::escaped(sbuf,newTitle.c_str())
                                 << "',slug='" << dbpp::SQL::escaped(sbuf,slug.c_str())
                                 << "',descrition='" << dbpp::SQL::escaped(sbuf,newDesc.c_str())
                                 << "',text='" << dbpp::SQL::escaped(sbuf,newText.c_str())
                                 << "' WHERE id='" << cid << "';";
@@ -1883,7 +1889,7 @@ namespace blogi {
            dbpp::SQL sql;
            dbpp::DBResult res;

            sql << "SELECT title,descrition,id FROM content WHERE title @@ to_tsquery('"
            sql << "SELECT title,descrition,slug FROM content WHERE title @@ to_tsquery('"
                  << sql.escaped(buf,word)
                  <<"') OR descrition @@ to_tsquery('"
                  << sql.escaped(buf,word)
@@ -2065,7 +2071,9 @@ namespace blogi {
                    // Overwrite existing post
                    content_id = atoi(res[0][0]);
                    sql.clear();
                    sql << "UPDATE content SET descrition='" << dbpp::SQL::escaped(sbuf, description.c_str())
                    std::string slug = makeSlug(title.c_str());
                    sql << "UPDATE content SET slug='" << dbpp::SQL::escaped(sbuf, slug.c_str())
                        << "', descrition='" << dbpp::SQL::escaped(sbuf, description.c_str())
                        << "', text='" << dbpp::SQL::escaped(sbuf, html.c_str())
                        << "', author='" << authorId
                        << "', created='" << time_str.c_str()
@@ -2079,8 +2087,10 @@ namespace blogi {
                } else {
                    // New post
                    sql.clear();
                    sql << "INSERT INTO content (title,descrition,text,author,created) VALUES ('"
                    std::string slug = makeSlug(title.c_str());
                    sql << "INSERT INTO content (title,slug,descrition,text,author,created) VALUES ('"
                        << dbpp::SQL::escaped(sbuf, title.c_str()) << "','"
                        << dbpp::SQL::escaped(sbuf, slug.c_str()) << "','"
                        << dbpp::SQL::escaped(sbuf, description.c_str()) << "','"
                        << dbpp::SQL::escaped(sbuf, html.c_str()) << "','" << authorId << "','"
                        << time_str.c_str() << "') RETURNING id;";
@@ -2118,7 +2128,7 @@ namespace blogi {

                json_object_object_add(response, "status", json_object_new_string("success"));
                json_object_object_add(response, "message", json_object_new_string(tr(_lang,"Content published successfully.").c_str()));
                std::string url = Args->config->getprefix() + "/content/read/" + std::to_string(content_id);
                std::string url = Args->config->getprefix() + "/content/read/" + slug;
                json_object_object_add(response, "url", json_object_new_string(url.c_str()));
            } catch (std::exception &e) {
                json_object_object_add(response, "status", json_object_new_string("error"));