2011-10-16 23:33:45 +02:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-31 00:47:43 +01:00
|
|
|
|
|
|
|
void build_current_path()
|
2011-10-16 23:33:45 +02:00
|
|
|
{
|
2011-10-31 00:47:43 +01:00
|
|
|
system->dirs.MakePath(cur->request->dir_tab, path);
|
|
|
|
|
|
|
|
if( cur->request->is_item )
|
|
|
|
{
|
|
|
|
path += cur->request->item.url;
|
|
|
|
}
|
|
|
|
else
|
2011-10-16 23:33:45 +02:00
|
|
|
{
|
2011-10-31 00:47:43 +01:00
|
|
|
// we assume that directories are without the last trailing slash
|
|
|
|
NoLastSlash(path);
|
|
|
|
}
|
|
|
|
}
|
2011-10-16 23:33:45 +02:00
|
|
|
|
|
|
|
|
2011-10-31 00:47:43 +01:00
|
|
|
|
|
|
|
void group_link_tab(Info & i)
|
|
|
|
{
|
|
|
|
if( i.params.size() == 1 )
|
|
|
|
{
|
|
|
|
build_current_path();
|
2011-10-16 23:33:45 +02:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-31 00:47:43 +01:00
|
|
|
void group_tab_is_current_link(Info & i)
|
|
|
|
{
|
|
|
|
if( group_tab_found )
|
|
|
|
{
|
|
|
|
build_current_path();
|
|
|
|
|
|
|
|
if( !i.par.empty() )
|
|
|
|
i.res = (pgroups->GetOption(set_index, group_index, value_index, i.par) == path);
|
|
|
|
else
|
|
|
|
i.res = (pgroups->GetOption(set_index, group_index, value_index, L"value") == path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-16 23:33:45 +02:00
|
|
|
|
|
|
|
void AddEzcFunctions(PluginInfo & info)
|
|
|
|
{
|
|
|
|
using TemplatesFunctions::EzcFun;
|
|
|
|
EzcFun * fun = reinterpret_cast<EzcFun*>(info.p1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
2011-10-31 00:47:43 +01:00
|
|
|
fun->Insert("group_tab", group_tab);
|
|
|
|
fun->Insert("group_link_tab", group_link_tab);
|
|
|
|
fun->Insert("group_tab_value", group_tab_value);
|
|
|
|
fun->Insert("group_tab_is_current_link", group_tab_is_current_link);
|
2011-10-16 23:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|