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
This commit is contained in:
Tomasz Sowa 2011-10-16 21:33:45 +00:00
parent c7b6ca67a2
commit 0550212b64
28 changed files with 594 additions and 401 deletions

View File

@ -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

View File

@ -345,33 +345,54 @@ return false;
void Space::Print(std::wostream & out)
void Space::PrintLevel(std::wostream & out, int level)
{
for(int i=0 ; i<level ; ++i)
out << ' ';
}
void Space::Print(std::wostream & out, int level)
{
PrintLevel(out, level);
out << "Space name: " << name << std::endl;
out << "table_single: " << std::endl;
TableSingle::iterator i1;
for(i1 = table_single.begin() ; i1 != table_single.end() ; ++i1)
out << i1->first << '=' << 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 ; i<spaces.size() ; ++i)
spaces[i]->Print(out);
spaces[i]->Print(out, level+1);
}

View File

@ -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);
};

View File

@ -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");
}

View File

@ -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;

View File

@ -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")

View File

@ -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;

View File

@ -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);
}

View File

@ -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

View File

@ -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
{

View File

@ -11,8 +11,8 @@
<li><a href="[doc_base_url][dir]reload/tickets">{reload_tickets}</a></li>
[end]
[if winix_has_plugin "groupitem"]
<li><a href="[doc_base_url][dir]reload/groupitem">{reload_groupitem}</a></li>
[if winix_has_plugin "group"]
<li><a href="[doc_base_url][dir]reload/group">{reload_group}</a></li>
[end]
[if winix_has_plugin "export"]

View File

@ -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)

View File

@ -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)

View File

@ -1,6 +1,6 @@
include Makefile.o.dep
name = groupitem.so
name = group.so
all: $(name)

View File

@ -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

View File

@ -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 ; a<i->second.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<g.Size() ; ++a )
{
log << "grupa: " << a << logend;
log << "sciezek: " << g.GroupSize(a) << logend;
for(size_t x=0 ; x<g.GroupSize(a) ; ++x)
{
log << " " << g.GroupPath(a, x) << logend;
}
}
}
}

View File

@ -16,6 +16,7 @@
#include "core/confparser.h"
#include "core/item.h"
#include "core/system.h"
#include "core/config.h"
@ -47,25 +48,25 @@ public:
GroupInfo();
void SetSystem(System * psystem);
void SetConfig(Config * pconfig);
void ReadGroupsConfigs(bool skip_existing_configs);
Groups * FindGroups(long dir_id); // can return a null pointer
int mount_par_group_conf;
int mount_par_group_lang_conf;
void PrintGroups();
private:
System * system;
Config * config;
// map[dir_id] -> GroupsWrap
// map[mount_dir_id] -> GroupsWrapItem
typedef std::map<long, GroupsWrapItem> GroupsWrap;
GroupsWrap groups_wrap;
Space space;
ConfParser conf_parser;
std::vector<Item*> config_dir_tab;
Item config_file;

216
plugins/group/groups.cpp Executable file
View File

@ -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 <limits>
#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 ; v<group.spaces.size() ; )
{
Space::Table::iterator vali = group.spaces[v]->table.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 ; i<groups->sort_value.size() ; ++i)
if( val == groups->sort_value[i] )
return i;
return std::numeric_limits<size_t>::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();
}
}

130
plugins/group/groups.h Executable file
View File

@ -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 <map>
#include <vector>
#include <string>
#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<std::wstring, size_t> SetIndex;
SetIndex set_index;
/*
indexes to a groups in a set
mapping: value->group index
*/
typedef std::map<std::wstring, size_t> GroupIndex;
/*
group indexes in a specified set
std::vector<how many sets there are>
*/
std::vector<GroupIndex> 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

View File

@ -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);
}

128
plugins/group/templates.cpp Executable file
View File

@ -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<EzcFun*>(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

View File

@ -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<PathsMap::iterator, bool> 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();
}
}

View File

@ -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 <map>
#include <vector>
#include <string>
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<std::wstring, size_t> 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<size_t> GroupsTab;
GroupsTab groups_tab;
/*
paths_names
*/
typedef std::vector<const std::wstring*> PathsNames;
PathsNames paths_names;
const std::wstring empty_str;
};
}
#endif

View File

@ -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<EzcFun*>(info.p1);
fun->Insert("group_tab", group_tab);
fun->Insert("group_tab_link", group_tab_link);
}
} // namespace

View File

@ -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];

View File

@ -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);

View File

@ -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);