updated to the new Pikotools api (new Space struct)

This commit is contained in:
2021-04-09 17:50:58 +02:00
parent 00b980e74b
commit 35e10ed469
52 changed files with 795 additions and 736 deletions

View File

@@ -330,23 +330,27 @@ void ExportInfo::SendAllFilesFromDir(long dir_id)
void ExportInfo::AdditionalExport(const Item & item)
{
for(size_t i=0 ; i<item.item_content.meta.spaces.size() ; ++i)
if( item.item_content.meta.child_spaces )
{
if( item.item_content.meta.spaces[i]->name == L"export" )
AdditionalExport(item, *item.item_content.meta.spaces[i]);
for(size_t i=0 ; i<item.item_content.meta.child_spaces->size() ; ++i)
{
PT::Space & child = *(*item.item_content.meta.child_spaces)[i];
if( child.name && *child.name == L"export" )
AdditionalExport(item, child);
}
}
}
void ExportInfo::AdditionalExport(const Item & item, PT::Space & meta)
{
if( meta.ListText(L"additional_export", additional_export) )
meta.to_list(L"additional_export", additional_export);
for(size_t i=0 ; i<additional_export.size() ; ++i)
{
for(size_t i=0 ; i<additional_export.size() ; ++i)
{
log << log1 << "exportuje dodatkowo takiego swiniaka: " << additional_export[i] << logend;
AdditionalExport(additional_export[i]);
}
log << log1 << "additional export: " << additional_export[i] << logend;
AdditionalExport(additional_export[i]);
}
}

View File

@@ -121,7 +121,7 @@ void gallery_tab_meta_str(Info & i)
if( gallery_index < gallery_info.item_sort_tab.size() )
{
Item & item = *gallery_info.item_sort_tab[gallery_index];
item.item_content.meta.Serialize(i.out, true, false);
item.item_content.meta.serialize_to_space_stream(i.out, true);
}
}

View File

