added: to Request options used by ezc generators:

bool gen_trim_white;
       bool gen_skip_new_line;
       bool gen_use_special_chars;
added: new ezc filter: fil_csv_escape
       for escaping csv fields





git-svn-id: svn://ttmath.org/publicrep/winix/trunk@877 e52654a7-88a9-db11-a3e9-0013d4bc506e
pull/3/head
Tomasz Sowa 11 years ago
parent adf273479a
commit 260c12894d

@ -430,6 +430,9 @@ bool sent = false;
if( cur.request->page_generated || !cur.request->redirect_to.empty() || !cur.request->x_sendfile.empty() )
return;
templates.SetEzcParameters( cur.request->gen_trim_white,
cur.request->gen_skip_new_line,
cur.request->gen_use_special_chars);
if( cur.request->is_item && cur.request->item.file_type == WINIX_ITEM_FILETYPE_NONE &&
cur.request->item.content_type == Item::ct_raw && cur.request->status == WINIX_ERR_OK && cur.request->function )

@ -119,6 +119,10 @@ void Request::Clear()
subdomain.clear();
ClearAjax();
ajax_serializer = 0;
gen_trim_white = false;
gen_skip_new_line = false;
gen_use_special_chars = false;
}

@ -151,6 +151,11 @@ struct Request
// if not null then the request will have a JSON as an output
PT::SpaceToJSON * ajax_serializer;
// options used by ezc generators
bool gen_trim_white;
bool gen_skip_new_line;
bool gen_use_special_chars;
Request();
void SetConfig(Config * pconfig);

@ -326,6 +326,9 @@ void thread_sort_tab_run(Info & i)
Ezc::Pattern * p = pattern_cacher.GetPattern(*thread_info.item_sort_tab[item_sort_index]);
item_run_content.Clear();
ezc_generator.TrimWhite(gen_trim_white);
ezc_generator.SkipNewLine(gen_skip_new_line);
ezc_generator.RecognizeSpecialChars(gen_use_special_chars);
ezc_generator.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
ezc_generator.Generate(item_run_content, *p);

@ -97,4 +97,43 @@ void fil_first_wordup(Info & i)
}
bool fil_csv_has_colon_or_quote(const std::wstring & str)
{
for(size_t i=0 ; i<str.size() ; ++i)
{
if( str[i] == ',' || str[i] == '"' )
return true;
}
return false;
}
void fil_csv_escape(Info & i)
{
const std::wstring & str = i.in.Str();
if( fil_csv_has_colon_or_quote(str) )
{
i.out << R("\"");
for(size_t a=0 ; a<str.size() ; ++a)
{
if( str[a] == '"' )
i.out << R("\"\"");
else
i.out << R(str[a]);
}
i.out << R("\"");
}
else
{
i.out << R(str);
}
}
} // namespace

@ -45,6 +45,9 @@ void insert_page_run(Info & i)
insert_page_cur += 1;
info.run_content.Clear();
info.ezc_gen.TrimWhite(gen_trim_white);
info.ezc_gen.SkipNewLine(gen_skip_new_line);
info.ezc_gen.RecognizeSpecialChars(gen_use_special_chars);
info.ezc_gen.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
info.ezc_gen.Generate(info.run_content, *pat);
item_print_content(i.out, info.run_content.Str(), info.item.content_type);

@ -291,6 +291,9 @@ void item_run(Info & i)
Ezc::Pattern * p = pattern_cacher.GetPattern(cur->request->item);
item_run_content.Clear();
ezc_generator.TrimWhite(gen_trim_white);
ezc_generator.SkipNewLine(gen_skip_new_line);
ezc_generator.RecognizeSpecialChars(gen_use_special_chars);
ezc_generator.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
ezc_generator.Generate(item_run_content, *p);
@ -651,6 +654,9 @@ void item_tab_run(Info & i)
{
Ezc::Pattern * p = pattern_cacher.GetPattern(cur->request->item_tab[item_index]);
item_run_content.Clear();
ezc_generator.TrimWhite(gen_trim_white);
ezc_generator.SkipNewLine(gen_skip_new_line);
ezc_generator.RecognizeSpecialChars(gen_use_special_chars);
ezc_generator.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
ezc_generator.Generate(item_run_content, *p);
item_print_content(i.out, item_run_content.Str(), cur->request->item_tab[item_index].content_type);

@ -57,6 +57,12 @@ SessionManager * session_manager;
// generator used by content() function
static EzcGen content_gen;
// options used by ezc generators
// set from each Request object
bool gen_trim_white;
bool gen_skip_new_line;
bool gen_use_special_chars;
Ezc::Pattern * GetPatternForFunction()
@ -126,6 +132,9 @@ Ezc::Pattern * p = 0;
if( p )
{
content_gen.TrimWhite(gen_trim_white);
content_gen.SkipNewLine(gen_skip_new_line);
content_gen.RecognizeSpecialChars(gen_use_special_chars);
content_gen.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
content_gen.Generate(i.out, *p);
}
@ -224,7 +233,7 @@ void Templates::CreateFunctions()
ezc_functions.Insert("env_user_tab_id", env_user_tab_id);
ezc_functions.Insert("env_user_tab_name", env_user_tab_name);
ezc_functions.Insert("env_user_tab_is_current", env_user_tab_is_current);
ezc_functions.Insert("fil_csv_escape", fil_csv_escape);
/*
filters
@ -877,6 +886,16 @@ return index;
}
void Templates::SetEzcParameters(bool trim_white, bool skip_new_line, bool use_special_chars)
{
using namespace TemplatesFunctions;
gen_trim_white = trim_white;
gen_skip_new_line = skip_new_line;
gen_use_special_chars = use_special_chars;
}
void Templates::Generate()
{
@ -885,9 +904,17 @@ using namespace TemplatesFunctions;
Ezc::Pattern * index = SelectIndexPattern();
if( index )
{
generator.TrimWhite(gen_trim_white);
generator.SkipNewLine(gen_skip_new_line);
generator.RecognizeSpecialChars(gen_use_special_chars);
generator.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
generator.Generate(cur->request->page, *index);
}
else
{
log << log1 << "Templates: I cannot find an index template" << logend;
}
}
@ -912,6 +939,10 @@ void Templates::Generate(Ezc::Pattern & pattern)
{
using namespace TemplatesFunctions;
generator.TrimWhite(gen_trim_white);
generator.SkipNewLine(gen_skip_new_line);
generator.RecognizeSpecialChars(gen_use_special_chars);
generator.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
generator.Generate(cur->request->page, pattern);
}

@ -60,6 +60,9 @@ namespace TemplatesFunctions
extern Functions * functions;
extern SessionManager * session_manager;
extern bool gen_trim_white;
extern bool gen_skip_new_line;
extern bool gen_use_special_chars;
@ -171,6 +174,7 @@ namespace TemplatesFunctions
void fil_tosmall(Info & i);
void fil_firstup(Info & i);
void fil_first_wordup(Info & i);
void fil_csv_escape(Info & i);
/*
@ -542,6 +546,9 @@ public:
void ReadTemplates();
void ReadNewIndexTemplates();
void ReadNewChangeTemplates();
void SetEzcParameters(bool trim_white, bool skip_new_line, bool use_special_chars);
void Generate();
void GenerateRunRaw();
void Generate(Ezc::Pattern & pattern);

Loading…
Cancel
Save