diff --git a/content/content.cpp b/content/content.cpp index c55a773..fdcdfad 100755 --- a/content/content.cpp +++ b/content/content.cpp @@ -59,33 +59,33 @@ void Content::SetDefaultFunctionForFile() void Content::SetDefaultFunctionForDir() { + long default_item = request.dir_table.back()->default_item; + + if( default_item != -1 ) + { + request.session->IncrementTimersIfExist(); + + log << log3 << "Content: Default item: id: " << default_item << logend; + RedirectTo(default_item); + return; + } + + if( data.mounts.CurrentMountType() == Mount::thread ) { request.pfunction = data.functions.GetFunction(FUN_THREAD); - + if( request.pfunction ) log << log3 << "Content: default function: " << request.pfunction->item.url << logend; - } else { - long default_item = request.dir_table.back()->default_item; - - if( default_item == -1 ) - { - request.pfunction = data.functions.GetFunction(FUN_LS); + // cms + request.pfunction = data.functions.GetFunction(FUN_LS); - if( request.pfunction ) - log << log3 << "Content: default function: " << request.pfunction->item.url << logend; - } - else - { - request.session->IncrementTimersIfExist(); - - log << log3 << "Content: Default item: id: " << default_item << logend; - RedirectTo(default_item); - } - } + if( request.pfunction ) + log << log3 << "Content: default function: " << request.pfunction->item.url << logend; + } } diff --git a/content/emacs.cpp b/content/emacs.cpp index 1de2925..7219a71 100755 --- a/content/emacs.cpp +++ b/content/emacs.cpp @@ -25,7 +25,16 @@ void Content::PostFunEmacsAdd() request.is_item = true; - request.item.user_id = request.session->puser ? request.session->puser->id : -1; + if( request.session->puser ) + { + request.item.user_id = request.session->puser->id; + } + else + { + request.item.user_id = -1; + request.item.guest_name = request.PostVar("guestname"); + } + request.item.group_id = -1; request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask request.item.parent_id = request.dir_table.back()->id; diff --git a/content/mkdir.cpp b/content/mkdir.cpp index a6a54eb..cee61ec 100755 --- a/content/mkdir.cpp +++ b/content/mkdir.cpp @@ -33,7 +33,17 @@ void Content::PostFunMkdir(bool add_to_dir_table, int mask) item.subject = request.PostVar("subject"); item.url = request.PostVar("url"); item.parent_id = request.dir_table.back()->id; - item.user_id = request.session->puser ? request.session->puser->id : -1; + + if( request.session->puser ) + { + item.user_id = request.session->puser->id; + } + else + { + item.user_id = -1; + item.guest_name = request.PostVar("guestname"); + } + item.group_id = -1; item.privileges = mask; item.default_item = -1; diff --git a/content/rm.cpp b/content/rm.cpp index 1376547..b183a3d 100755 --- a/content/rm.cpp +++ b/content/rm.cpp @@ -98,6 +98,9 @@ void Content::FunRm() request.session->done_status = Error::ok; log << log2 << "Content: deleted item: subject: " << request.item.subject << ", id: " << request.item.id << logend; TemplatesFunctions::pattern_cacher.DeletePattern(request.item); + + if( data.mounts.CurrentMountType() == Mount::thread ) + db.EditThreadRemoveItem(request.item.parent_id); } else { diff --git a/core/Makefile.dep b/core/Makefile.dep index 3c111e5..f8e236e 100755 --- a/core/Makefile.dep +++ b/core/Makefile.dep @@ -12,7 +12,8 @@ db_itemcolumns.o: db.h item.h user.h group.h thread.h error.h log.h db_itemcolumns.o: dircontainer.h ugcontainer.h dircontainer.o: dircontainer.h item.h log.h dirs.o: dirs.h item.h dircontainer.h error.h log.h db.h user.h group.h -dirs.o: thread.h ugcontainer.h +dirs.o: thread.h ugcontainer.h data.h users.h groups.h functions.h function.h +dirs.o: lastcontainer.h mounts.h mount.h done.o: done.h error.o: error.h log.h function.o: function.h item.h diff --git a/core/db.cpp b/core/db.cpp index 932c1d0..562233a 100755 --- a/core/db.cpp +++ b/core/db.cpp @@ -420,7 +420,7 @@ Error Db::AddItemIntoItem(Item & item) { AssertConnection(); std::ostringstream query; - query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, subject, url) values ("; + query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, subject, guest_name, url) values ("; query << '\'' << item.user_id << "', "; query << '\'' << item.group_id << "', "; query << '\'' << item.privileges << "', "; @@ -431,6 +431,7 @@ Error Db::AddItemIntoItem(Item & item) query << '\'' << item.content_id << "', "; query << '\'' << item.default_item << "', "; query << '\'' << Escape(item.subject) << "', "; + query << '\'' << Escape(item.guest_name) << "', "; url_without_id = AddItemCreateUrlSubject(item); @@ -522,7 +523,7 @@ Error Db::EditItemInItem(Item & item, bool with_url) { AssertConnection(); std::ostringstream query; - query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject"; + query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject, guest_name"; if( with_url ) query << ", url"; @@ -536,7 +537,8 @@ Error Db::EditItemInItem(Item & item, bool with_url) query << '\'' << static_cast(item.type) << "', "; query << '\'' << item.default_item << "', "; query << '\'' << item.parent_id << "', "; - query << '\'' << Escape(item.subject) << "' "; + query << '\'' << Escape(item.subject) << "', "; + query << '\'' << Escape(item.guest_name) << "' "; if( with_url ) { @@ -749,7 +751,7 @@ return result; PGresult * Db::GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc) { std::ostringstream query; - query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item"; + query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item, guest_name"; if( type != Item::dir ) { @@ -819,7 +821,7 @@ void Db::GetItems(std::vector & item_table, long parent_id, Item::Type typ } - +// !! ta chyba nie uzywana juz? void Db::GetItem(std::vector & item_table, long id) { PGresult * r = 0; @@ -957,7 +959,7 @@ bool result = false; AssertConnection(); std::ostringstream query; - query << "select user_id, group_id, privileges, subject, content from core.item left join core.content on item.content_id = content.id where item.id='" << id << "';"; // !! tymczasowo odczytujemy z content i subject + query << "select user_id, group_id, privileges, subject, content, guest_name from core.item left join core.content on item.content_id = content.id where item.id='" << id << "';"; // !! tymczasowo odczytujemy z content i subject r = AssertQuery( query.str() ); AssertResultStatus(r, PGRES_TUPLES_OK); @@ -993,10 +995,11 @@ Error Db::EditPrivById(Item & item, long id) { AssertConnection(); std::ostringstream query; - query << "update core.item set (user_id, group_id, privileges) = ("; + query << "update core.item set (user_id, group_id, privileges, guest_name) = ("; query << '\'' << item.user_id << "', "; query << '\'' << item.group_id << "', "; - query << '\'' << item.privileges << "' "; + query << '\'' << item.privileges << "', "; + query << '\'' << Escape(item.guest_name) << "' "; query << ") where id='" << id << "';"; @@ -1449,7 +1452,7 @@ Error Db::GetThreads(long parent_id, std::vector & thread_tab) AssertConnection(); std::ostringstream query; - query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id " + query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id, item.guest_name " "from core.thread left join core.item on thread.last_item = item.id " "where thread.parent_id = '" << parent_id << "' order by date_modification asc;"; @@ -1467,6 +1470,9 @@ Error Db::GetThreads(long parent_id, std::vector & thread_tab) int clast_item = AssertColumn(r, "last_item"); int cdate_modification = PQfnumber(r, "date_modification"); int cuser_id = PQfnumber(r, "user_id"); + int cguest_name = PQfnumber(r, "guest_name"); + + for(int i=0 ; i & thread_tab) thread.last_item.id = atol( AssertValue(r, i, clast_item) ); thread.last_item.date_modification = ConvertTime( Db::AssertValue(r, i, cdate_modification) ); thread.last_item.user_id = atol( Db::AssertValue(r, i, cuser_id) ); - + thread.last_item.guest_name = Db::AssertValue(r, i, cguest_name); + thread_tab.push_back(thread); } } @@ -1554,3 +1561,73 @@ Error Db::EditThreadAddItem(long dir_id, long item_id) return status; } + + + +Error Db::EditThreadRemoveItem(long dir_id) +{ + PGresult * r = 0; + Error status = Error::ok; + + try + { + AssertConnection(); + std::ostringstream query, query2; + + long last_item_id = -1; + + query << "select id from core.item where parent_id='" << dir_id << "' order by date_creation desc limit 1;"; + r = AssertQuery( query.str() ); + AssertResultStatus(r, PGRES_TUPLES_OK); + + if( PQntuples(r) == 1 ) + last_item_id = atol( AssertValue(r, 0, 0) ); + + ClearResult(r); + + query2 << "update core.thread set (items, last_item) = (items-1,'" << last_item_id + << "') where dir_id='" << dir_id << "';"; + + r = AssertQuery(query2.str()); + AssertResultStatus(r, PGRES_COMMAND_OK); + } + catch(const Error & e) + { + status = e; + } + + ClearResult(r); + + +return status; +} + + +Error Db::RemoveThread(long dir_id) +{ + PGresult * r = 0; + Error status = Error::ok; + + try + { + AssertConnection(); + std::ostringstream query; + query << "delete from core.thread where dir_id='" << dir_id << "';"; + + const char * crows = PQcmdTuples(r); + if( crows ) + log << log2 << "Db: deleted " << atol(crows) << " rows from core.thread" << logend; + + r = AssertQuery(query.str()); + AssertResultStatus(r, PGRES_COMMAND_OK); + } + catch(const Error & e) + { + status = e; + } + + ClearResult(r); + +return status; +} + diff --git a/core/db.h b/core/db.h index 956bc21..aea7b19 100755 --- a/core/db.h +++ b/core/db.h @@ -84,6 +84,8 @@ public: Error GetThreadByDirId(long dir_id, Thread & thread); Error GetThreads(long parent_id, std::vector & thread_tab); Error EditThreadAddItem(long dir_id, long item_id); + Error EditThreadRemoveItem(long dir_id); + Error RemoveThread(long dir_id); protected: @@ -125,7 +127,7 @@ protected: struct ItemColumns { - int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item, subject, content, content_type; + int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item, subject, content, content_type, guest_name; void SetColumns(PGresult * r); diff --git a/core/db_itemcolumns.cpp b/core/db_itemcolumns.cpp index 60aa567..742c42e 100755 --- a/core/db_itemcolumns.cpp +++ b/core/db_itemcolumns.cpp @@ -28,6 +28,7 @@ void Db::ItemColumns::SetColumns(PGresult * r) subject = PQfnumber(r, "subject"); content = PQfnumber(r, "content"); content_type = PQfnumber(r, "content_type"); + guest_name = PQfnumber(r, "guest_name"); } @@ -48,6 +49,7 @@ void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item) if( subject != -1 ) item.subject = Db::AssertValue(r, row, subject); if( content != -1 ) item.content = Db::AssertValue(r, row, content); if( content_type != -1 ) item.content_type = atoi( Db::AssertValue(r, row, content_type) ); + if( guest_name != -1 ) item.guest_name = Db::AssertValue(r, row, guest_name); } diff --git a/core/dirs.cpp b/core/dirs.cpp index 998fe1b..6e38c61 100755 --- a/core/dirs.cpp +++ b/core/dirs.cpp @@ -11,7 +11,7 @@ #include "error.h" #include "log.h" #include "db.h" - +#include "data.h" void Dirs::Clear() @@ -404,6 +404,9 @@ void Dirs::DeleteDir(long id) if( db.DelDirById(id) == Error::ok ) dir_table.DelById(id); + + if( data.mounts.CurrentMountType() == Mount::thread ) + db.RemoveThread(id); } diff --git a/core/item.h b/core/item.h index 3e25180..f278ab5 100755 --- a/core/item.h +++ b/core/item.h @@ -24,6 +24,9 @@ long user_id; long group_id; int privileges; +// used as a user name when user_id is equal -1 +std::string guest_name; + tm date_creation; tm date_modification; @@ -77,6 +80,8 @@ void Clear() group_id = -1; privileges = 0; + guest_name.clear(); + subject.clear(); content.clear(); url.clear(); diff --git a/core/mount.cpp b/core/mount.cpp index b6b323f..328e00e 100755 --- a/core/mount.cpp +++ b/core/mount.cpp @@ -59,6 +59,12 @@ bool Mount::ParseStrParam(const std::string & param, const std::vector & ar if( param == "withinfo" ) p = withinfo; else + if( param == "thread_with_header" ) + p = thread_with_header; + else + if( param == "thread_with_info" ) + p = thread_with_info; + else if( param == "restrictcreatethread" ) p = restrictcreatethread; else diff --git a/core/mount.h b/core/mount.h index 466f920..ddee360 100755 --- a/core/mount.h +++ b/core/mount.h @@ -35,6 +35,8 @@ public: desc, withheader, withinfo, + thread_with_header, + thread_with_info, restrictcreatethread, only_root_can_remove, can_use_emacs_on, diff --git a/core/mounts.cpp b/core/mounts.cpp index 3897a75..b7b9af3 100755 --- a/core/mounts.cpp +++ b/core/mounts.cpp @@ -22,7 +22,7 @@ void Mounts::ReadMounts() std::string temp = "cms / withheader, withinfo \n" "thread /news desc, withheader, withinfo, restrictcreatethread(-1) \n" - "thread /forum asc, withinfo, restrictcreatethread(3), only_root_can_remove, can_use_emacs_on(4), can_use_mkdir_on(3)"; + "thread /forum asc, withheader, withinfo, thread_with_info, restrictcreatethread(3), only_root_can_remove, can_use_emacs_on(4), can_use_mkdir_on(3)"; Error err = mp.Parse(temp, mount_table); diff --git a/templates/dir.cpp b/templates/dir.cpp index acb4896..a9292ff 100755 --- a/templates/dir.cpp +++ b/templates/dir.cpp @@ -226,6 +226,61 @@ void dir_last_subject(Info & i) } +void dir_last_info(Info & i) +{ + Ezc::Generator gen(i.out, pat_dir_last_info, functions); + gen.Generate(); +} + + +void dir_last_user(Info & i) +{ + User * puser = data.users.GetUser(request.dir_table.back()->user_id); + + if( puser ) + HtmlEscape(i.out, puser->name); + else + { + i.out << "~"; + + if( !request.dir_table.back()->guest_name.empty() ) + HtmlEscape(i.out, request.dir_table.back()->guest_name); + else + i.out << "guest"; // !! dodac do konfiga + } +} + + +void dir_last_date_creation(Info & i) +{ + tm * ptm = &request.dir_table.back()->date_creation; + + i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); +} + + +void dir_last_date_modification(Info & i) +{ + tm * ptm = &request.dir_table.back()->date_modification; + + i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); +} + + +void dir_last_dates_equal(Info & i) +{ + tm * ptm1 = &request.dir_table.back()->date_creation; + tm * ptm2 = &request.dir_table.back()->date_modification; + + i.result = ptm1->tm_year == ptm2->tm_year && + ptm1->tm_mon == ptm2->tm_mon && + ptm1->tm_mday == ptm2->tm_mday && + ptm1->tm_hour == ptm2->tm_hour && + ptm1->tm_min == ptm2->tm_min && + ptm1->tm_sec == ptm2->tm_sec; +} + + void dir_old(Info & i) { diff --git a/templates/doc.cpp b/templates/doc.cpp index 48f6982..59b7fbd 100755 --- a/templates/doc.cpp +++ b/templates/doc.cpp @@ -35,10 +35,16 @@ void doc_title(Info & i) // from 1 means skipping the root directory for(a = 1 ; asubject; + { + i.out << " / "; + HtmlEscape(i.out, request.dir_table[a]->subject); + } if( request.is_item ) - i.out << " / " << request.item.subject; + { + i.out << " / "; + HtmlEscape(i.out, request.item.subject); + } } diff --git a/templates/item.cpp b/templates/item.cpp index adf36a7..6e59458 100755 --- a/templates/item.cpp +++ b/templates/item.cpp @@ -146,7 +146,14 @@ void item_user(Info & i) if( puser ) HtmlEscape(i.out, puser->name); else - i.out << "~guest"; // !! dodac do konfiga + { + i.out << "~"; + + if( !request.item.guest_name.empty() ) + HtmlEscape(i.out, request.item.guest_name); + else + i.out << "guest"; // !! dodac do konfiga + } } @@ -413,7 +420,14 @@ void item_tab_user(Info & i) if( puser ) HtmlEscape(i.out, puser->name); else - i.out << "~guest"; // !! dodac do konfiga + { + i.out << "~"; + + if( !request.item_table[item_index].guest_name.empty() ) + HtmlEscape(i.out, request.item_table[item_index].guest_name); + else + i.out << "guest"; // !! dodac do konfiga + } } } diff --git a/templates/mount.cpp b/templates/mount.cpp index 2d0060a..9071bc8 100755 --- a/templates/mount.cpp +++ b/templates/mount.cpp @@ -29,8 +29,16 @@ void mount_param_withinfo(Info & i) } +void mount_param_thread_with_header(Info & i) +{ + i.result = data.mounts.CurrentMountIsParam(Mount::thread_with_header); +} +void mount_param_thread_with_info(Info & i) +{ + i.result = data.mounts.CurrentMountIsParam(Mount::thread_with_info); +} } // namespace TemplatesFunctions diff --git a/templates/templates.cpp b/templates/templates.cpp index 892cc1b..05a3e73 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -35,6 +35,7 @@ Ezc::Pattern pat_err_per_denied; Ezc::Pattern pat_err_others; Ezc::Pattern pat_item_info; Ezc::Pattern pat_item_tab_info; +Ezc::Pattern pat_dir_last_info; Ezc::Functions functions; @@ -280,9 +281,14 @@ void Templates::CreateFunctions() functions.Insert("dir_tab_url", dir_tab_url); functions.Insert("dir_tab_link", dir_tab_link); - functions.Insert("dir_last_default_item_dir", dir_last_default_item_dir); - functions.Insert("dir_last_default_item_url", dir_last_default_item_url); - functions.Insert("dir_last_subject", dir_last_subject); + functions.Insert("dir_last_default_item_dir", dir_last_default_item_dir); + functions.Insert("dir_last_default_item_url", dir_last_default_item_url); + functions.Insert("dir_last_subject", dir_last_subject); + functions.Insert("dir_last_info", dir_last_info); + functions.Insert("dir_last_user", dir_last_user); + functions.Insert("dir_last_date_creation", dir_last_date_creation); + functions.Insert("dir_last_date_modification", dir_last_date_modification); + functions.Insert("dir_last_dates_equal", dir_last_dates_equal); functions.Insert("dir_old", dir_old); @@ -355,7 +361,6 @@ void Templates::CreateFunctions() thread */ functions.Insert("thread_is", thread_is); - functions.Insert("thread_subject", thread_subject); functions.Insert("thread_show_edit_subject", thread_show_edit_subject); functions.Insert("thread_tab", thread_tab); functions.Insert("thread_tab_url", thread_tab_url); @@ -370,8 +375,10 @@ void Templates::CreateFunctions() /* mount */ - functions.Insert("mount_param_withheader", mount_param_withheader); - functions.Insert("mount_param_withinfo", mount_param_withinfo); + functions.Insert("mount_param_withheader", mount_param_withheader); + functions.Insert("mount_param_withinfo", mount_param_withinfo); + functions.Insert("mount_param_thread_with_header", mount_param_thread_with_header); + functions.Insert("mount_param_thread_with_info", mount_param_thread_with_info); @@ -449,6 +456,9 @@ void Templates::Read() pat_fun_createthread.Directory(data.templates); pat_fun_createthread.ParseFile("fun_createthread.html"); + pat_dir_last_info.Directory(data.templates); + pat_dir_last_info.ParseFile("dir_last_info.html"); + CreateFunctions(); #ifdef APPTEMPLATES diff --git a/templates/templates.h b/templates/templates.h index fe4198a..5c9e39b 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -32,7 +32,9 @@ namespace TemplatesFunctions extern Ezc::Functions functions; extern Ezc::Pattern pat_item_info; extern Ezc::Pattern pat_item_tab_info; - + extern Ezc::Pattern pat_dir_last_info; + + /* sys */ @@ -127,6 +129,11 @@ namespace TemplatesFunctions void dir_last_default_item_dir(Info &); void dir_last_default_item_url(Info & i); void dir_last_subject(Info & i); + void dir_last_info(Info & i); + void dir_last_user(Info & i); + void dir_last_date_creation(Info & i); + void dir_last_date_modification(Info & i); + void dir_last_dates_equal(Info & i); void dir_old(Info & i); @@ -197,7 +204,6 @@ namespace TemplatesFunctions */ void thread_is(Info & i); void thread_show_edit_subject(Info & i); - void thread_subject(Info & i); void thread_tab(Info & i); void thread_tab_url(Info & i); void thread_tab_subject(Info & i); @@ -212,7 +218,8 @@ namespace TemplatesFunctions */ void mount_param_withheader(Info & i); void mount_param_withinfo(Info & i); - + void mount_param_thread_with_header(Info & i); + void mount_param_thread_with_info(Info & i); } // namespace TemplatesFunctions diff --git a/templates/thread.cpp b/templates/thread.cpp index ab8a08f..9f81293 100755 --- a/templates/thread.cpp +++ b/templates/thread.cpp @@ -34,20 +34,6 @@ void thread_show_edit_subject(Info & i) } -void thread_subject(Info & i) -{ - Item * dir = data.dirs.GetDir( request.thread.dir_id ); - - if( dir ) - { - HtmlEscape(i.out, dir->subject); - } - else - { - i.out << ""; - } -} - static size_t thread_tab_index; @@ -131,7 +117,14 @@ bool unknown = true; if( puser ) HtmlEscape(i.out, puser->name); else - HtmlEscape(i.out, "~guest"); // !! dodac to do data + { + i.out << "~"; + + if( !dir->guest_name.empty() ) + HtmlEscape(i.out, dir->guest_name); + else + i.out << "guest"; // !! dodac do konfiga + } } } @@ -162,7 +155,14 @@ void thread_tab_last_item_user(Info & i) if( puser ) HtmlEscape(i.out, puser->name); else - HtmlEscape(i.out, "~guest"); // !! dodac to do data + { + i.out << "~"; + + if( !request.thread_tab[thread_tab_index].last_item.guest_name.empty() ) + HtmlEscape(i.out, request.thread_tab[thread_tab_index].last_item.guest_name); + else + i.out << "guest"; // !! dodac do konfiga + } } } }