Commit 8139712c authored by jan.koester's avatar jan.koester
Browse files

test

parent 2c3ecdbf
Loading
Loading
Loading
Loading
+23 −22
Changes for plugins/staticpage/static.cpp: 23 added lines, 22 removed lines.
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ void blogi::StaticPage::initPlugin(){
    dbpp::SQL sql;
    dbpp::DBResult res;
    sql << "CREATE TABLE IF NOT EXISTS static_content ("
        << "id integer PRIMARY KEY " << Args->database[0]->autoincrement(sql) << ","
        << "id uuid PRIMARY KEY,"
        << "text text,"
        << "meta text,"
        << "url character varying(255) NOT NULL UNIQUE"
@@ -151,7 +151,11 @@ void blogi::StaticPage::newPage(const int tid,libhttppp::HttpRequest& req, libht
    }catch(...){};

    if(!surl.empty() && ( !text.empty() && text.validate(&err) ) ){
        sql << "INSERT INTO static_content (url,meta,text) VALUES('"
        uuid::uuid id;
        id.generate();

        sql << "INSERT INTO static_content (id,url,meta,text) VALUES('"
            << "'" << id.c_str() << "',"
            << sql.escaped(sbuf,surl.c_str()) << "','"
            << sql.escaped(sbuf,meta.c_str()) << "','"
            << sql.escaped(sbuf,text.c_str()) <<"');";
@@ -182,7 +186,7 @@ void blogi::StaticPage::newPage(const int tid,libhttppp::HttpRequest& req, libht

void blogi::StaticPage::delPage(const int tid,libhttppp::HttpRequest& req, libhtmlpp::HtmlString& setdiv){
    char url[512];
    int id=-1;
    uuid::uuid id;
    dbpp::SQL sql;
    dbpp::DBResult res;

@@ -201,7 +205,7 @@ void blogi::StaticPage::delPage(const int tid,libhttppp::HttpRequest& req, libht
                    throw excep;
                }
            }
            id=atoi(cdat->getValue().c_str());
            id.parse(cdat->getValue().c_str());
        }else if(cdat->getKey()=="confirmed"){
            if(cdat->getValue()=="true")
                confirmed=true;
@@ -209,19 +213,19 @@ void blogi::StaticPage::delPage(const int tid,libhttppp::HttpRequest& req, libht
    }

    if(confirmed){
        sql << "DELETE FROM static_content WHERE id='" << id << "'";
        sql << "DELETE FROM static_content WHERE id='" << id.c_str() << "'";
        Args->database[tid]->exec(sql,res);
        setdiv << "<div id=\"staticsettings\"><span>page with id " << id << " is removed !</span></div>";
        setdiv << "<div id=\"staticsettings\"><span>page with id " << id.c_str() << " is removed !</span></div>";
    }else{
        setdiv << "<div id=\"staticsettings\"><span>You wan't remove the page with id " << id << "?</span><br>"
               << "<a href=\"" << Args->config->buildurl("settings/staticpage/delpage?",url,512) << "pageid=" << id << "&confirmed=true\">Yes</a><a href=\"" << Args->config->buildurl("settings/staticpage",url,512) << "\"> NO </a>"
        setdiv << "<div id=\"staticsettings\"><span>You wan't remove the page with id " << id.c_str() << "?</span><br>"
               << "<a href=\"" << Args->config->buildurl("settings/staticpage/delpage?",url,512) << "pageid=" << id.c_str() << "&confirmed=true\">Yes</a><a href=\"" << Args->config->buildurl("settings/staticpage",url,512) << "\"> NO </a>"
               << "</div>";
    }
}

void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libhtmlpp::HtmlString& setdiv){
    char url[512];
    int id=-1;
    uuid::uuid id;
    dbpp::SQL sql;
    dbpp::DBResult res;
    std::vector<char> sbuf;
@@ -247,13 +251,13 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh
                    std::copy(curformdat->Value.begin(),curformdat->Value.end(),
                              std::inserter<std::vector<char>>(buf,buf.begin()));
                    buf.push_back('\0');
                    id=atoi(buf.data());
                    id.parse(buf.data());
                }
            }
        }


        if(id>=0){
        if(!id.empty()){
            for (libhttppp::HttpForm::MultipartForm::Data* curformdat = form.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) {
                for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition* curctdisp = curformdat->getDisposition(); curctdisp; curctdisp=curctdisp->nextContentDisposition()){

@@ -267,12 +271,12 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh

                    if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"url")==0){
                        libhtmlpp::HtmlEncode(data.data(),&result);
                        sql<< "update static_content set url='" << result.c_str() << "' where id='" << id <<"'; ";
                        sql<< "update static_content set url='" << result.c_str() << "' where id='" << id.c_str() <<"'; ";
                    }else if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"meta")==0){
                        libhtmlpp::HtmlEncode(data.data(),&result);
                        sql<< "update static_content set meta='" << result.c_str() << "' where id='" << id <<"'; ";
                        sql<< "update static_content set meta='" << result.c_str() << "' where id='" << id.c_str()  <<"'; ";
                    }else if(std::equal(curctdisp->getValue().begin(),curctdisp->getValue().end(),"text")==0){
                        sql<< "update static_content set text='"<< sql.escaped(sbuf,data.data()) << "' where id='" << id <<"'; ";
                        sql<< "update static_content set text='"<< sql.escaped(sbuf,data.data()) << "' where id='" << id.c_str()  <<"'; ";
                    }
                }
            }
@@ -280,11 +284,7 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh
                Args->database[tid]->exec(sql,res);
                sql.clear();
            }
        }
    }catch(...){};

    if(id<0){

        }else{
            for(libhttppp::HttpForm::UrlcodedForm::Data *cdat=form.UrlFormData.getFormData(); cdat; cdat=cdat->nextData()){
                if(cdat->getKey()=="pageid"){
                    size_t pgidlen=cdat->getValue().length();
@@ -295,18 +295,19 @@ void blogi::StaticPage::editPage(const int tid,libhttppp::HttpRequest& req, libh
                            throw excep;
                        }
                    }
                id=atoi(cdat->getValue().c_str());
                    id.parse(cdat->getValue());
                }
            }

        if(id<0){
            if(id.empty()){
                libhttppp::HTTPException excep;
                excep[libhttppp::HTTPException::Error] << "Staticpage with this id not found!";
                throw excep;
            }
        }
    }catch(...){};

    sql << "select id,url,meta,text from static_content where id='"; sql << id << "' LIMIT 1";
    sql << "select id,url,meta,text from static_content where id='"; sql << id.c_str() << "' LIMIT 1";

    if(Args->database[tid]->exec(sql,res)<1){
        return;