Commit 2b072778 authored by jan.koester's avatar jan.koester
Browse files

test

parent 8187dcfa
Loading
Loading
Loading
Loading
+26 −42
Changes for plugins/template/template.cpp: 26 added lines, 42 removed lines.
Original line number Diff line number Diff line
@@ -77,22 +77,13 @@ namespace blogi {
            std::string url = req.getRequestURL();
            std::string base = Args->config->buildurl("settings/template/");

            // Sub-routing
            if (url.find(base) != std::string::npos && url.length() > base.length()) {
            // Sub-routing (like survey plugin pattern)
            if (url.length() > base.length()) {
                std::string sub = url.substr(base.length());
                // Parse query string
                std::string path = sub;
                std::string query;
                auto qpos = sub.find('?');
                if (qpos != std::string::npos) {
                    path = sub.substr(0, qpos);
                    query = sub.substr(qpos + 1);
                }

                if (path == "delete") {
                    return settingsDelete(tid, req, _lang, query);
                } else if (path == "edit") {
                    return settingsEdit(tid, req, _lang, query);
                if (sub.find("delete") == 0) {
                    return settingsDelete(tid, req, _lang);
                } else if (sub.find("edit") == 0) {
                    return settingsEdit(tid, req, _lang);
                }
            }

@@ -201,14 +192,14 @@ namespace blogi {
            for (int i = 0; i < n; ++i) {
                json_object *jrow = json_object_new_object();
                json_object *jcells = json_object_new_array();
                json_object_array_add(jcells, json_object_new_string(res[i][0]));
                json_object_array_add(jcells, json_object_new_string(res[i][1]));
                json_object_array_add(jcells, json_object_new_string(res[i][0] ? res[i][0] : ""));
                json_object_array_add(jcells, json_object_new_string(res[i][1] ? res[i][1] : ""));

                int devType = atoi(res[i][2]);
                int devType = res[i][2] ? atoi(res[i][2]) : 0;
                const char *devLabel = devType == 1 ? "Desktop" : devType == 2 ? "Mobile" : "All";
                json_object_array_add(jcells, json_object_new_string(tr(_lang, devLabel).c_str()));

                int htmlLen = atoi(res[i][3]);
                int htmlLen = res[i][3] ? atoi(res[i][3]) : 0;
                std::string sizeStr = htmlLen > 0 ? (std::to_string(htmlLen) + " Bytes") : tr(_lang, "Empty");
                json_object_array_add(jcells, json_object_new_string(sizeStr.c_str()));

@@ -249,20 +240,18 @@ namespace blogi {
            return jroot;
        }

        json_object* settingsDelete(const int tid, libhttppp::HttpRequest &req, const std::string &_lang, const std::string &query) {
            // Parse id from query
            std::string idStr;
            auto p = query.find("id=");
            if (p != std::string::npos) {
                idStr = query.substr(p + 3);
                auto amp = idStr.find('&');
                if (amp != std::string::npos) idStr = idStr.substr(0, amp);
        json_object* settingsDelete(const int tid, libhttppp::HttpRequest &req, const std::string &_lang) {
            // Parse id from request parameters (GET/POST)
            int id = -1;
            libhttppp::HttpForm form;
            form.parse(req);
            for (const auto &cdat : form.urlData()) {
                if (cdat.key == "id")
                    id = atoi(cdat.value.c_str());
            }

            json_object *jroot = json_object_new_object();

            if (!idStr.empty()) {
                int id = atoi(idStr.c_str());
            if (id > 0) {
                try {
                    dbpp::SQL sql;
@@ -276,7 +265,6 @@ namespace blogi {
                    json_object_object_add(jroot, "message_type", json_object_new_string("error"));
                }
            }
            }

            // Show list after delete
            json_object *idx = settingsIndex(tid, req, _lang);
@@ -292,21 +280,17 @@ namespace blogi {
            return idx;
        }

        json_object* settingsEdit(const int tid, libhttppp::HttpRequest &req, const std::string &_lang, const std::string &query) {
            // Parse id from query
            std::string idStr;
            auto p = query.find("id=");
            if (p != std::string::npos) {
                idStr = query.substr(p + 3);
                auto amp = idStr.find('&');
                if (amp != std::string::npos) idStr = idStr.substr(0, amp);
        json_object* settingsEdit(const int tid, libhttppp::HttpRequest &req, const std::string &_lang) {
            // Parse id from request parameters (GET/POST)
            int id = -1;
            libhttppp::HttpForm form;
            form.parse(req);
            for (const auto &cdat : form.urlData()) {
                if (cdat.key == "id")
                    id = atoi(cdat.value.c_str());
            }

            int id = atoi(idStr.c_str());

            // Check for form submission (POST)
            libhttppp::HttpForm form;
            form.parse(req);
            bool saved = false;
            for (const auto &cur : form.urlData()) {
                if (cur.key == "tpl_layer") {