X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fsiteinserter.cpp;h=f7d9ef245b6d8ef17d321aa1cf0bb2fba2096e2f;hb=7ddb1aeb0b3dc7384597e75f7b3557f2d8f6d14c;hp=9db96517ed98b5378c897ea470d9651bc8d1918b;hpb=e773b0ecb8a35c67cde5b2e82bbebb05224f34d0;p=fms.git diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp index 9db9651..f7d9ef2 100644 --- a/src/freenet/siteinserter.cpp +++ b/src/freenet/siteinserter.cpp @@ -40,8 +40,6 @@ std::string SiteInserter::GenerateIndex(const std::string &htmltemplate, const l { std::string content=""; - content="

FMS site of "+SanitizeOutput(name)+"

"; - content+="

My last few posts

"; SQLite3DB::Statement boardst=m_db->Prepare("SELECT tblBoard.BoardName FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblMessageBoard.MessageID=? ORDER BY tblBoard.BoardName COLLATE NOCASE;"); @@ -84,13 +82,17 @@ std::string SiteInserter::GenerateIndex(const std::string &htmltemplate, const l content+=""; content+="
"; content+=SanitizeOutput(post); + //post=SanitizeOutput(post); + //StringFunctions::Replace(post,"\r\n","
"); + //content+=post; content+="
"; content+=""; st.Step(); } - return StringFunctions::Replace(htmltemplate,"[CONTENT]",content); + std::string output=StringFunctions::Replace(htmltemplate,"[CONTENT]",content); + return StringFunctions::Replace(output,"[IDENTITYNAME]",SanitizeOutput(name)); } @@ -113,7 +115,7 @@ std::string SiteInserter::GenerateLinks(const bool publishtrustlist, const bool void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey, std::map &pages) { - SQLite3DB::Statement st=m_db->Prepare("SELECT Name, PrivateKey, PublishTrustList, PublishBoardList FROM tblLocalIdentity WHERE LocalIdentityID=?;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT Name, PrivateKey, PublishTrustList, PublishBoardList, FreesiteEdition FROM tblLocalIdentity WHERE LocalIdentityID=?;"); st.Bind(0,localidentityid); st.Step(); @@ -127,14 +129,29 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey std::string publishboardliststr=""; bool publishtrustlist=false; bool publishboardlist=false; + std::string editionstr=""; st.ResultText(0,name); st.ResultText(1,key); st.ResultText(2,publishtrustliststr); st.ResultText(3,publishboardliststr); + st.ResultText(4,editionstr); publishtrustliststr=="true" ? publishtrustlist=true : publishtrustlist=false; publishboardliststr=="true" ? publishboardlist=true : publishboardlist=false; + // no edition exists - start at 0 + if(editionstr=="") + { + editionstr="0"; + } + // previous edition exists - add 1 + else + { + int edition=0; + StringFunctions::Convert(editionstr,edition); + edition++; + StringFunctions::Convert(edition,editionstr); + } filename=name+"-template.htm"; FILE *infile=fopen(filename.c_str(),"r+b"); @@ -173,7 +190,7 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey key.erase(0,3); key="USK"+key; } - key+=m_messagebase+"/0/"; + key+=m_messagebase+"/"+editionstr+"/"; uskkey=key; } @@ -182,6 +199,66 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages unable to open "+filename+" or site-template.htm."); } + // get extra files that the user wants to add to the Freesite + filename=name+"-files.txt"; + infile=fopen(filename.c_str(),"r+b"); + if(infile) + { + std::vector files; + + fseek(infile,0,SEEK_END); + long len=ftell(infile); + fseek(infile,0,SEEK_SET); + + std::vector data; + data.resize(len); + fread(&data[0],1,data.size(),infile); + fclose(infile); + + // split on \r and \n - on systems with \r\n line endings there will be blank entries, but we'll just skip those + std::string filecontent(data.begin(),data.end()); + StringFunctions::SplitMultiple(filecontent,"\r\n",files); + + for(std::vector::iterator i=files.begin(); i!=files.end(); i++) + { + if((*i)!="" && (*i).find("index.htm")==std::string::npos && (*i).find("trustlist.htm")==std::string::npos && (*i).find("files.htm")==std::string::npos) + { + filename=(*i); + infile=fopen(filename.c_str(),"r+b"); + if(infile) + { + fseek(infile,0,SEEK_END); + len=ftell(infile); + fseek(infile,0,SEEK_SET); + + data.resize(len); + fread(&data[0],1,data.size(),infile); + fclose(infile); + + filecontent=""; + filecontent.append(data.begin(),data.end()); + + // strip off path from filename + while(filename.find_first_of("/")!=std::string::npos) + { + filename.erase(0,filename.find_first_of("/")+1); + } + + if(filecontent.size()>0) + { + pages[filename]=filecontent; + } + + } + else + { + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages could not include user file "+(*i)); + } + } + } + + } + } } @@ -285,6 +362,8 @@ const bool SiteInserter::HandlePutFailed(FCPMessage &message) RemoveFromInsertList(localidentityid); + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::HandlePutFailed failed to insert Freesite, Freenet error code : "+message["Code"]); + return true; } @@ -337,7 +416,7 @@ const std::string SiteInserter::SanitizeOutput(const std::string &input) return output; } -void SiteInserter::StartInsert(const long &localidentityid) +const bool SiteInserter::StartInsert(const long &localidentityid) { FCPMessage message; std::string localidentityidstr=""; @@ -381,4 +460,6 @@ void SiteInserter::StartInsert(const long &localidentityid) m_inserting.push_back(localidentityid); + return true; + }