From 260c12894dc11fc40d3d99178b41a148ff2b5dd6 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 26 Aug 2012 19:53:47 +0000 Subject: [PATCH] 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 --- core/app.cpp | 3 +++ core/request.cpp | 4 ++++ core/request.h | 5 +++++ plugins/thread/templates.cpp | 3 +++ templates/filters.cpp | 39 ++++++++++++++++++++++++++++++++++++ templates/insert.cpp | 3 +++ templates/item.cpp | 6 ++++++ templates/templates.cpp | 33 +++++++++++++++++++++++++++++- templates/templates.h | 7 +++++++ 9 files changed, 102 insertions(+), 1 deletion(-) diff --git a/core/app.cpp b/core/app.cpp index 4cd9b29..6d4986a 100755 --- a/core/app.cpp +++ b/core/app.cpp @@ -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 ) diff --git a/core/request.cpp b/core/request.cpp index e04d14c..be5794a 100755 --- a/core/request.cpp +++ b/core/request.cpp @@ -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; } diff --git a/core/request.h b/core/request.h index 0c1903d..55af97c 100755 --- a/core/request.h +++ b/core/request.h @@ -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); diff --git a/plugins/thread/templates.cpp b/plugins/thread/templates.cpp index 2304bde..b76a918 100755 --- a/plugins/thread/templates.cpp +++ b/plugins/thread/templates.cpp @@ -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); diff --git a/templates/filters.cpp b/templates/filters.cpp index 7fa61c8..1c7c15a 100755 --- a/templates/filters.cpp +++ b/templates/filters.cpp @@ -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 ; iezc_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); diff --git a/templates/item.cpp b/templates/item.cpp index 29edfd2..3be7fe9 100755 --- a/templates/item.cpp +++ b/templates/item.cpp @@ -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); diff --git a/templates/templates.cpp b/templates/templates.cpp index bb6ede1..d6a3cfe 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -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); } diff --git a/templates/templates.h b/templates/templates.h index 99b9acb..1ef9d22 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -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);