Loading plugins/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -3,3 +3,4 @@ add_subdirectory(gameinfo) add_subdirectory(content) add_subdirectory(nodeinfo) add_subdirectory(youtube) add_subdirectory(navbar) plugins/content/content.cpp +32 −17 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ namespace blogi { ~Content(){ }; void contentIdxPage(netplus::con *curcon,libhttppp::HttpRequest *curreq,const char *tag,int start,int end){ void contentIdxPage(netplus::con *curcon,libhttppp::HttpRequest *curreq,libhtmlpp::HtmlElement &page,const char *tag,int start,int end){ libhttppp::HTTPException excep; libhtmlpp::HtmlString condat; Loading Loading @@ -133,7 +133,10 @@ namespace blogi { condat << "</ul></div>"; } std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid),meta.c_str()); page.getElementbyID("main")->insertChild(condat.parse());; Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid),meta.c_str()); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading @@ -142,7 +145,7 @@ namespace blogi { resp.send(curcon,out.c_str(),out.length()); }; void contentPage(netplus::con* curcon, libhttppp::HttpRequest* curreq) { void contentPage(netplus::con* curcon, libhttppp::HttpRequest* curreq,libhtmlpp::HtmlElement &page) { libhttppp::HTTPException excep; libhtmlpp::HtmlString condat; Loading Loading @@ -180,7 +183,10 @@ namespace blogi { << "</div></div>"; std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid)); page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid)); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading @@ -189,7 +195,7 @@ namespace blogi { resp.send(curcon,out.c_str(),out.length()); }; void addPostPage(netplus::con *curcon,libhttppp::HttpRequest *curreq){ void addPostPage(netplus::con *curcon,libhttppp::HttpRequest *curreq,libhtmlpp::HtmlElement &page){ std::string sid; char url[512]; Loading Loading @@ -321,7 +327,10 @@ namespace blogi { << "</div>"; std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid)); page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid)); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading @@ -330,7 +339,7 @@ namespace blogi { resp.send(curcon,out.c_str(),out.length()); } void delPostPage(netplus::con* curcon, libhttppp::HttpRequest* curreq) { void delPostPage(netplus::con* curcon, libhttppp::HttpRequest* curreq,libhtmlpp::HtmlElement &page) { std::string sid; char url[512]; Loading Loading @@ -365,7 +374,10 @@ namespace blogi { condat << "<span>Beitrag geloescht</span>"; std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid)); page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid)); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading Loading @@ -413,7 +425,7 @@ namespace blogi { } } void editPostPage(netplus::con* curcon, libhttppp::HttpRequest* curreq) { void editPostPage(netplus::con* curcon, libhttppp::HttpRequest* curreq,libhtmlpp::HtmlElement &page) { std::string sid; char url[512]; if (!Args->auth->isLoggedIn(curreq,sid)) { Loading Loading @@ -554,7 +566,10 @@ namespace blogi { << "</div>"; }; std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid)); page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid)); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading @@ -579,7 +594,7 @@ namespace blogi { return; } bool Controller(netplus::con * curcon, libhttppp::HttpRequest * req){ bool Controller(netplus::con * curcon, libhttppp::HttpRequest * req,libhtmlpp::HtmlElement &page){ char url[512]; if(strncmp(req->getRequestURL(),Args->config->buildurl("content",url,512),strlen(Args->config->buildurl("content",url,125)))!=0){ return false; Loading @@ -594,13 +609,13 @@ namespace blogi { } if (strncmp(curl.c_str(),Args->config->buildurl("content/addpost",url,512),strlen(Args->config->buildurl("content/addpost",url,512)))==0){ addPostPage(curcon,req); addPostPage(curcon,req,page); }else if (strncmp(curl.c_str(), Args->config->buildurl("content/read",url,512), strlen(Args->config->buildurl("content/read",url,512))) == 0) { contentPage(curcon,req); contentPage(curcon,req,page); }else if (strncmp(curl.c_str(), Args->config->buildurl("content/edit",url,512), strlen(Args->config->buildurl("content/edit",url,512))) == 0) { editPostPage(curcon,req); editPostPage(curcon,req,page); }else if (strncmp(curl.c_str(), Args->config->buildurl("content/del",url,512), strlen(Args->config->buildurl("content/del",url,512))) == 0) { delPostPage(curcon, req); delPostPage(curcon, req,page); }else if (strstr(req->getRequestURL(),"robots.txt")){ const char *robot = "User-agent: Googlebot\r\n\r\nUser-agent: *\r\nAllow: /"; libhttppp::HttpResponse resp; Loading @@ -621,9 +636,9 @@ namespace blogi { std::cerr << startpos << std::endl; if (strcmp(curl.c_str(),Args->config->buildurl("content/tag",url,512))>0){ size_t len = strlen(Args->config->buildurl("content/tag/",url,512)); contentIdxPage(curcon,req,curl.substr(len,curl.length()-len).c_str(),startpos,SITELIMIT); contentIdxPage(curcon,req,page,curl.substr(len,curl.length()-len).c_str(),startpos,SITELIMIT); }else{ contentIdxPage(curcon,req,nullptr,startpos,SITELIMIT); contentIdxPage(curcon,req,page,nullptr,startpos,SITELIMIT); } } return true; Loading plugins/gameinfo/gameinfo.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ namespace blogi { } } bool Controller(netplus::con *curcon,libhttppp::HttpRequest *req){ bool Controller(netplus::con *curcon,libhttppp::HttpRequest *req,libhtmlpp::HtmlElement &page){ char url[512]; if(strncmp(req->getRequestURL(),Args->config->buildurl("gamestatus",url,512),strlen(Args->config->buildurl("gamestatus",url,512)))!=0){ return false; Loading Loading @@ -114,8 +114,9 @@ namespace blogi { condat << "</div>"; std::string out,sid; page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->RenderSite(out,req->getRequestURL(),condat, Args->theme->printSite(out,page,req->getRequestURL(), Args->auth->isLoggedIn(req,sid)); libhttppp::HttpResponse resp; Loading plugins/navbar/CMakeLists.txt 0 → 100644 +5 −0 Original line number Diff line number Diff line add_library(navbar SHARED navbar.cpp) target_link_libraries(navbar dl blogidev) install (TARGETS navbar DESTINATION lib/blogi/plugins) plugins/navbar/navbar.cpp 0 → 100644 +120 −0 Original line number Diff line number Diff line /******************************************************************************* * Copyright (c) 2023, Jan Koester jan.koester@gmx.net * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <cstring> #include <string> #include "plugin.h" #include "database.h" #include "theme.h" #include "conf.h" namespace blogi { class Navbar : public PluginApi { public: Navbar(){ Navigation = new libhtmlpp::HtmlElement(); } ~Navbar(){ delete Navigation; } const char* getName(){ return "navbar"; } const char* getVersion(){ return "0.1"; } const char* getAuthor(){ return "Jan Koester"; } void initPlugin(){ return; } void Rendering(libhtmlpp::HtmlElement* curpage){ blogi::SQL sql; blogi::DBResult res; sql << "select url,name from navbar ORDER BY id"; int n = Args->database->exec(&sql,res); if(n<1){ libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Critical] << "No entries found for navbar"; throw excep; } libhtmlpp::HtmlString buf; buf << "<div id=\"navbar\">" << "<ul>"; for (int i = 0; i < n; i++) { buf << "<li "; buf << "class=\"inactive\""; buf << "><a href=\"" << res[i][0] << "\">" << res[i][1] << "</a></li>"; } //<li class=\"active\" style=\"padding:1px 10px; float:left\"><a href=\"" << _Config.config->buildurl(index,url,512) <<"\">Blog</a></li> buf << "</ul></div>"; Navigation->appendChild(buf.parse()); Args->theme->Rendering(curpage,"header",Navigation); } bool haveSettings(){ return true; } void Settings(libhttppp::HttpRequest *req,libhtmlpp::HtmlString &setdiv){ setdiv << "<div id=\"navsettings\"><span>Navbar Settings</span></div>"; } bool Controller(netplus::con *curcon,libhttppp::HttpRequest *req){ std::string turl=req->getRequestURL(); if(turl.rfind('?')>0){ turl=turl.substr(0,turl.rfind('?')); } // if(turl.compare(0,strlen(res[i][0]),res[i][0]) == 0 ) // // buf << "class=\"active\""; // else // return false; } private: libhtmlpp::HtmlElement *Navigation; }; }; extern "C" blogi::PluginApi* create() { return new blogi::Navbar(); } extern "C" void destroy(blogi::PluginApi* p) { delete p; } Loading
plugins/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -3,3 +3,4 @@ add_subdirectory(gameinfo) add_subdirectory(content) add_subdirectory(nodeinfo) add_subdirectory(youtube) add_subdirectory(navbar)
plugins/content/content.cpp +32 −17 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ namespace blogi { ~Content(){ }; void contentIdxPage(netplus::con *curcon,libhttppp::HttpRequest *curreq,const char *tag,int start,int end){ void contentIdxPage(netplus::con *curcon,libhttppp::HttpRequest *curreq,libhtmlpp::HtmlElement &page,const char *tag,int start,int end){ libhttppp::HTTPException excep; libhtmlpp::HtmlString condat; Loading Loading @@ -133,7 +133,10 @@ namespace blogi { condat << "</ul></div>"; } std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid),meta.c_str()); page.getElementbyID("main")->insertChild(condat.parse());; Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid),meta.c_str()); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading @@ -142,7 +145,7 @@ namespace blogi { resp.send(curcon,out.c_str(),out.length()); }; void contentPage(netplus::con* curcon, libhttppp::HttpRequest* curreq) { void contentPage(netplus::con* curcon, libhttppp::HttpRequest* curreq,libhtmlpp::HtmlElement &page) { libhttppp::HTTPException excep; libhtmlpp::HtmlString condat; Loading Loading @@ -180,7 +183,10 @@ namespace blogi { << "</div></div>"; std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid)); page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid)); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading @@ -189,7 +195,7 @@ namespace blogi { resp.send(curcon,out.c_str(),out.length()); }; void addPostPage(netplus::con *curcon,libhttppp::HttpRequest *curreq){ void addPostPage(netplus::con *curcon,libhttppp::HttpRequest *curreq,libhtmlpp::HtmlElement &page){ std::string sid; char url[512]; Loading Loading @@ -321,7 +327,10 @@ namespace blogi { << "</div>"; std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid)); page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid)); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading @@ -330,7 +339,7 @@ namespace blogi { resp.send(curcon,out.c_str(),out.length()); } void delPostPage(netplus::con* curcon, libhttppp::HttpRequest* curreq) { void delPostPage(netplus::con* curcon, libhttppp::HttpRequest* curreq,libhtmlpp::HtmlElement &page) { std::string sid; char url[512]; Loading Loading @@ -365,7 +374,10 @@ namespace blogi { condat << "<span>Beitrag geloescht</span>"; std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid)); page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid)); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading Loading @@ -413,7 +425,7 @@ namespace blogi { } } void editPostPage(netplus::con* curcon, libhttppp::HttpRequest* curreq) { void editPostPage(netplus::con* curcon, libhttppp::HttpRequest* curreq,libhtmlpp::HtmlElement &page) { std::string sid; char url[512]; if (!Args->auth->isLoggedIn(curreq,sid)) { Loading Loading @@ -554,7 +566,10 @@ namespace blogi { << "</div>"; }; std::string out; Args->theme->RenderSite(out,curreq->getRequestURL(),condat,Args->auth->isLoggedIn(curreq,sid)); page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->printSite(out,page,curreq->getRequestURL(),Args->auth->isLoggedIn(curreq,sid)); libhttppp::HttpResponse resp; resp.setVersion(HTTPVERSION(1.1)); Loading @@ -579,7 +594,7 @@ namespace blogi { return; } bool Controller(netplus::con * curcon, libhttppp::HttpRequest * req){ bool Controller(netplus::con * curcon, libhttppp::HttpRequest * req,libhtmlpp::HtmlElement &page){ char url[512]; if(strncmp(req->getRequestURL(),Args->config->buildurl("content",url,512),strlen(Args->config->buildurl("content",url,125)))!=0){ return false; Loading @@ -594,13 +609,13 @@ namespace blogi { } if (strncmp(curl.c_str(),Args->config->buildurl("content/addpost",url,512),strlen(Args->config->buildurl("content/addpost",url,512)))==0){ addPostPage(curcon,req); addPostPage(curcon,req,page); }else if (strncmp(curl.c_str(), Args->config->buildurl("content/read",url,512), strlen(Args->config->buildurl("content/read",url,512))) == 0) { contentPage(curcon,req); contentPage(curcon,req,page); }else if (strncmp(curl.c_str(), Args->config->buildurl("content/edit",url,512), strlen(Args->config->buildurl("content/edit",url,512))) == 0) { editPostPage(curcon,req); editPostPage(curcon,req,page); }else if (strncmp(curl.c_str(), Args->config->buildurl("content/del",url,512), strlen(Args->config->buildurl("content/del",url,512))) == 0) { delPostPage(curcon, req); delPostPage(curcon, req,page); }else if (strstr(req->getRequestURL(),"robots.txt")){ const char *robot = "User-agent: Googlebot\r\n\r\nUser-agent: *\r\nAllow: /"; libhttppp::HttpResponse resp; Loading @@ -621,9 +636,9 @@ namespace blogi { std::cerr << startpos << std::endl; if (strcmp(curl.c_str(),Args->config->buildurl("content/tag",url,512))>0){ size_t len = strlen(Args->config->buildurl("content/tag/",url,512)); contentIdxPage(curcon,req,curl.substr(len,curl.length()-len).c_str(),startpos,SITELIMIT); contentIdxPage(curcon,req,page,curl.substr(len,curl.length()-len).c_str(),startpos,SITELIMIT); }else{ contentIdxPage(curcon,req,nullptr,startpos,SITELIMIT); contentIdxPage(curcon,req,page,nullptr,startpos,SITELIMIT); } } return true; Loading
plugins/gameinfo/gameinfo.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ namespace blogi { } } bool Controller(netplus::con *curcon,libhttppp::HttpRequest *req){ bool Controller(netplus::con *curcon,libhttppp::HttpRequest *req,libhtmlpp::HtmlElement &page){ char url[512]; if(strncmp(req->getRequestURL(),Args->config->buildurl("gamestatus",url,512),strlen(Args->config->buildurl("gamestatus",url,512)))!=0){ return false; Loading Loading @@ -114,8 +114,9 @@ namespace blogi { condat << "</div>"; std::string out,sid; page.getElementbyID("main")->insertChild(condat.parse()); Args->theme->RenderSite(out,req->getRequestURL(),condat, Args->theme->printSite(out,page,req->getRequestURL(), Args->auth->isLoggedIn(req,sid)); libhttppp::HttpResponse resp; Loading
plugins/navbar/CMakeLists.txt 0 → 100644 +5 −0 Original line number Diff line number Diff line add_library(navbar SHARED navbar.cpp) target_link_libraries(navbar dl blogidev) install (TARGETS navbar DESTINATION lib/blogi/plugins)
plugins/navbar/navbar.cpp 0 → 100644 +120 −0 Original line number Diff line number Diff line /******************************************************************************* * Copyright (c) 2023, Jan Koester jan.koester@gmx.net * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <cstring> #include <string> #include "plugin.h" #include "database.h" #include "theme.h" #include "conf.h" namespace blogi { class Navbar : public PluginApi { public: Navbar(){ Navigation = new libhtmlpp::HtmlElement(); } ~Navbar(){ delete Navigation; } const char* getName(){ return "navbar"; } const char* getVersion(){ return "0.1"; } const char* getAuthor(){ return "Jan Koester"; } void initPlugin(){ return; } void Rendering(libhtmlpp::HtmlElement* curpage){ blogi::SQL sql; blogi::DBResult res; sql << "select url,name from navbar ORDER BY id"; int n = Args->database->exec(&sql,res); if(n<1){ libhttppp::HTTPException excep; excep[libhttppp::HTTPException::Critical] << "No entries found for navbar"; throw excep; } libhtmlpp::HtmlString buf; buf << "<div id=\"navbar\">" << "<ul>"; for (int i = 0; i < n; i++) { buf << "<li "; buf << "class=\"inactive\""; buf << "><a href=\"" << res[i][0] << "\">" << res[i][1] << "</a></li>"; } //<li class=\"active\" style=\"padding:1px 10px; float:left\"><a href=\"" << _Config.config->buildurl(index,url,512) <<"\">Blog</a></li> buf << "</ul></div>"; Navigation->appendChild(buf.parse()); Args->theme->Rendering(curpage,"header",Navigation); } bool haveSettings(){ return true; } void Settings(libhttppp::HttpRequest *req,libhtmlpp::HtmlString &setdiv){ setdiv << "<div id=\"navsettings\"><span>Navbar Settings</span></div>"; } bool Controller(netplus::con *curcon,libhttppp::HttpRequest *req){ std::string turl=req->getRequestURL(); if(turl.rfind('?')>0){ turl=turl.substr(0,turl.rfind('?')); } // if(turl.compare(0,strlen(res[i][0]),res[i][0]) == 0 ) // // buf << "class=\"active\""; // else // return false; } private: libhtmlpp::HtmlElement *Navigation; }; }; extern "C" blogi::PluginApi* create() { return new blogi::Navbar(); } extern "C" void destroy(blogi::PluginApi* p) { delete p; }