@@ -80,14 +80,14 @@ bool GroupInfo::ParseGroups(const std::wstring & str, Groups & groups)
PT::Space & space = *groups.GetSpace();
conf_parser.SetSpace(space);
if( conf_parser.ParseString(str) == PT::SpaceParser::ok )
if( conf_parser.ParseSpace(str) == PT::SpaceParser::ok )
{
groups.Reindex();
}
else
{
slog << logerror << "Syntax error in line: " << conf_parser.line << logend;
log << log1 << "Syntax error in line: " << conf_parser.line << logend;
slog << logerror << "Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
log << log1 << "Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
groups.Clear();
}

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2011-2018, Tomasz Sowa
* Copyright (c) 2011-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,21 +59,27 @@ void Groups::Reindex()
group_index_tab.clear();
size_t seti = 0;
while( seti < space.spaces.size() )
if( space.child_spaces )
{
const std::wstring & name = space.spaces[seti]->name;
while( seti < space.child_spaces->size() )
{
PT::Space & sp = *(*space.child_spaces)[seti];
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);
if( sp.name )
{
if( set_index.find(*sp.name) == set_index.end() )
{
set_index[*sp.name] = seti;
group_index_tab.push_back(GroupIndex());
ReindexGroups(group_index_tab.back(), sp);
seti += 1;
}
else
{
slog << logerror << "set: " << sp.name << " already defined (skipping)" << logend;
space.remove_child_space(seti);
}
}
}
}
}
@@ -83,74 +89,83 @@ void Groups::ReindexGroups(GroupIndex & group_index, PT::Space & set)
{
size_t i, v;
// loop through all groups in the set
for( i=0 ; i < set.spaces.size() ; ++i )
if( set.child_spaces )
{
PT::Space & group = *set.spaces[i];
// !! IMPROVE ME will be safer to copy the value out
// if we used accidently the group.Text later the key
// would be overwritten
const std::wstring & key = group.Text(L"key", L"value");
// loop through all values in the group
for(v=0 ; v<group.spaces.size() ; )
// loop through all groups in the set
for( i=0 ; i < set.child_spaces->size() ; ++i )
{
std::wstring * vali = group.spaces[v]->GetFirstValue(key);
PT::Space & group = *(*set.child_spaces)[i];
// !! IMPROVE ME will be safer to copy the value out
// if we used accidently the group.Text later the key
// would be overwritten
std::wstring key = group.to_wstr(L"key", L"value");
if( vali )
if( group.child_spaces )
{
GroupIndex::iterator g = group_index.find(*vali);
if( g == group_index.end() )
// loop through all values in the group
for(v=0 ; v<group.child_spaces->size() ; )
{
group_index[*vali] = i;
v += 1;
}
else
{
slog << logwarning << "set: " << set.name << " has a group with a duplicated value: "
<< *vali << " (skipping)" << logend;
std::wstring * vali = (*group.child_spaces)[v]->get_wstr(key.c_str());
group.spaces.erase(group.spaces.begin() + v);
if( vali )
{
GroupIndex::iterator g = group_index.find(*vali);
if( g == group_index.end() )
{
group_index[*vali] = i;
v += 1;
}
else
{
slog << logwarning << "set: " << set.name << " has a group with a duplicated value: "
<< *vali << " (skipping)" << logend;
group.remove_child_space(v);
}
}
else
{
log << log1 << "key: " << key << " was not found" << logend;
slog << logwarning << "set: " << set.name
<< " has a group without a value (skipping)" << logend;
group.remove_child_space(v);
}
}
}
else
{
log << log1 << "key: " << key << " was not found" << logend;
slog << logwarning << "set: " << set.name
<< " has a group without a value (skipping)" << logend;
group.spaces.erase(group.spaces.begin() + v);
}
SortValues(group);
}
SortValues(group);
}
}
void Groups::SortValues(PT::Space & group)
{
sort_by = group.Text(L"sort_by");
sort_asc = (group.Text(L"sort_asc", L"true") == L"true");
sort_by = group.to_wstr(L"sort_by");
sort_asc = group.is_equal(L"sort_asc", L"true");
if( !sort_by.empty() )
if( !sort_by.empty() && group.child_spaces )
{
group.ListText(L"sort", sort_value);
std::sort(group.spaces.begin(), group.spaces.end(), SortFunHelper(this));
group.to_list(L"sort", sort_value, true);
std::sort(group.child_spaces->begin(), group.child_spaces->end(), SortFunHelper(this));
}
}
bool Groups::SortFunHelper::operator()(PT::Space * sp1, PT::Space * sp2)
{
const std::wstring & val1 = sp1->Text(groups->sort_by, L"");
const std::wstring & val2 = sp2->Text(groups->sort_by, L"");
const std::wstring * val1 = sp1->get_wstr(groups->sort_by.c_str());
const std::wstring * val2 = sp2->get_wstr(groups->sort_by.c_str());
if( !val1 || !val2 )
return false;
if( groups->sort_asc )
return SortValue(val1) < SortValue(val2);
return SortValue(*val1) < SortValue(*val2);
else
return SortValue(val1) > SortValue(val2);
return SortValue(*val1) > SortValue(*val2);
}
@@ -191,16 +206,21 @@ 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() )
if( space.child_spaces && seti < space.child_spaces->size() )
{
PT::Space & groups = *space.spaces[seti];
PT::Space & groups = *(*space.child_spaces)[seti];
if( groupi < groups.spaces.size() )
if( groups.child_spaces && groupi < groups.child_spaces->size() )
{
PT::Space & value = *groups.spaces[groupi];
PT::Space & value = *(*groups.child_spaces)[groupi];
if( valuei < value.spaces.size() )
return value.spaces[valuei]->TextRef(option);
if( value.child_spaces && valuei < value.child_spaces->size() )
{
const std::wstring * res = (*value.child_spaces)[valuei]->get_wstr(option);
if( res )
return *res;
}
}
}
@@ -217,12 +237,12 @@ const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei
size_t Groups::Size(size_t seti, size_t groupi)
{
if( seti < space.spaces.size() )
if( space.child_spaces && seti < space.child_spaces->size() )
{
PT::Space & groups = *space.spaces[seti];
PT::Space & groups = *(*space.child_spaces)[seti];
if( groupi < groups.spaces.size() )
return groups.spaces[groupi]->spaces.size();
if( groups.child_spaces && groupi < groups.child_spaces->size() )
return (*groups.child_spaces)[groupi]->child_spaces->size();
}
return 0;
@@ -236,7 +256,7 @@ return 0;
void Groups::Clear()
{
space.Clear();
space.clear();
set_index.clear();
group_index_tab.clear();
}

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* Copyright (c) 2011-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -136,7 +136,7 @@ private:
std::wstring sort_by;
bool sort_asc;
PT::Space::Value sort_value;
std::vector<std::wstring> sort_value;
struct SortFunHelper
{

View File

@@ -77,16 +77,16 @@ void ReloadConfigFile(PluginInfo & info, Item & file)
PT::SpaceParser parser;
parser.SetSpace(space);
PT::SpaceParser::Status status = parser.ParseString(file.item_content.content_raw);
PT::SpaceParser::Status status = parser.ParseSpace(file.item_content.content_raw);
if( status == PT::SpaceParser::syntax_error )
{
info.log << log1 << "MR: syntax error in file: " << file.url << ", line: " << parser.line << " (skipping this file)" << logend;
info.log << log1 << "MR: syntax error in file: " << file.url << ", line: " << parser.get_last_parsed_line() << " (skipping this file)" << logend;
}
else
if( status == PT::SpaceParser::ok )
{
std::wstring * list_id_str = space.GetFirstValue(L"list_id");
std::wstring * list_id_str = space.get_wstr(L"list_id");
if( list_id_str )
{

View File

@@ -390,7 +390,7 @@ void menu_dir_tab_meta_str(Info & i)
StackItem * sitem = reinterpret_cast<StackItem*>(stack->fun_data);
if( stack->iter < sitem->citem->menu_items.size() )
sitem->citem->menu_items[stack->iter].meta.Serialize(i.out, true, false);
sitem->citem->menu_items[stack->iter].meta.serialize_to_space_stream(i.out, true);
}
}

View File

@@ -77,9 +77,9 @@ void Seo::MakePost()
item.subject = subject;
PT::Space & seo = item.item_content.meta.FindAddSpace(L"seo");
seo.Add(L"description", description);
seo.Add(L"keywords", keywords);
PT::Space & seo = item.item_content.meta.find_add_child_space(L"seo");
seo.add(L"description", description);
seo.add(L"keywords", keywords);
ItemModelData item_model_data;
item_model_data.prepare_unique_url = false;

View File

@@ -80,11 +80,11 @@ bool Reply::HasAccess()
return false;
PT::Space * thread_space = cur->request->item.item_content.meta_admin.FindSpace(L"thread");
PT::Space * thread_space = cur->request->item.item_content.meta_admin.find_child_space(L"thread");
if( thread_space )
{
if( thread_space->Bool(L"closed", false) )
if( thread_space->to_bool(L"closed", false) )
return false;
}

View File

@@ -231,7 +231,7 @@ return DoCommand(query);
long TDb::FindLastAnswer(long file_id)
{
PGresult * r = 0;
Error status = WINIX_ERR_OK;
//Error status = WINIX_ERR_OK;
long last_item_id = -1;
try
@@ -249,7 +249,7 @@ long TDb::FindLastAnswer(long file_id)
}
catch(const Error & e)
{
status = e;
//status = e;
}
ClearResult(r);

View File

@@ -185,7 +185,7 @@ PT::Space & EditTicket::PrepareSpace()
if( is_new )
{
PT::Space * ticket_space = cur->request->item.item_content.meta.FindSpace(L"ticket");
PT::Space * ticket_space = cur->request->item.item_content.meta.find_child_space(L"ticket");
if( ticket_space )
{
@@ -203,11 +203,11 @@ bool EditTicket::CloseTicket()
{
cur->request->item.propagate_connector();
PT::Space & ticket_space = cur->request->item.item_content.meta_admin.FindAddSpace(L"ticket");
ticket_space.Add(L"closed", true);
PT::Space & ticket_space = cur->request->item.item_content.meta_admin.find_add_child_space(L"ticket");
ticket_space.add(L"closed", true);
PT::Space & thread_space = cur->request->item.item_content.meta_admin.FindAddSpace(L"thread");
thread_space.Add(L"closed", true);
PT::Space & thread_space = cur->request->item.item_content.meta_admin.find_add_child_space(L"thread");
thread_space.add(L"closed", true);
//if( db->EditAdminMetaById(cur->request->item.ameta, cur->request->item.id) == WINIX_ERR_OK )
if( cur->request->item.item_content.update() )

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -144,30 +144,36 @@ void SessionData::BuildFileList(std::vector<long> & file_tab, PT::Space & space)
{
file_tab.clear();
for(size_t i=0 ; i<space.spaces.size() ; ++i)
if( space.child_spaces )
{
PT::Space & sp = *space.spaces[i];
for(size_t i=0 ; i<space.child_spaces->size() ; ++i)
{
PT::Space & sp = *(*space.child_spaces)[i];
if( sp.name == L"param" )
CheckFile(file_tab, sp);
if( sp.name && (*sp.name) == L"param" )
CheckFile(file_tab, sp);
}
}
}
void SessionData::CheckFile(std::vector<long> & file_tab, PT::Space & space)
{
for(size_t i=0 ; i<space.spaces.size() ; ++i)
if( space.child_spaces )
{
PT::Space & subsp = *space.spaces[i];
if( subsp.name == L"file" )
for(size_t i=0 ; i<space.child_spaces->size() ; ++i)
{
std::wstring * file_id_str = subsp.GetFirstValue(L"itemid");
PT::Space & subsp = *(*space.child_spaces)[i];
if( file_id_str )
if( subsp.name && *subsp.name == L"file" )
{
long file_id = Tol(*file_id_str);
file_tab.push_back(file_id);
std::wstring * file_id_str = subsp.get_wstr(L"itemid");
if( file_id_str )
{
long file_id = Tol(*file_id_str);
file_tab.push_back(file_id);
}
}
}
}

View File

@@ -173,16 +173,19 @@ PT::Space * find_ticket_param(long param_id, PT::Space & meta)
{
wchar_t param_id_str[50];
// for performane
// should be a little faster in each loop comparing only just text
Toa(param_id, param_id_str, sizeof(param_id_str)/sizeof(wchar_t));
for(size_t i=0 ; i<meta.spaces.size() ; ++i)
if( meta.child_spaces )
{
PT::Space & sp = *meta.spaces[i];
// for performane
// should be a little faster in each loop comparing only just text
Toa(param_id, param_id_str, sizeof(param_id_str)/sizeof(wchar_t));
if( sp.name == L"param" && sp.Text(L"id") == param_id_str )
return &sp;
for(size_t i=0 ; i<meta.child_spaces->size() ; ++i)
{
PT::Space & sp = *(*meta.child_spaces)[i];
if( sp.name && *sp.name == L"param" && sp.is_equal(L"id", param_id_str) )
return &sp;
}
}
return 0;
@@ -226,7 +229,7 @@ size_t par_index;
}
else
{
PT::Space * meta = item_meta.FindSpace(L"ticket");
PT::Space * meta = item_meta.find_child_space(L"ticket");
if( meta )
{
@@ -246,15 +249,19 @@ size_t par_index;
void ticket_print_value_select(Info & i, TicketValue & value)
{
if( value.is_param && value.is_value )
if( value.is_param && value.is_value && value.config_par->child_spaces )
{
for(size_t a=0 ; a<value.config_par->spaces.size() ; ++a)
for(size_t a=0 ; a<value.config_par->child_spaces->size() ; ++a)
{
PT::Space & sp = *value.config_par->spaces[a];
PT::Space & sp = *(*value.config_par->child_spaces)[a];
if( sp.name == L"option" && sp.Long(L"id") == value.ticket_par->intv )
if( sp.name && *sp.name == L"option" && sp.to_long(L"id") == value.ticket_par->intv )
{
i.out << sp.Text(L"value");
std::wstring * val = sp.get_wstr(L"value");
if( val )
i.out << *val;
break;
}
}
@@ -267,7 +274,7 @@ void ticket_print_value(Info & i, TicketValue & value)
if( !value.is_param || !value.is_value )
return;
std::wstring * type = value.config_par->GetFirstValue(L"type");
std::wstring * type = value.config_par->get_wstr(L"type");
if( value.is_in_ticket_par )
{
@@ -281,7 +288,10 @@ void ticket_print_value(Info & i, TicketValue & value)
}
else
{
i.out << value.value_meta->Text(L"value");
std::wstring * val = value.value_meta->get_wstr(L"value");
if( val )
i.out << *val;
}
}
@@ -312,10 +322,10 @@ void ticket_meta_value(Info & i)
void ticket_is_closed(Info & i)
{
PT::Space * ticket_space = ticket_info.item->item_content.meta_admin.FindSpace(L"ticket");
PT::Space * ticket_space = ticket_info.item->item_content.meta_admin.find_child_space(L"ticket");
if( ticket_space )
i.res = ticket_space->Bool(L"closed", false);
i.res = ticket_space->to_bool(L"closed", false);
}
@@ -330,24 +340,27 @@ void ticket_param_value_for_param_id(Info & i)
PT::Space & space = *ticket_info.cur_conf;
int id = Toi(i.par);
for( ; conf_index < space.spaces.size() ; ++conf_index)
if( space.child_spaces )
{
if( space.spaces[conf_index]->name == L"param" &&
space.spaces[conf_index]->Int(L"id") == id )
for( ; conf_index < space.child_spaces->size() ; ++conf_index)
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = space.spaces[conf_index];
value_for_param_id.param_id = value_for_param_id.config_par->Long(L"id");
PT::Space & sp = *(*space.child_spaces)[conf_index];
if( ticket_info.ticket && ticket_info.item )
if( sp.name && *sp.name == L"param" && sp.to_int(L"id") == id )
{
find_ticket_value(value_for_param_id, ticket_info.ticket->par_tab, ticket_info.item->item_content.meta);
ticket_print_value(i, value_for_param_id);
}
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = &sp;
value_for_param_id.param_id = sp.to_long(L"id");
break;
if( ticket_info.ticket && ticket_info.item )
{
find_ticket_value(value_for_param_id, ticket_info.ticket->par_tab, ticket_info.item->item_content.meta);
ticket_print_value(i, value_for_param_id);
}
break;
}
}
}
}
@@ -361,20 +374,21 @@ void ticket_does_param_id_have_value(Info & i)
size_t conf_index = 0;
PT::Space & space = *ticket_info.cur_conf;
if( i.params.size() == 2 )
if( i.params.size() == 2 && space.child_spaces )
{
long id = Tol(i.params[0].str);
long id2 = Tol(i.params[1].str);
for( ; conf_index < space.spaces.size() ; ++conf_index)
for( ; conf_index < space.child_spaces->size() ; ++conf_index)
{
if( space.spaces[conf_index]->name == L"param" &&
space.spaces[conf_index]->Int(L"id") == id )
PT::Space & sp = *(*space.child_spaces)[conf_index];
if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == id )
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = space.spaces[conf_index];
value_for_param_id.param_id = value_for_param_id.config_par->Long(L"id");
value_for_param_id.config_par = &sp;
value_for_param_id.param_id = sp.to_long(L"id");
if( ticket_info.ticket && ticket_info.item )
{
@@ -545,10 +559,10 @@ void tickets_tab_is_closed(Info & i)
if( tickets_value.is_item )
{
PT::Space * ticket_space = tickets_value.item->item_content.meta_admin.FindSpace(L"ticket");
PT::Space * ticket_space = tickets_value.item->item_content.meta_admin.find_child_space(L"ticket");
if( ticket_space )
i.res = ticket_space->Bool(L"closed", false);
i.res = ticket_space->to_bool(L"closed", false);
}
}
@@ -625,22 +639,27 @@ void tickets_tab_param_value_for_param_id(Info & i)
{
size_t param_index = 0;
PT::Space & space = *ticket_info.cur_conf;
int id = Toi(i.par);
long id = Tol(i.par);
for( ; param_index < space.spaces.size() ; ++param_index)
if( space.child_spaces )
{
if( space.spaces[param_index]->name == L"param" &&
space.spaces[param_index]->Int(L"id") == id )
for( ; param_index < space.child_spaces->size() ; ++param_index)
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = space.spaces[param_index];
value_for_param_id.param_id = value_for_param_id.config_par->Long(L"id");
PT::Space & sp = *(*space.child_spaces)[param_index];
find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
ticket_print_value(i, value_for_param_id);
if( sp.name && *sp.name == L"param" &&
sp.to_long(L"id") == id )
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = &sp;
value_for_param_id.param_id = sp.to_long(L"id");
break;
find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
ticket_print_value(i, value_for_param_id);
break;
}
}
}
}
@@ -660,32 +679,36 @@ void tickets_tab_does_param_id_have_value(Info & i)
long id = Toi(i.params[0].str);
long id2 = Toi(i.params[1].str);
for( ; param_index < space.spaces.size() ; ++param_index)
if( space.child_spaces )
{
if( space.spaces[param_index]->name == L"param" &&
space.spaces[param_index]->Int(L"id") == id )
for( ; param_index < space.child_spaces->size() ; ++param_index)
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = space.spaces[param_index];
value_for_param_id.param_id = value_for_param_id.config_par->Long(L"id");
PT::Space & sp = *(*space.child_spaces)[param_index];
find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
if( value_for_param_id.is_value )
if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == id )
{
if( value_for_param_id.is_in_ticket_par )
{
i.res = value_for_param_id.ticket_par->intv == id2;
}
else
{
log << log1 << "Ticket: tickets_tab_does_param_id_have_value cannot be used with meta values"
<< logend;
}
}
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = &sp;
value_for_param_id.param_id = sp.to_long(L"id");
break;
find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
if( value_for_param_id.is_value )
{
if( value_for_param_id.is_in_ticket_par )
{
i.res = value_for_param_id.ticket_par->intv == id2;
}
else
{
log << log1 << "Ticket: tickets_tab_does_param_id_have_value cannot be used with meta values"
<< logend;
}
}
break;
}
}
}
}
@@ -702,17 +725,27 @@ void tickets_tab_conf_tab(Info & i)
conf_index = i.iter;
PT::Space & space = *ticket_info.cur_conf;
while( conf_index < space.spaces.size() && space.spaces[conf_index]->name != L"param" )
conf_index += 1;
i.res = conf_index < space.spaces.size();
if( i.res )
if( space.child_spaces )
{
value.is_param = true;
value.config_par = space.spaces[conf_index];
value.param_id = value.config_par->Long(L"id");
find_ticket_value(value, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
while( conf_index < space.child_spaces->size() )
{
PT::Space & sp = *(*space.child_spaces)[conf_index];
if( sp.name && *sp.name == L"param" )
break;
conf_index += 1;
}
i.res = conf_index < space.child_spaces->size();
if( i.res )
{
value.is_param = true;
value.config_par = (*space.child_spaces)[conf_index];
value.param_id = value.config_par->to_long(L"id");
find_ticket_value(value, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
}
}
}
}
@@ -751,7 +784,7 @@ void tickets_tab_conf_tab_param_name(Info & i)
if( value.is_param )
{
std::wstring * name = value.config_par->GetFirstValue(L"name");
std::wstring * name = value.config_par->get_wstr(L"name");
if( name )
i.out << *name;
@@ -773,7 +806,7 @@ void tickets_tab_conf_tab_type_is(Info & i)
tickets_tab_check_reqid();
if( value.is_param )
i.res = (value.config_par->Text(L"type") == i.par);
i.res = value.config_par->is_equal(L"type", i.par);
}
@@ -809,13 +842,23 @@ void tickets_tab_conf_tab_file_tab(Info & i)
PT::Space & mt = *value.value_meta;
while( tickets_file_index < mt.spaces.size() && mt.spaces[tickets_file_index]->name != L"file" )
tickets_file_index += 1;
if( mt.child_spaces )
{
while( tickets_file_index < mt.child_spaces->size() )
{
PT::Space & sp = *(*mt.child_spaces)[tickets_file_index];
i.res = (tickets_file_index < mt.spaces.size());
if( sp.name && *sp.name == L"file" )
break;
if( i.res && i.iter > 0 )
tickets_file_number += 1;
tickets_file_index += 1;
}
i.res = (tickets_file_index < mt.child_spaces->size());
if( i.res && i.iter > 0 )
tickets_file_number += 1;
}
}
}
@@ -828,7 +871,7 @@ void tickets_tab_conf_tab_file_tab_index(Info & i)
{
PT::Space & mt = *value.value_meta;
if( tickets_file_index < mt.spaces.size() )
if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() )
i.out << tickets_file_number;
}
}
@@ -843,8 +886,8 @@ void tickets_tab_conf_tab_file_tab_path(Info & i)
{
PT::Space & mt = *value.value_meta;
if( tickets_file_index < mt.spaces.size() )
i.out << mt.spaces[tickets_file_index]->Text(L"path");
if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() )
i.out << (*mt.child_spaces)[tickets_file_index]->to_wstr(L"path");
}
}
@@ -857,8 +900,8 @@ void tickets_tab_conf_tab_file_tab_itemid(Info & i)
{
PT::Space & mt = *value.value_meta;
if( tickets_file_index < mt.spaces.size() )
i.out << mt.spaces[tickets_file_index]->Text(L"itemid");
if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() )
i.out << (*mt.child_spaces)[tickets_file_index]->to_wstr(L"itemid");
}
}
@@ -871,8 +914,8 @@ void tickets_tab_conf_tab_file_tab_meta(Info & i)
{
PT::Space & mt = *value.value_meta;
if( tickets_file_index < mt.spaces.size() )
space_value(i, *mt.spaces[tickets_file_index]);
if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() )
space_value(i, *(*mt.child_spaces)[tickets_file_index]);
}
}
@@ -913,19 +956,29 @@ void ticket_tab(Info & i)
conf_index = i.iter;
PT::Space & space = *ticket_info.cur_conf;
while( conf_index < space.spaces.size() && space.spaces[conf_index]->name != L"param" )
conf_index += 1;
i.res = conf_index < space.spaces.size();
if( i.res )
if( space.child_spaces )
{
value.is_param = true;
value.config_par = space.spaces[conf_index];
value.param_id = value.config_par->Long(L"id");
while( conf_index < space.child_spaces->size() )
{
PT::Space & sp = *(*space.child_spaces)[conf_index];
if( ticket_info.ticket && ticket_info.item )
find_ticket_value(value, ticket_info.ticket->par_tab, ticket_info.item->item_content.meta);
if( sp.name && *sp.name == L"param" )
break;
conf_index += 1;
}
i.res = conf_index < space.child_spaces->size();
if( i.res )
{
value.is_param = true;
value.config_par = (*space.child_spaces)[conf_index];
value.param_id = value.config_par->to_long(L"id");
if( ticket_info.ticket && ticket_info.item )
find_ticket_value(value, ticket_info.ticket->par_tab, ticket_info.item->item_content.meta);
}
}
}
@@ -955,7 +1008,7 @@ void ticket_tab_param_name(Info & i)
ticket_tab_check_reqid();
if( value.is_param )
i.out << value.config_par->Text(L"name");
i.out << value.config_par->to_wstr(L"name");
}
@@ -1008,7 +1061,7 @@ void ticket_tab_type_is(Info & i)
ticket_tab_check_reqid();
if( value.is_param )
i.res = (value.config_par->Text(L"type") == i.par);
i.res = value.config_par->is_equal(L"type", i.par);
}
@@ -1021,10 +1074,20 @@ void ticket_tab_select_tab(Info & i)
select_index = i.iter;
PT::Space & sp = *value.config_par;
while( select_index < sp.spaces.size() && sp.spaces[select_index]->name != L"option" )
select_index += 1;
if( sp.child_spaces )
{
while( select_index < sp.child_spaces->size() )
{
PT::Space & sp_child = *(*sp.child_spaces)[select_index];
i.res = (select_index < sp.spaces.size());
if( sp_child.name && *sp_child.name == L"option" )
break;
select_index += 1;
}
i.res = (select_index < sp.child_spaces->size());
}
}
}
@@ -1037,9 +1100,11 @@ void ticket_tab_select_tab_is_selected(Info & i)
{
PT::Space & sp = *value.config_par;
if( select_index < sp.spaces.size() )
if( sp.child_spaces && select_index < sp.child_spaces->size() )
{
long id = sp.spaces[select_index]->Long(L"id");
PT::Space & sp_child = *(*sp.child_spaces)[select_index];
long id = sp_child.to_long(L"id");
if( value.is_value )
{
@@ -1048,7 +1113,7 @@ void ticket_tab_select_tab_is_selected(Info & i)
}
else
{
i.res = (id == sp.Long(L"default"));
i.res = (id == sp.to_long(L"default"));
}
}
}
@@ -1063,8 +1128,8 @@ void ticket_tab_select_tab_name(Info & i)
{
PT::Space & sp = *value.config_par;
if( select_index < sp.spaces.size() )
i.out << sp.spaces[select_index]->Text(L"value");
if( sp.child_spaces && select_index < sp.child_spaces->size() )
i.out << (*sp.child_spaces)[select_index]->to_wstr(L"value");
}
}
@@ -1077,8 +1142,8 @@ void ticket_tab_select_tab_id(Info & i)
{
PT::Space & sp = *value.config_par;
if( select_index < sp.spaces.size() )
i.out << sp.spaces[select_index]->Text(L"id");
if( sp.child_spaces && select_index < sp.child_spaces->size() )
i.out << (*sp.child_spaces)[select_index]->to_wstr(L"id");
}
}
@@ -1090,8 +1155,8 @@ void ticket_tab_select_tab_meta(Info & i)
{
PT::Space & sp = *value.config_par;
if( select_index < sp.spaces.size() )
space_value(i, *sp.spaces[select_index]);
if( sp.child_spaces && select_index < sp.child_spaces->size() )
space_value(i, *(*sp.child_spaces)[select_index]);
}
}
@@ -1110,13 +1175,23 @@ void ticket_tab_file_tab(Info & i)
PT::Space & mt = *value.value_meta;
while( ticket_file_index < mt.spaces.size() && mt.spaces[ticket_file_index]->name != L"file" )
ticket_file_index += 1;
if( mt.child_spaces )
{
while( ticket_file_index < mt.child_spaces->size() )
{
PT::Space & sp = *(*mt.child_spaces)[ticket_file_index];
i.res = (ticket_file_index < mt.spaces.size());
if( sp.name && *sp.name == L"file" )
break;
if( i.res && i.iter > 0 )
ticket_file_number += 1;
ticket_file_index += 1;
}
i.res = (ticket_file_index < mt.child_spaces->size());
if( i.res && i.iter > 0 )
ticket_file_number += 1;
}
}
}
@@ -1129,7 +1204,7 @@ void ticket_tab_file_tab_index(Info & i)
{
PT::Space & mt = *value.value_meta;
if( ticket_file_index < mt.spaces.size() )
if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() )
i.out << ticket_file_number;
}
}
@@ -1143,8 +1218,8 @@ void ticket_tab_file_tab_path(Info & i)
{
PT::Space & mt = *value.value_meta;
if( ticket_file_index < mt.spaces.size() )
i.out << mt.spaces[ticket_file_index]->Text(L"path");
if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() )
i.out << (*mt.child_spaces)[ticket_file_index]->to_wstr(L"path");
}
}
@@ -1156,8 +1231,8 @@ void ticket_tab_file_tab_itemid(Info & i)
{
PT::Space & mt = *value.value_meta;
if( ticket_file_index < mt.spaces.size() )
i.out << mt.spaces[ticket_file_index]->Text(L"itemid");
if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() )
i.out << (*mt.child_spaces)[ticket_file_index]->to_wstr(L"itemid");
}
}
@@ -1169,8 +1244,8 @@ void ticket_tab_file_tab_meta(Info & i)
{
PT::Space & mt = *value.value_meta;
if( ticket_file_index < mt.spaces.size() )
space_value(i, *mt.spaces[ticket_file_index]);
if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() )
space_value(i, *(*mt.child_spaces)[ticket_file_index]);
}
}

