Commit 150d82a3 authored by jan.koester's avatar jan.koester
Browse files

test

parent ee579b7f
Loading
Loading
Loading
Loading
+12 −10
Changes for plugins/template/template.cpp: 12 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -254,21 +254,22 @@ namespace blogi {

        json_object* settingsDelete(const int tid, libhttppp::HttpRequest &req, const std::string &_lang) {
            // Parse id from request parameters (GET/POST)
            int id = -1;
            std::string id;
            libhttppp::HttpForm form;
            form.parse(req);
            for (const auto &cdat : form.urlData()) {
                if (cdat.key == "id")
                    id = atoi(cdat.value.c_str());
                    id = cdat.value;
            }

            json_object *jroot = json_object_new_object();

            if (id > 0) {
            if (!id.empty()) {
                try {
                    std::vector<char> sbuf;
                    dbpp::SQL sql;
                    dbpp::DBResult res;
                    sql << "DELETE FROM templates WHERE id = " << id << ";";
                    sql << "DELETE FROM templates WHERE id = '" << dbpp::SQL::escaped(sbuf, id.c_str()) << "';";
                    Args->database[tid]->exec(sql, res);
                    json_object_object_add(jroot, "message", json_object_new_string(tr(_lang, "Deleted!").c_str()));
                    json_object_object_add(jroot, "message_type", json_object_new_string("success"));
@@ -294,12 +295,12 @@ namespace blogi {

        json_object* settingsEdit(const int tid, libhttppp::HttpRequest &req, const std::string &_lang) {
            // Parse id from request parameters (GET/POST)
            int id = -1;
            std::string id;
            libhttppp::HttpForm form;
            form.parse(req);
            for (const auto &cdat : form.urlData()) {
                if (cdat.key == "id")
                    id = atoi(cdat.value.c_str());
                    id = cdat.value;
            }

            // Check for form submission (POST)
@@ -319,7 +320,7 @@ namespace blogi {
                    sql << "UPDATE templates SET layer = '"
                        << dbpp::SQL::escaped(sbuf, layer.c_str()) << "', html = '"
                        << dbpp::SQL::escaped(sbuf, html.c_str()) << "', type = "
                        << type << " WHERE id = " << id << ";";
                        << type << " WHERE id = '" << dbpp::SQL::escaped(sbuf, id.c_str()) << "';";
                    try {
                        Args->database[tid]->exec(sql, res);
                        saved = true;
@@ -330,7 +331,7 @@ namespace blogi {

            json_object *jroot = json_object_new_object();
            json_object_object_add(jroot, "title", json_object_new_string(
                (tr(_lang, "Edit Template") + " #" + std::to_string(id)).c_str()));
                (tr(_lang, "Edit Template") + " #" + id).c_str()));

            if (saved) {
                json_object_object_add(jroot, "message", json_object_new_string(tr(_lang, "Saved!").c_str()));
@@ -341,9 +342,10 @@ namespace blogi {
            std::string layer, html;
            int type = 0;
            {
                std::vector<char> sbuf;
                dbpp::SQL sql;
                dbpp::DBResult res;
                sql << "SELECT layer, html, type FROM templates WHERE id = " << id << ";";
                sql << "SELECT layer, html, type FROM templates WHERE id = '" << dbpp::SQL::escaped(sbuf, id.c_str()) << "';";
                try {
                    int n = Args->database[tid]->exec(sql, res);
                    if (n > 0) {
@@ -373,7 +375,7 @@ namespace blogi {
            json_object *jform = json_object_new_object();
            json_object_object_add(jform, "method", json_object_new_string("POST"));
            json_object_object_add(jform, "action", json_object_new_string(
                (Args->config->buildurl("settings/template/edit?id=") + std::to_string(id)).c_str()));
                (Args->config->buildurl("settings/template/edit?id=") + id).c_str()));

            json_object *jfields = json_object_new_array();