Commit 52f0df67 authored by jan.koester's avatar jan.koester
Browse files

test

parent 7a6a0d7f
Loading
Loading
Loading
Loading
+55 −0
Changes for plugins/contact/contact.cpp: 55 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -46,17 +46,72 @@
#include <blogi.h>
#include <i18n.h>

#include <json-c/json.h>

namespace blogi {
    class Contact : public PluginApi{
    public:

        void initPlugin(){

            try {
                getConfig(*Args->database[0],"CONTACTMAIL",_Receiver);
            } catch(...) {}

            std::cout << "contact plugin loaded" <<std::endl;
        }

        bool haveSettings(){
            return true;
        }

        json_object* Settings(const int tid,libhttppp::HttpRequest &req,const std::string &sessionid){
            std::string _lang = getLang(*Args->database[tid]);
            bool saved = false;

            libhttppp::HttpForm form;
            form.parse(req);

            for(const auto &cur : form.urlData()){
                if(cur.key=="contactmail"){
                    setConfig(*Args->database[tid],"CONTACTMAIL",cur.value);
                    saved = true;
                }
            }

            if(saved){
                try { getConfig(*Args->database[tid],"CONTACTMAIL",_Receiver); } catch(...){}
            }

            json_object *jroot = json_object_new_object();
            json_object_object_add(jroot, "title", json_object_new_string(tr(_lang,"Contact Settings").c_str()));

            if(saved){
                json_object_object_add(jroot, "message", json_object_new_string(tr(_lang,"Saved!").c_str()));
                json_object_object_add(jroot, "message_type", json_object_new_string("success"));
            }

            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/contact").c_str()));

            json_object *jfields = json_object_new_array();

            json_object *jf = json_object_new_object();
            json_object_object_add(jf, "name", json_object_new_string("contactmail"));
            json_object_object_add(jf, "label", json_object_new_string(tr(_lang,"Receiver Email").c_str()));
            json_object_object_add(jf, "type", json_object_new_string("text"));
            json_object_object_add(jf, "value", json_object_new_string(_Receiver.c_str()));
            json_object_array_add(jfields, jf);

            json_object_object_add(jform, "fields", jfields);
            json_object_object_add(jform, "submit", json_object_new_string(tr(_lang,"save").c_str()));
            json_object_object_add(jroot, "form", jform);

            return jroot;
        }

        bool Controller(const int tid,libhttppp::HttpRequest &req,libhtmlpp::HtmlElement *page,const std::string &sessionid){
            libhttppp::HttpForm curform;
            curform.parse(req);
+2 −0
Changes for src/translations.h: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -324,6 +324,8 @@ namespace blogi {
            {"I18N_CUSTOM_COLOR",        "Eigene Farbe"},
            {"I18N_THEME_VARIABLE",      "Theme-Variable"},
            // Plugin: contact
            {"Contact Settings",     "Kontakt Einstellungen"},
            {"Receiver Email",       "Empf&auml;nger E-Mail"},
            {"Mail sent!",           "Mail versandt!"},
            {"Name:",                "Name:"},
            {"Email:",               "Email:"},