View File

@@ -106,7 +106,7 @@ void TicketInfo::Clear()
cur_conf_wrap = &cur_conf_wrap_empty;
cur_conf = &cur_conf_empty;
cur_conf->Clear();
cur_conf->clear();
item_tab.clear();
ticket_tab.clear();
@@ -167,9 +167,9 @@ bool TicketInfo::ParseTicketConf(long mount_dir_id, const std::wstring & path)
conf_tab[mount_dir_id].file_name = path;
conf_parser.SetSpace(conf_tab[mount_dir_id].conf);
conf_tab[mount_dir_id].conf.Clear();
conf_tab[mount_dir_id].conf.clear();
return (conf_parser.ParseString(config_file.item_content.content_raw) == PT::SpaceParser::ok);
return (conf_parser.ParseSpace(config_file.item_content.content_raw) == PT::SpaceParser::ok);
}
@@ -264,15 +264,15 @@ void TicketInfo::FindCurrentConf()
void TicketInfo::CheckMinMaxValue(PT::Space & space, Ticket::TicketParam & par)
{
std::wstring * type = space.GetFirstValue(L"type");
std::wstring * type = space.get_wstr(L"type");
if( !type )
return;
if( *type == L"integer" )
{
std::wstring * min_str = space.GetFirstValue(L"min");
std::wstring * max_str = space.GetFirstValue(L"min");
std::wstring * min_str = space.get_wstr(L"min");
std::wstring * max_str = space.get_wstr(L"min");
if( min_str )
{
@@ -303,16 +303,19 @@ void TicketInfo::CheckMinMaxValue(PT::Space & space, Ticket::TicketParam & par)
else
if( *type == L"select" )
{
for(size_t a=0 ; a<space.spaces.size() ; ++a)
if( space.child_spaces )
{
PT::Space & sp = *space.spaces[a];
for(size_t a=0 ; a<space.child_spaces->size() ; ++a)
{
PT::Space & sp = *(*space.child_spaces)[a];
if( sp.name == L"option" && sp.Long(L"id") == par.intv )
return;
if( sp.name && *sp.name == L"option" && sp.to_long(L"id") == par.intv )
return;
}
}
par.intv = 0;
std::wstring * def = space.GetFirstValue(L"default");
std::wstring * def = space.get_wstr(L"default");
if( def )
par.intv = Tol(*def);
@@ -322,16 +325,19 @@ void TicketInfo::CheckMinMaxValue(PT::Space & space, Ticket::TicketParam & par)
PT::Space & TicketInfo::FindAddMetaByParam(PT::Space & meta, long param)
{
for(size_t i=0 ; i<meta.spaces.size() ; ++i)
if( meta.child_spaces )
{
PT::Space & sp = *meta.spaces[i];
for(size_t i=0 ; i<meta.child_spaces->size() ; ++i)
{
PT::Space & sp = *(*meta.child_spaces)[i];
if( sp.name == L"param" && sp.Long(L"id") == param )
return sp;
if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == param )
return sp;
}
}
PT::Space & sp = meta.AddSpace(L"param");
sp.Add(L"id", param);
PT::Space & sp = meta.add_child_space(L"param");
sp.add(L"id", param);
return sp;
}
@@ -340,9 +346,9 @@ return sp;
bool TicketInfo::ReadTicketValue(PT::Space & space, long param_id, Ticket::TicketParam & par, const std::wstring & value, PT::Space & meta)
{
if( space.Text(L"type") == L"integer" ||
space.Text(L"type") == L"progress" ||
space.Text(L"type") == L"select" )
if( space.is_equal(L"type", L"integer") ||
space.is_equal(L"type", L"progress") ||
space.is_equal(L"type", L"select") )
{
par.intv = Tol(value);
par.decv.clear();
@@ -350,16 +356,16 @@ bool TicketInfo::ReadTicketValue(PT::Space & space, long param_id, Ticket::Ticke
return true;
}
else
if( space.Text(L"type") == L"string" ||
space.Text(L"type") == L"multistring" )
if( space.is_equal(L"type", L"string") ||
space.is_equal(L"type", L"multistring") )
{
// !! dodac cos co sprawdzi czy string nie zawiera znakow konca linii
PT::Space & sp = FindAddMetaByParam(meta, param_id);
sp.Add(L"value", value);
sp.add(L"value", value);
return false;
}
if( space.Text(L"type") == L"images" ||
space.Text(L"type") == L"files" )
if( space.is_equal(L"type", L"images") ||
space.is_equal(L"type", L"files") )
{
if( !value.empty() )
{
@@ -404,16 +410,16 @@ void TicketInfo::ReadTicketValue(PT::Space & space,
if( cur->request->status == WINIX_ERR_OK )
{
PT::Space & space = FindAddMetaByParam(meta, param_id);
PT::Space & file_space = space.AddSpace(L"file");
PT::Space & file_space = space.add_child_space(L"file");
if( file.item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE )
file_space.Add(L"type", L"image");
file_space.add(L"type", L"image");
else
file_space.Add(L"type", L"file");
file_space.add(L"type", L"file");
file_space.Add(L"itemid", file.id);
file_space.add(L"itemid", file.id);
system->MakePath(file, file_path);
file_space.Add(L"path", file_path);
file_space.add(L"path", file_path);
}
else
{
@@ -425,11 +431,11 @@ void TicketInfo::ReadTicketValue(PT::Space & space,
void TicketInfo::ReadTicketValue(PT::Space & space,
long param_id, const PostFile & value, PT::Space & meta)
{
std::wstring * type = space.GetFirstValue(L"type");
std::wstring * type = space.get_wstr(L"type");
if( type && (*type == L"images" || *type == L"files") )
{
std::wstring * upload_path = space.GetFirstValue(L"upload_dir");
std::wstring * upload_path = space.get_wstr(L"upload_dir");
if( upload_path && !upload_path->empty() )
{
@@ -479,14 +485,17 @@ void TicketInfo::ReadTicketParam(Ticket & ticket, long param_id, const std::wstr
{
ticket_param.Clear();
for(size_t i=0 ; i<cur_conf->spaces.size() ; ++i)
if( cur_conf->child_spaces )
{
PT::Space & space = *cur_conf->spaces[i];
if( space.name == L"param" && Tol(space.Text(L"id")) == param_id )
for(size_t i=0 ; i<cur_conf->child_spaces->size() ; ++i)
{
ReadTicketParam(space, ticket, param_id, value, meta);
return;
PT::Space & space = *(*cur_conf->child_spaces)[i];
if( space.name && *space.name == L"param" && space.to_long(L"id") == param_id )
{
ReadTicketParam(space, ticket, param_id, value, meta);
return;
}
}
}
@@ -497,14 +506,17 @@ void TicketInfo::ReadTicketParam(Ticket & ticket, long param_id, const std::wstr
// always adds a new parameter
void TicketInfo::ReadTicketParam(long param_id, const PostFile & value, PT::Space & meta)
{
for(size_t i=0 ; i<cur_conf->spaces.size() ; ++i)
if( cur_conf->child_spaces )
{
PT::Space & space = *cur_conf->spaces[i];
if( space.name == L"param" && space.Long(L"id") == param_id )
for(size_t i=0 ; i<cur_conf->child_spaces->size() ; ++i)
{
ReadTicketValue(space, param_id, value, meta);
return;
PT::Space & space = *(*cur_conf->child_spaces)[i];
if( space.name && *space.name == L"param" && space.to_long(L"id") == param_id )
{
ReadTicketValue(space, param_id, value, meta);
return;
}
}
}
@@ -517,29 +529,32 @@ void TicketInfo::ReadTicketParam(long param_id, const PostFile & value, PT::Spac
bool TicketInfo::DeleteTicketFile(Ticket & ticket, long file_id, PT::Space & meta)
{
for(size_t i=0 ; i<meta.spaces.size() ; ++i)
if( meta.child_spaces )
{
PT::Space & param = *meta.spaces[i];
if( param.name == L"param" )
for(size_t i=0 ; i<meta.child_spaces->size() ; ++i)
{
for(size_t z=0 ; z<param.spaces.size() ; ++z)
PT::Space & param = *(*meta.child_spaces)[i];
if( param.name && *param.name == L"param" && param.child_spaces )
{
PT::Space & file = *param.spaces[z];
if( file.name == L"file" )
for(size_t z=0 ; z<param.child_spaces->size() ; ++z)
{
if( file.Long(L"itemid") == file_id )
PT::Space & file = *(*param.child_spaces)[z];
if( file.name && *file.name == L"file" )
{
param.RemoveSpace(z);
if( file.to_long(L"itemid") == file_id )
{
param.remove_child_space(z);
// !! IMPROVE ME
// temporarily we delete the file here
// but it should be really deleted when the user will press
// the submit button
//functions->fun_rm.RemoveFileOrSymlink(file_id, true);
// !! IMPROVE ME
// temporarily we delete the file here
// but it should be really deleted when the user will press
// the submit button
//functions->fun_rm.RemoveFileOrSymlink(file_id, true);
return true;
return true;
}
}
}
}
@@ -616,9 +631,8 @@ void TicketInfo::RemoveTicket(long file_id)
void TicketInfo::CopyTicketSpace(PT::Space & ticket_space, Item & item)
{
PT::Space & ticket_meta = item.item_content.meta.FindAddSpace(L"ticket");
PT::Space & ticket_meta = item.item_content.meta.find_add_child_space(L"ticket");
ticket_meta = ticket_space;
ticket_meta.name = L"ticket";
}