From 0550212b64907957848052c92eb3c69bf983bf20 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 16 Oct 2011 21:33:45 +0000 Subject: [PATCH] changed: GroupItem plugin has been renamed to Group it's nearly finished now we are using three levels from Space (ConfParser) - group set - group - values git-svn-id: svn://ttmath.org/publicrep/winix/trunk@773 e52654a7-88a9-db11-a3e9-0013d4bc506e --- Makefile | 6 +- core/confparser.cpp | 57 ++++-- core/confparser.h | 3 +- core/mounts.cpp | 1 + core/mounts.h | 2 + core/pluginmsg.h | 11 +- core/sessionmanager.cpp | 3 + db/dbbase.cpp | 2 +- functions/Makefile.dep | 6 + functions/login.cpp | 4 + html/fun_reload.html | 4 +- locale/en | 2 +- locale/pl | 2 +- plugins/{groupitem => group}/Makefile | 2 +- plugins/{groupitem => group}/Makefile.dep | 4 +- plugins/{groupitem => group}/Makefile.o.dep | 0 plugins/{groupitem => group}/groupinfo.cpp | 58 ++---- plugins/{groupitem => group}/groupinfo.h | 9 +- plugins/group/groups.cpp | 216 ++++++++++++++++++++ plugins/group/groups.h | 130 ++++++++++++ plugins/{groupitem => group}/init.cpp | 10 +- plugins/group/templates.cpp | 128 ++++++++++++ plugins/groupitem/groups.cpp | 119 ----------- plugins/groupitem/groups.h | 105 ---------- plugins/groupitem/templates.cpp | 87 -------- templates/mount.cpp | 20 +- templates/templates.cpp | 2 + templates/templates.h | 2 + 28 files changed, 594 insertions(+), 401 deletions(-) rename plugins/{groupitem => group}/Makefile (95%) rename plugins/{groupitem => group}/Makefile.dep (98%) rename plugins/{groupitem => group}/Makefile.o.dep (100%) rename plugins/{groupitem => group}/groupinfo.cpp (77%) rename plugins/{groupitem => group}/groupinfo.h (91%) create mode 100755 plugins/group/groups.cpp create mode 100755 plugins/group/groups.h rename plugins/{groupitem => group}/init.cpp (77%) create mode 100755 plugins/group/templates.cpp delete mode 100755 plugins/groupitem/groups.cpp delete mode 100755 plugins/groupitem/groups.h delete mode 100755 plugins/groupitem/templates.cpp diff --git a/Makefile b/Makefile index 855c85f..fba6ece 100755 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ plugins: FORCE @cd plugins/thread ; $(MAKE) -e @cd plugins/ticket ; $(MAKE) -e @cd plugins/gallery ; $(MAKE) -e - @cd plugins/groupitem ; $(MAKE) -e + @cd plugins/group ; $(MAKE) -e @cd plugins/menu ; $(MAKE) -e @cd plugins/export ; $(MAKE) -e @@ -57,7 +57,7 @@ clean: @cd plugins/thread ; $(MAKE) -e clean @cd plugins/ticket ; $(MAKE) -e clean @cd plugins/gallery ; $(MAKE) -e clean - @cd plugins/groupitem ; $(MAKE) -e clean + @cd plugins/group ; $(MAKE) -e clean @cd plugins/menu ; $(MAKE) -e clean @cd plugins/export ; $(MAKE) -e clean @cd ../ezc/src ; $(MAKE) -e clean @@ -79,7 +79,7 @@ depend: @cd plugins/thread ; $(MAKE) -e depend @cd plugins/ticket ; $(MAKE) -e depend @cd plugins/gallery ; $(MAKE) -e depend - @cd plugins/groupitem ; $(MAKE) -e depend + @cd plugins/group ; $(MAKE) -e depend @cd plugins/menu ; $(MAKE) -e depend @cd plugins/export ; $(MAKE) -e depend @cd ../ezc/src ; $(MAKE) -e depend diff --git a/core/confparser.cpp b/core/confparser.cpp index 9dbdf06..f9df884 100755 --- a/core/confparser.cpp +++ b/core/confparser.cpp @@ -345,33 +345,54 @@ return false; -void Space::Print(std::wostream & out) +void Space::PrintLevel(std::wostream & out, int level) { + for(int i=0 ; ifirst << '=' << i1->second << std::endl; - - out << "table: " << std::endl; - - Table::iterator i2; - Value::iterator i3; - - for(i2 = table.begin() ; i2 != table.end() ; ++i2) + if( !table_single.empty() ) { - out << i2->first << '='; + PrintLevel(out, level); + out << "table_single: " << std::endl; + TableSingle::iterator i1; - for(i3 = i2->second.begin() ; i3 != i2->second.end() ; ++i3) - out << *i3 << ','; + for(i1 = table_single.begin() ; i1 != table_single.end() ; ++i1) + { + PrintLevel(out, level); + out << i1->first << '=' << i1->second << std::endl; + } + } - out << std::endl; + if( !table.empty() ) + { + PrintLevel(out, level); + out << "table: " << std::endl; + + Table::iterator i2; + Value::iterator i3; + + for(i2 = table.begin() ; i2 != table.end() ; ++i2) + { + PrintLevel(out, level); + out << i2->first << '='; + + for(i3 = i2->second.begin() ; i3 != i2->second.end() ; ++i3) + out << *i3 << ','; + + out << std::endl; + } } for(size_t i=0 ; iPrint(out); + spaces[i]->Print(out, level+1); } diff --git a/core/confparser.h b/core/confparser.h index 88e665a..167b450 100755 --- a/core/confparser.h +++ b/core/confparser.h @@ -236,7 +236,7 @@ public: printing the content (for debug purposes) */ - void Print(std::wostream & out); + void Print(std::wostream & out, int level = 0); private: std::wstring tmp_name; @@ -248,6 +248,7 @@ private: bool ToBool(const std::wstring & value); wchar_t ToSmall(wchar_t c); bool EqualNoCase(const wchar_t * str1, const wchar_t * str2); + void PrintLevel(std::wostream & out, int level); }; diff --git a/core/mounts.cpp b/core/mounts.cpp index 7f16419..eae2edc 100755 --- a/core/mounts.cpp +++ b/core/mounts.cpp @@ -63,6 +63,7 @@ void Mounts::CreateMountPar() mount_par_change_template = AddMountPar(L"change_template"); mount_par_static = AddMountPar(L"static"); mount_par_css = AddMountPar(L"css"); + mount_par_lang = AddMountPar(L"lang"); } diff --git a/core/mounts.h b/core/mounts.h index 16ebfe7..31f0110 100755 --- a/core/mounts.h +++ b/core/mounts.h @@ -83,6 +83,7 @@ public: int MountParChangeTemplate() { return mount_par_change_template; } int MountParStatic() { return mount_par_static; } int MountParCss() { return mount_par_css; } + int MountParLang() { return mount_par_lang; } void SetDirs(Dirs * pdirs); void SetDb(Db * pdb); @@ -157,6 +158,7 @@ private: int mount_par_change_template; int mount_par_static; int mount_par_css; + int mount_par_lang; MountTab mount_tab; diff --git a/core/pluginmsg.h b/core/pluginmsg.h index 8664eec..5058023 100755 --- a/core/pluginmsg.h +++ b/core/pluginmsg.h @@ -43,7 +43,7 @@ #define WINIX_CONTENT_MAKE 2002 // here you can attach your own session data (based on PluginDataBase class) -// call request.session->plugin_data.Assign(pointer) +// call cur->session->plugin_data.Assign(pointer) #define WINIX_SESSION_CREATED 3000 // here you should remove your session data @@ -94,7 +94,7 @@ #define WINIX_NOTIFY_ADD_TEMPLATE 3013 // the request is being ended -// you can clear some of your object here +// you can clear some of your objects here #define WINIX_END_REQUEST 3014 // a new file (page) has been added @@ -132,13 +132,18 @@ // in p1 you have a pointer to the Item struct #define WINIX_IMAGE_RESIZED 3052 - // content of a directory was sorted // (winix 'sort' function was used) // in p1 you have a pointer to the Item struct (of the directory) // this is from system->dirs so you should not change the item #define WINIX_DIR_CONTENT_SORTED 3050 +// a user has been logged +// send from 'login' winix function +// this message is also called when winix starts and reads sessions +// from the session file +#define WINIX_USER_LOGGED 3060 + // here you add your own html templates // call TemplatesFunctions::patterns.Add(L"file_name.html") diff --git a/core/sessionmanager.cpp b/core/sessionmanager.cpp index 2e36048..d362f3f 100755 --- a/core/sessionmanager.cpp +++ b/core/sessionmanager.cpp @@ -268,6 +268,9 @@ SessionContainer::Iterator i; i->plugin_data.Resize(plugin.Size()); cur->session = &(*i); plugin.Call(WINIX_SESSION_CREATED); + + if( cur->session->puser ) + plugin.Call(WINIX_USER_LOGGED); } cur->session = &temporary_session; diff --git a/db/dbbase.cpp b/db/dbbase.cpp index 93796bd..393fcd7 100755 --- a/db/dbbase.cpp +++ b/db/dbbase.cpp @@ -104,7 +104,7 @@ void DbBase::AssertResult(PGresult * r, ExecStatusType t) { if( PQresultStatus(r) != t ) { - log << "Db: Incorrect result status: " << PQerrorMessage(db_conn->GetPgConn()) << logend; + log << log1 << "Db: Incorrect result status: " << PQerrorMessage(db_conn->GetPgConn()) << logend; throw Error(WINIX_ERR_DB_INCORRENT_RESULT_STATUS); } diff --git a/functions/Makefile.dep b/functions/Makefile.dep index 23994de..e4fb19e 100755 --- a/functions/Makefile.dep +++ b/functions/Makefile.dep @@ -462,6 +462,12 @@ login.o: ../templates/misc.h ../templates/htmltextstream.h ../core/mounts.h login.o: ../core/mountparser.h ../core/crypt.h ../core/users.h login.o: ../core/groups.h ../core/group.h ../core/loadavg.h ../core/image.h login.o: ../core/basethread.h ../core/threadmanager.h ../core/synchro.h +login.o: ../core/plugin.h ../core/pluginmsg.h ../core/system.h +login.o: ../core/sessionmanager.h ../core/sessioncontainer.h +login.o: ../functions/functions.h ../templates/templates.h +login.o: ../templates/patterncacher.h ../templates/indexpatterns.h +login.o: ../templates/patterns.h ../templates/changepatterns.h +login.o: ../core/sessionmanager.h logout.o: logout.h functionbase.h ../core/item.h ../db/db.h ../db/dbbase.h logout.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h logout.o: ../core/misc.h ../core/item.h ../core/requesttypes.h diff --git a/functions/login.cpp b/functions/login.cpp index eab02e3..ee2bd9f 100755 --- a/functions/login.cpp +++ b/functions/login.cpp @@ -9,6 +9,7 @@ #include "login.h" #include "utf8.h" +#include "core/plugin.h" @@ -114,6 +115,9 @@ void Login::MakePost() if( CheckUserPass(login, pass, user_id) ) { system->users.LoginUser(user_id, !remem.empty()); + + if( cur->session->puser ) + plugin.Call(WINIX_USER_LOGGED); } else { diff --git a/html/fun_reload.html b/html/fun_reload.html index b69579a..594694b 100755 --- a/html/fun_reload.html +++ b/html/fun_reload.html @@ -11,8 +11,8 @@
  • {reload_tickets}
  • [end] -[if winix_has_plugin "groupitem"] -
  • {reload_groupitem}
  • +[if winix_has_plugin "group"] +
  • {reload_group}
  • [end] [if winix_has_plugin "export"] diff --git a/locale/en b/locale/en index 02a2ae5..eeca958 100755 --- a/locale/en +++ b/locale/en @@ -152,7 +152,7 @@ reload_header = Reload reload_select = Choose an item to reload reload_templates = html templates reload_tickets = tickets config files -reload_groupitem = groups config files +reload_group = groups config files reload_export = export directories (FTP) diff --git a/locale/pl b/locale/pl index 83c3f46..a01d966 100755 --- a/locale/pl +++ b/locale/pl @@ -170,7 +170,7 @@ reload_header = Przeładuj reload_select = Wybierz pozycję reload_templates = szablony html reload_tickets = pliki konfiguracyjne ticketów -reload_groupitem = pliki konfiguracyjne grup +reload_group = pliki konfiguracyjne grup reload_export = katalogi exportu (FTP) diff --git a/plugins/groupitem/Makefile b/plugins/group/Makefile similarity index 95% rename from plugins/groupitem/Makefile rename to plugins/group/Makefile index 5c2081f..84f9c6b 100755 --- a/plugins/groupitem/Makefile +++ b/plugins/group/Makefile @@ -1,6 +1,6 @@ include Makefile.o.dep -name = groupitem.so +name = group.so all: $(name) diff --git a/plugins/groupitem/Makefile.dep b/plugins/group/Makefile.dep similarity index 98% rename from plugins/groupitem/Makefile.dep rename to plugins/group/Makefile.dep index 917b3d5..ffe54cf 100755 --- a/plugins/groupitem/Makefile.dep +++ b/plugins/group/Makefile.dep @@ -30,7 +30,7 @@ groupinfo.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h groupinfo.o: ../../core/users.h ../../core/loadavg.h ../../core/image.h groupinfo.o: ../../core/basethread.h ../../core/threadmanager.h groupinfo.o: ../../core/log.h -groups.o: groups.h ../../core/log.h +groups.o: groups.h ../../core/confparser.h ../../core/log.h init.o: ../../core/log.h ../../core/plugin.h ../../core/pluginmsg.h init.o: ../../core/log.h ../../core/textstream.h ../../core/logmanipulators.h init.o: ../../core/slog.h ../../core/cur.h ../../core/request.h @@ -138,4 +138,4 @@ templates.o: ../../functions/stat.h ../../functions/subject.h templates.o: ../../functions/template.h ../../functions/tinymce.h templates.o: ../../functions/uname.h ../../functions/upload.h templates.o: ../../functions/uptime.h ../../functions/who.h -templates.o: ../../functions/vim.h groupinfo.h +templates.o: ../../functions/vim.h groupinfo.h ../../core/misc.h diff --git a/plugins/groupitem/Makefile.o.dep b/plugins/group/Makefile.o.dep similarity index 100% rename from plugins/groupitem/Makefile.o.dep rename to plugins/group/Makefile.o.dep diff --git a/plugins/groupitem/groupinfo.cpp b/plugins/group/groupinfo.cpp similarity index 77% rename from plugins/groupitem/groupinfo.cpp rename to plugins/group/groupinfo.cpp index 2064b2b..b1f8bea 100755 --- a/plugins/groupitem/groupinfo.cpp +++ b/plugins/group/groupinfo.cpp @@ -20,7 +20,6 @@ namespace GroupItem GroupInfo::GroupInfo() { mount_par_group_conf = -1; - mount_par_group_lang_conf = -1; } @@ -30,6 +29,12 @@ void GroupInfo::SetSystem(System * psystem) } +void GroupInfo::SetConfig(Config * pconfig) +{ + config = pconfig; +} + + Groups * GroupInfo::FindGroups(long dir_id) { GroupsWrap::iterator i = groups_wrap.find(dir_id); @@ -45,25 +50,19 @@ Groups * GroupInfo::FindGroups(long dir_id) bool GroupInfo::ParseGroups(const std::wstring & str, Groups & groups) { groups.Clear(); - + Space & space = *groups.GetSpace(); conf_parser.SetSpace(space); - conf_parser.UTF8(true); + conf_parser.UTF8(config->utf8); if( conf_parser.ParseString(str) == ConfParser::ok ) { - Space::Table::iterator i; - - for(i=space.table.begin() ; i!=space.table.end() ; ++i) - { - groups.AddGroup(); - log << log1 << "stworzylem nowa grupe" << logend; - - for(size_t a=0 ; asecond.size() ; ++a) - { - groups.AddPath(i->second[a]); - log << log1 << " dodalem sciezke: " << i->second[a] << logend; - } - } + groups.Reindex(); + } + else + { + slog << logerror << "Syntax error in line: " << conf_parser.line << logend; + log << log1 << "Syntax error in line: " << conf_parser.line << logend; + groups.Clear(); } return conf_parser.status == ConfParser::ok; @@ -172,33 +171,6 @@ void GroupInfo::ReadGroupsConfigs(bool skip_existing_configs) -void GroupInfo::PrintGroups() -{ - GroupsWrap::iterator i = groups_wrap.begin(); - - for( ; i != groups_wrap.end() ; ++i) - { - log << "grupy dla dir_id: " << i->first << logend; - - Groups & g = i->second.groups; - - log << "rozmiar: " << g.Size() << logend; - - for(size_t a=0 ; a GroupsWrap + // map[mount_dir_id] -> GroupsWrapItem typedef std::map GroupsWrap; GroupsWrap groups_wrap; - Space space; ConfParser conf_parser; std::vector config_dir_tab; Item config_file; diff --git a/plugins/group/groups.cpp b/plugins/group/groups.cpp new file mode 100755 index 0000000..44289e8 --- /dev/null +++ b/plugins/group/groups.cpp @@ -0,0 +1,216 @@ +/* + * This file is a part of Winix + * and is not publicly distributed + * + * Copyright (c) 2011, Tomasz Sowa + * All rights reserved. + * + */ + +#include +#include "groups.h" +#include "core/log.h" + + +namespace GroupItem +{ + + + +Space * Groups::GetSpace() +{ + return &space; +} + + + +void Groups::Reindex() +{ + set_index.clear(); + group_index_tab.clear(); + size_t seti = 0; + + while( seti < space.spaces.size() ) + { + const std::wstring & name = space.spaces[seti]->name; + + if( set_index.find(name) == set_index.end() ) + { + set_index[name] = seti; + group_index_tab.push_back(GroupIndex()); + ReindexGroups(group_index_tab.back(), *space.spaces[seti]); + seti += 1; + } + else + { + slog << logerror << "set: " << name << " already defined (skipping)" << logend; + space.spaces.erase(space.spaces.begin() + seti); + } + } +} + + +void Groups::ReindexGroups(GroupIndex & group_index, Space & set) +{ +size_t i, v; + + // loop through all groups in the set + for( i=0 ; i < set.spaces.size() ; ++i ) + { + Space & group = *set.spaces[i]; + const std::wstring & key = group.Text(L"key", L"value"); + + // loop through all values in the group + for(v=0 ; vtable.find(key); + + if( vali != group.spaces[v]->table.end() && vali->second.size() == 1 ) + { + GroupIndex::iterator g = group_index.find(vali->second[0]); + + if( g == group_index.end() ) + { + group_index[vali->second[0]] = i; + v += 1; + } + else + { + slog << logwarning << "set: " << set.name << " has a group with a duplicated value: " + << vali->second[0] << " (skipping)" << logend; + group.spaces.erase(group.spaces.begin() + v); + } + } + else + { + slog << logwarning << "set: " << set.name << " has a group without a value (skipping)" << logend; + group.spaces.erase(group.spaces.begin() + v); + } + } + + SortValues(group); + } +} + + +void Groups::SortValues(Space & group) +{ + sort_by = group.Text(L"sort_by"); + sort_asc = (group.Text(L"sort_asc", L"true") == L"true"); + + if( !sort_by.empty() ) + { + group.ListText(L"sort", sort_value); + std::sort(group.spaces.begin(), group.spaces.end(), SortFunHelper(this)); + } +} + + +bool Groups::SortFunHelper::operator()(Space * sp1, Space * sp2) +{ + const std::wstring & val1 = sp1->Text(groups->sort_by, L""); + const std::wstring & val2 = sp2->Text(groups->sort_by, L""); + + if( groups->sort_asc ) + return SortValue(val1) < SortValue(val2); + else + return SortValue(val1) > SortValue(val2); +} + + +size_t Groups::SortFunHelper::SortValue(const std::wstring & val) +{ + for(size_t i=0 ; isort_value.size() ; ++i) + if( val == groups->sort_value[i] ) + return i; + +return std::numeric_limits::max(); +} + + + +bool Groups::Find(const std::wstring & set, const std::wstring & value, size_t & seti, size_t & groupi) +{ + SetIndex::iterator i = set_index.find(set); + + if( i != set_index.end() ) + { + if( i->second < group_index_tab.size() ) + { + GroupIndex::iterator viter = group_index_tab[i->second].find(value); + + if( viter != group_index_tab[i->second].end() ) + { + seti = i->second; + groupi = viter->second; + return true; + } + } + } + +return false; +} + + + +const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option) +{ + if( seti < space.spaces.size() ) + { + Space & groups = *space.spaces[seti]; + + if( groupi < groups.spaces.size() ) + { + Space & value = *groups.spaces[groupi]; + + if( valuei < value.spaces.size() ) + return value.spaces[valuei]->Text(option); + + } + } + +return empty_str; +} + + +const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const std::wstring & option) +{ + return GetOption(seti, groupi, valuei, option.c_str()); +} + + +size_t Groups::Size(size_t seti, size_t groupi) +{ + if( seti < space.spaces.size() ) + { + Space & groups = *space.spaces[seti]; + + if( groupi < groups.spaces.size() ) + return groups.spaces[groupi]->spaces.size(); + } + +return 0; +} + + + + + + + +void Groups::Clear() +{ + space.Clear(); + set_index.clear(); + group_index_tab.clear(); +} + + + + + + + +} + + diff --git a/plugins/group/groups.h b/plugins/group/groups.h new file mode 100755 index 0000000..a5104a0 --- /dev/null +++ b/plugins/group/groups.h @@ -0,0 +1,130 @@ +/* + * This file is a part of Winix + * and is not publicly distributed + * + * Copyright (c) 2011, Tomasz Sowa + * All rights reserved. + * + */ + +#ifndef headerfile_winix_plugins_groupitem_groups +#define headerfile_winix_plugins_groupitem_groups + +#include +#include +#include +#include "core/confparser.h" + + + +namespace GroupItem +{ + + +class Groups +{ +public: + + /* + reading all space + (sets and groups) + */ + Space * GetSpace(); + + + /* + building all indexes + */ + void Reindex(); + + + bool Find(const std::wstring & set, const std::wstring & value, size_t & seti, size_t & groupi); + + + + /* + */ + size_t Size(size_t seti, size_t groupi); + + const std::wstring & GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option); + const std::wstring & GetOption(size_t seti, size_t groupi, size_t valuei, const std::wstring & option); + + + /* + removing all groups + */ + void Clear(); + + +private: + + /* + our space: + set1 ( + + # group1 + ( + ( value = "value1" + other = "foo" ) + + ( value = "something" + other = "x" ) + ) + + # group2 + ( + + ) + + ) # end of set1 + + # we can have more sets + # sets should have a unique name + # groups don't have a name + */ + Space space; + + + /* + indexes to a set of groups + */ + typedef std::map SetIndex; + SetIndex set_index; + + /* + indexes to a groups in a set + mapping: value->group index + */ + typedef std::map GroupIndex; + + /* + group indexes in a specified set + std::vector + */ + std::vector group_index_tab; + + const std::wstring empty_str; + + + std::wstring sort_by; + bool sort_asc; + Space::Value sort_value; + + struct SortFunHelper + { + Groups * groups; + SortFunHelper(Groups * pgroups) : groups(pgroups) {}; + size_t SortValue(const std::wstring & val); + bool operator()(Space * sp1, Space * sp2); + }; + + + + void ReindexGroups(GroupIndex & group_index, Space & set); + void SortValues(Space & group); +}; + +} + +#endif + diff --git a/plugins/groupitem/init.cpp b/plugins/group/init.cpp similarity index 77% rename from plugins/groupitem/init.cpp rename to plugins/group/init.cpp index 7f4b2fa..f0b3649 100755 --- a/plugins/groupitem/init.cpp +++ b/plugins/group/init.cpp @@ -20,7 +20,7 @@ extern "C" void Init(PluginInfo &); namespace GroupItem { -const wchar_t plugin_name[] = L"groupitem"; +const wchar_t plugin_name[] = L"group"; GroupInfo group_info; @@ -28,16 +28,13 @@ GroupInfo group_info; void AddMountPar(PluginInfo & info) { - group_info.mount_par_group_conf = info.system->mounts.AddMountPar(L"group_conf"); - group_info.mount_par_group_lang_conf = info.system->mounts.AddMountPar(L"group_lang_conf"); + group_info.mount_par_group_conf = info.system->mounts.AddMountPar(L"group_conf"); } void FstabChanged(PluginInfo & info) { group_info.ReadGroupsConfigs(true); - - group_info.PrintGroups(); } @@ -45,7 +42,7 @@ void ProcessRequest(PluginInfo & info) { if( info.cur->request->function == &info.functions->fun_reload ) { - if( info.cur->request->IsParam(L"groupitem") ) + if( info.cur->request->IsParam(L"group") ) group_info.ReadGroupsConfigs(false); } } @@ -71,6 +68,7 @@ using namespace GroupItem; plugin.Assign(WINIX_PROCESS_REQUEST, ProcessRequest); group_info.SetSystem(info.system); + group_info.SetConfig(info.config); info.p1 = (void*)(plugin_name); } diff --git a/plugins/group/templates.cpp b/plugins/group/templates.cpp new file mode 100755 index 0000000..1938c76 --- /dev/null +++ b/plugins/group/templates.cpp @@ -0,0 +1,128 @@ +/* + * This file is a part of Winix + * and is not publicly distributed + * + * Copyright (c) 2011, Tomasz Sowa + * All rights reserved. + * + */ + +#include "templates/templates.h" +#include "core/plugin.h" +#include "groupinfo.h" +#include "core/misc.h" + + + +namespace GroupItem +{ +using namespace TemplatesFunctions; +using TemplatesFunctions::system; + + +extern GroupInfo group_info; + + +static bool group_tab_found = false; +static Groups * pgroups; +static size_t req_id = 0; +static size_t set_index; +static size_t group_index; +static size_t value_index; +static std::wstring last_set, last_value; +static std::wstring path; + + + + +void group_tab_init(const std::wstring & set, const std::wstring & value) +{ + if( req_id != cur->request->id || last_set != set || last_value != value ) + { + req_id = cur->request->id; + pgroups = group_info.FindGroups(cur->mount->dir_id); + last_set = set; + last_value = value; + group_tab_found = false; + + if( pgroups && pgroups->Find(set, value, set_index, group_index) ) + group_tab_found = true; + } +} + + + + +void group_tab(Info & i) +{ + if( i.params.size() == 2 ) + { + group_tab_init(i.params[0], i.params[1]); + value_index = i.iter; + + if( group_tab_found ) + i.res = value_index < pgroups->Size(set_index, group_index); + } + else + { + group_tab_found = false; + } +} + + +void group_link_tab(Info & i) +{ + if( i.params.size() == 1 ) + { + system->dirs.MakePath(cur->request->dir_tab, path); + + if( cur->request->is_item ) + path += cur->request->item.url; + else + NoLastSlash(path); + + group_tab_init(i.params[0], path); + value_index = i.iter; + + if( group_tab_found ) + i.res = value_index < pgroups->Size(set_index, group_index); + } + else + { + group_tab_found = false; + } +} + + + +void group_tab_value(Info & i) +{ + if( group_tab_found ) + { + if( !i.par.empty() ) + i.out << pgroups->GetOption(set_index, group_index, value_index, i.par); + else + i.out << pgroups->GetOption(set_index, group_index, value_index, L"value"); + } +} + + + +void AddEzcFunctions(PluginInfo & info) +{ + using TemplatesFunctions::EzcFun; + EzcFun * fun = reinterpret_cast(info.p1); + + /* + */ + fun->Insert("group_tab", group_tab); + fun->Insert("group_link_tab", group_link_tab); + fun->Insert("group_tab_value", group_tab_value); +} + + +} // namespace + + + + diff --git a/plugins/groupitem/groups.cpp b/plugins/groupitem/groups.cpp deleted file mode 100755 index ab33179..0000000 --- a/plugins/groupitem/groups.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * This file is a part of Winix - * and is not publicly distributed - * - * Copyright (c) 2011, Tomasz Sowa - * All rights reserved. - * - */ - -#include "groups.h" -#include "core/log.h" - - - -namespace GroupItem -{ - - -size_t Groups::AddGroup() -{ - groups_tab.push_back(paths_names.size()); - -return groups_tab.size()-1; -} - - -void Groups::AddPath(const std::wstring & path) -{ - if( groups_tab.empty() ) - { - log << log1 << "GroupItem: cannot add a path (there are not any groups)" << logend; - return; - } - - size_t group_index = groups_tab.size()-1; - std::pair res = paths_map.insert(std::make_pair(path, group_index)); - - if( !res.second ) - return; - - paths_names.push_back(&(res.first->first)); -} - - - -size_t Groups::Find(const std::wstring & path) -{ - log << "mapa: " << logend; - - PathsMap::iterator a = paths_map.begin(); - - for( ; a != paths_map.end() ; ++a ) - { - log << a->first << " -> " << a->second << logend; - } - - - - - PathsMap::iterator i = paths_map.find(path); - - if( i == paths_map.end() ) - return groups_tab.size(); - -return i->second; -} - - - -size_t Groups::Size() -{ - return groups_tab.size(); -} - - -size_t Groups::GroupSize(size_t group_index) -{ - if( group_index >= groups_tab.size() ) - return 0; - - if( group_index+1 == groups_tab.size() ) - return paths_names.size() - groups_tab[group_index]; - -return groups_tab[group_index+1] - groups_tab[group_index]; -} - - -const std::wstring & Groups::GroupPath(size_t group_index, size_t path_index) -{ - if( group_index >= groups_tab.size() ) - return empty_str; - - size_t index = groups_tab[group_index] + path_index; - - if( index >= paths_names.size() ) - return empty_str; - -return *paths_names[index]; -} - - - - -void Groups::Clear() -{ - paths_map.clear(); - groups_tab.clear(); - paths_names.clear(); -} - - - - - - - -} - - diff --git a/plugins/groupitem/groups.h b/plugins/groupitem/groups.h deleted file mode 100755 index c6a4f3c..0000000 --- a/plugins/groupitem/groups.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * This file is a part of Winix - * and is not publicly distributed - * - * Copyright (c) 2011, Tomasz Sowa - * All rights reserved. - * - */ - -#ifndef headerfile_winix_plugins_groupitem_groups -#define headerfile_winix_plugins_groupitem_groups - -#include -#include -#include - - - -namespace GroupItem -{ - - -class Groups -{ -public: - - - /* - adding a new group - this method returns a group index - */ - size_t AddGroup(); - - - /* - adding a new path to the last group - */ - void AddPath(const std::wstring & path); - - - - /* - finding a group which has the specified path - this method returns a group index - if there is not such a path everywhere then group size is returned - */ - size_t Find(const std::wstring & path); - - - /* - returning how many groups we have - */ - size_t Size(); - - - /* - returning the size of the specified group - */ - size_t GroupSize(size_t group_index); - - - /* - returning a path of the specified group and position - or en empty string if indexes are out of ranges - */ - const std::wstring & GroupPath(size_t group_index, size_t path_index); - - - /* - removing all groups - */ - void Clear(); - - -private: - - /* - paths_map[L"path_name"] -> group index - */ - typedef std::map PathsMap; - PathsMap paths_map; - - /* - groups[group_index] -> index in paths_names - the group consists of elements from - groups_tab[groups_index] to groups_tab[groups_index+1] (without the last one) - */ - typedef std::vector GroupsTab; - GroupsTab groups_tab; - - - /* - paths_names - */ - typedef std::vector PathsNames; - PathsNames paths_names; - - - const std::wstring empty_str; -}; - -} - -#endif - diff --git a/plugins/groupitem/templates.cpp b/plugins/groupitem/templates.cpp deleted file mode 100755 index e957d15..0000000 --- a/plugins/groupitem/templates.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is a part of Winix - * and is not publicly distributed - * - * Copyright (c) 2011, Tomasz Sowa - * All rights reserved. - * - */ - -#include "templates/templates.h" -#include "core/plugin.h" -#include "groupinfo.h" - - -namespace GroupItem -{ -using namespace TemplatesFunctions; -using TemplatesFunctions::system; - - -extern GroupInfo group_info; - - -static size_t group_tab_reqid = 0; -static bool group_tab_found = false; -static Groups * pgroups; -static size_t group_index; -static size_t group_tab_index; -static std::wstring group_last_path; - - - - -void group_tab_init(const std::wstring & path) -{ - if( group_tab_reqid != cur->request->id || group_last_path != path) - { - group_tab_found = false; - group_tab_reqid = cur->request->id; - group_last_path = path; - pgroups = group_info.FindGroups(cur->request->dir_tab.back()->id); - - if( pgroups ) - { - group_tab_found = true; - group_index = pgroups->Find(path); - } - } -} - - - - -void group_tab(Info & i) -{ - group_tab_init(i.par); - group_tab_index = i.iter; - - if( group_tab_found ) - i.res = group_tab_index < pgroups->GroupSize(group_index); -} - - - -void group_tab_link(Info & i) -{ - if( group_tab_found ) - i.out << pgroups->GroupPath(group_index, group_tab_index); -} - - - -void AddEzcFunctions(PluginInfo & info) -{ - using TemplatesFunctions::EzcFun; - EzcFun * fun = reinterpret_cast(info.p1); - - fun->Insert("group_tab", group_tab); - fun->Insert("group_tab_link", group_tab_link); -} - - -} // namespace - - - - diff --git a/templates/mount.cpp b/templates/mount.cpp index 6749a7d..00cfe79 100755 --- a/templates/mount.cpp +++ b/templates/mount.cpp @@ -23,27 +23,39 @@ void mount_type_is(Info & i) if( mount_type_id == -1 ) return; - i.res = (system->mounts.pmount->type == mount_type_id); + i.res = (cur->mount->type == mount_type_id); } void mount_page_arg_is(Info & i) { - i.res = system->mounts.pmount->IsArg(system->mounts.MountParPage(), i.par); + i.res = cur->mount->IsArg(system->mounts.MountParPage(), i.par); +} + + +void mount_lang_arg(Info & i) +{ + i.out << cur->mount->FirstArg(system->mounts.MountParLang()); +} + + +void mount_lang_arg_is(Info & i) +{ + i.res = cur->mount->IsArg(system->mounts.MountParLang(), i.par); } void mount_has_html_template(Info & i) { - i.res = system->mounts.pmount->param[system->mounts.MountParHtmlTemplate()].defined; + i.res = cur->mount->param[system->mounts.MountParHtmlTemplate()].defined; } void mount_first_html_template(Info & i) { - Mount::ParamRow & par = system->mounts.pmount->param[system->mounts.MountParHtmlTemplate()]; + Mount::ParamRow & par = cur->mount->param[system->mounts.MountParHtmlTemplate()]; if( par.defined && !par.arg.empty() ) i.out << par.arg[0]; diff --git a/templates/templates.cpp b/templates/templates.cpp index ebcb87b..576356a 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -344,6 +344,8 @@ void Templates::CreateFunctions() */ ezc_functions.Insert("mount_type_is", mount_type_is); ezc_functions.Insert("mount_page_arg_is", mount_page_arg_is); + ezc_functions.Insert("mount_lang_arg", mount_lang_arg); + ezc_functions.Insert("mount_lang_arg_is", mount_lang_arg_is); ezc_functions.Insert("mount_has_html_template", mount_has_html_template); ezc_functions.Insert("mount_first_html_template", mount_first_html_template); ezc_functions.Insert("mount_css_tab", mount_css_tab); diff --git a/templates/templates.h b/templates/templates.h index 619bc84..f69225e 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -267,6 +267,8 @@ namespace TemplatesFunctions */ void mount_type_is(Info & i); void mount_page_arg_is(Info & i); + void mount_lang_arg(Info & i); + void mount_lang_arg_is(Info & i); void mount_has_html_template(Info & i); void mount_first_html_template(Info & i); void mount_css_tab(Info & i);