added: Patterns class (in templates)
ezc patterns are managed by this class
added: some work in groupitem plugin (not finished yet)
changed: ConfParser can read a string from memory now
(need some testing yet)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@757 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -18,15 +18,23 @@
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
size_t pat_index;
|
||||
size_t pat_err_404;
|
||||
size_t pat_err_per_denied;
|
||||
|
||||
Patterns patterns; // all html patterns
|
||||
IndexPatterns index_patterns; // patterns for main index template (those from mountpoint)
|
||||
Patterns patterns; // those patterns from enum Pat
|
||||
Patterns patterns_fun; // patterns for winix functions
|
||||
// index_atterns uses patterns as a storage
|
||||
ChangePatterns change_patterns; // patterns for change_template mount option (storage is in 'patterns' too)
|
||||
PatternCacher pattern_cacher; // patterns for user items (files with an executable bit set)
|
||||
|
||||
Locale locale;
|
||||
EzcFun ezc_functions;
|
||||
LocaleFilter locale_filter;
|
||||
HTMLFilter html_filter;
|
||||
|
||||
|
||||
|
||||
// used by GenerateRunRaw()
|
||||
std::vector<std::wstring> empty_pars;
|
||||
const std::wstring empty_string;
|
||||
@@ -46,24 +54,26 @@ static EzcGen content_gen;
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * content_for_function()
|
||||
Ezc::Pattern * GetPatternForFunction()
|
||||
{
|
||||
static std::wstring fun_file;
|
||||
|
||||
if( !cur->request->function )
|
||||
{
|
||||
log << log1 << "Templates: no function" << logend;
|
||||
log << log1 << "Templates: cannot get a template for a function (there is not a function)" << logend;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const size_t loc_index = locale.GetLang();
|
||||
const size_t fun_id = static_cast<size_t>(cur->request->function->id);
|
||||
fun_file = config->templates_fun_prefix;
|
||||
fun_file += cur->request->function->fun.url;
|
||||
fun_file += config->templates_fun_postfix;
|
||||
|
||||
if( loc_index >= patterns_fun.size() || fun_id >= patterns_fun[loc_index].size() )
|
||||
{
|
||||
log << log1 << "Templates: incorrect function index" << logend;
|
||||
return 0;
|
||||
}
|
||||
Ezc::Pattern * p = change_patterns.Get(cur->mount->dir_id, fun_file, locale.GetLang());
|
||||
|
||||
return &patterns_fun[loc_index][fun_id];
|
||||
if( p )
|
||||
return p;
|
||||
|
||||
return patterns.Get(cur->request->function->template_index, locale.GetLang());
|
||||
}
|
||||
|
||||
|
||||
@@ -72,13 +82,6 @@ void content(Info & i)
|
||||
{
|
||||
Ezc::Pattern * p = 0;
|
||||
|
||||
if( locale.GetLang() >= patterns.size() )
|
||||
{
|
||||
log << log1 << "Templates: there is no such a language in patterns" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch( cur->request->status )
|
||||
{
|
||||
//case WINIX_ERR_NO_ITEM: !! we need something like 'error::item_required'
|
||||
@@ -92,14 +95,14 @@ Ezc::Pattern * p = 0;
|
||||
case WINIX_ERR_CANT_CHANGE_GROUP:
|
||||
case WINIX_ERR_CANT_CHANGE_PRIVILEGES:
|
||||
// !! locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = &patterns[locale.GetLang()][pat_err_per_denied];
|
||||
p = patterns.Get(pat_err_per_denied, locale.GetLang());
|
||||
break;
|
||||
|
||||
case WINIX_ERR_NO_ITEM:
|
||||
case WINIX_ERR_NO_FUNCTION:
|
||||
case WINIX_ERR_UNKNOWN_PARAM:
|
||||
// !! locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = &patterns[locale.GetLang()][pat_err_404];
|
||||
p = patterns.Get(pat_err_404, locale.GetLang());
|
||||
break;
|
||||
|
||||
//default:
|
||||
@@ -111,7 +114,7 @@ Ezc::Pattern * p = 0;
|
||||
//case WINIX_ERR_SPAM:
|
||||
//case WINIX_ERR_INCORRECT_REBUS:
|
||||
default:
|
||||
p = content_for_function();
|
||||
p = GetPatternForFunction();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -119,7 +122,7 @@ Ezc::Pattern * p = 0;
|
||||
if( p )
|
||||
content_gen.Generate(i.out, *p);
|
||||
else
|
||||
i.out << "<!-- there are not any patterns -->";
|
||||
log << log1 << "Templates: content: there are not any patterns";
|
||||
}
|
||||
|
||||
|
||||
@@ -522,25 +525,9 @@ void Templates::CreateFunctions()
|
||||
|
||||
|
||||
|
||||
void Templates::ReadFile(TemplatesFunctions::Pat pat, const wchar_t * file)
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Read(patterns, static_cast<size_t>(pat), locale, locale_filter, ezc_functions, file, config->utf8,
|
||||
config->templates_dir, config->templates_dir_default);
|
||||
}
|
||||
|
||||
|
||||
void Templates::ReadFileFun(size_t index, const wchar_t * file)
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Read(patterns_fun, index, locale, locale_filter, ezc_functions, file, config->utf8,
|
||||
config->templates_dir, config->templates_dir_default);
|
||||
}
|
||||
|
||||
|
||||
void Templates::SetLocale()
|
||||
void Templates::ReadLocale()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
@@ -550,10 +537,12 @@ using namespace TemplatesFunctions;
|
||||
locale.SetLang(config->locale_default_index); // !! w przyszlosci locale beda ustawiane dla kazdego uzytkownika osobno
|
||||
locale.SetLangDef(config->locale_default_index);
|
||||
locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
|
||||
log << log3 << "Templates: there are " << locale.Size() << " locales" << logend;
|
||||
}
|
||||
|
||||
|
||||
void Templates::ReadFunctionsTemplates()
|
||||
void Templates::ReadTemplatesForFunctions()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
@@ -562,24 +551,58 @@ using namespace TemplatesFunctions;
|
||||
for(; i != functions->End() ; ++i)
|
||||
{
|
||||
const std::wstring & fun_name = i->first;
|
||||
const size_t index = i->second->id;
|
||||
|
||||
if( index < functions->FunctionsSize() )
|
||||
fun_file = config->templates_fun_prefix;
|
||||
fun_file += fun_name;
|
||||
fun_file += config->templates_fun_postfix;
|
||||
|
||||
i->second->template_index = patterns.Add(fun_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Templates::ReadIndexTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Mounts::MountTab::const_iterator i;
|
||||
const Mounts::MountTab * pmount_tab = TemplatesFunctions::system->mounts.GetMountTab();
|
||||
const size_t html_id = (size_t)TemplatesFunctions::system->mounts.MountParHtmlTemplate();
|
||||
|
||||
// loop through all mount points
|
||||
for(i=pmount_tab->begin() ; i!=pmount_tab->end() ; ++i)
|
||||
{
|
||||
const Mount & mount = i->second;
|
||||
|
||||
if( html_id < mount.param.size() && mount.param[html_id].defined )
|
||||
{
|
||||
fun_file = config->templates_fun_prefix;
|
||||
fun_file += fun_name;
|
||||
fun_file += config->templates_fun_postfix;
|
||||
ReadFileFun(index, fun_file.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Templates: function index too large, fun: "
|
||||
<< fun_name << ", index: " << index << logend;
|
||||
size_t len = mount.param[html_id].arg.size();
|
||||
|
||||
// loop through all html_templates() values
|
||||
for(size_t a=0 ; a<len ; ++a)
|
||||
index_patterns.Add(mount.param[html_id].arg[a]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
reading only new index templates
|
||||
those which are exists are not touched
|
||||
the rest are deleted
|
||||
*/
|
||||
void Templates::ReadNewIndexTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
index_patterns.MarkAllToDelete();
|
||||
ReadIndexTemplates();
|
||||
index_patterns.DeleteMarked();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Templates::SetHtmlFilter()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
@@ -608,117 +631,88 @@ using namespace TemplatesFunctions;
|
||||
|
||||
|
||||
|
||||
void Templates::ReadTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
SetLocale();
|
||||
ClearPatterns();
|
||||
|
||||
ReadFile(pat_index, config->templates_index.c_str());
|
||||
ReadFile(pat_err_404, L"err_404.html");
|
||||
ReadFile(pat_err_per_denied, L"err_per_denied.html");
|
||||
|
||||
ReadFunctionsTemplates();
|
||||
index_patterns.ReloadPatterns(locale, locale_filter, false);
|
||||
|
||||
SetHtmlFilter();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// reading only new index templates (with parsing)
|
||||
// those which are exists are not touched
|
||||
// the rest are deleted
|
||||
void Templates::ReadNewIndexTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
index_patterns.MarkAllToDelete();
|
||||
ReadIndexFileNames(true);
|
||||
index_patterns.DeleteMarked();
|
||||
}
|
||||
|
||||
|
||||
// if add_pattern is true then pattern will be read (parsed)
|
||||
// if add_pattern is false then only file_name of the pattern will be remembered
|
||||
// you can next call ReadTemplates() to read those patterns
|
||||
void Templates::ReadIndexFileNames(bool add_pattern)
|
||||
void Templates::ReadChangeTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Mounts::MountTab::const_iterator i;
|
||||
const Mounts::MountTab * pmount_tab = TemplatesFunctions::system->mounts.GetMountTab();
|
||||
const size_t change_id = (size_t)TemplatesFunctions::system->mounts.MountParChangeTemplate();
|
||||
|
||||
// loop through all mount points
|
||||
for(i=pmount_tab->begin() ; i!=pmount_tab->end() ; ++i)
|
||||
{
|
||||
const Mount & mount = i->second;
|
||||
int html_id = TemplatesFunctions::system->mounts.MountParHtmlTemplate();
|
||||
|
||||
if( size_t(html_id) >= mount.param.size() )
|
||||
if( change_id < mount.param.size() && mount.param[change_id].defined )
|
||||
{
|
||||
log << log1 << "Templates: something wrong in mount points, there is no"
|
||||
<< " html template parameter" << logend;
|
||||
}
|
||||
else
|
||||
if( mount.param[html_id].defined )
|
||||
{
|
||||
size_t len = mount.param[html_id].arg.size();
|
||||
size_t a;
|
||||
const std::vector<std::wstring> & arg = mount.param[change_id].arg;
|
||||
|
||||
// loop through all html_templates() values
|
||||
for(a=0 ; a<len ; ++a)
|
||||
{
|
||||
const std::wstring & file_name = mount.param[html_id].arg[a];
|
||||
|
||||
if( add_pattern )
|
||||
index_patterns.AddPatternIfNotExists(file_name, locale, locale_filter, false); // file pattern will be unmarked
|
||||
else
|
||||
index_patterns.AddFileName(file_name);
|
||||
}
|
||||
for(size_t a=0 ; a+1 < arg.size() ; a += 2)
|
||||
change_patterns.Add(mount.dir_id, arg[a], arg[a+1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Templates::ClearPatterns(TemplatesFunctions::Patterns & patterns, size_t len)
|
||||
/*
|
||||
reading only new 'change' templates
|
||||
those which are exists are not touched
|
||||
the rest are deleted
|
||||
*/
|
||||
void Templates::ReadNewChangeTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
size_t loc, pat;
|
||||
|
||||
patterns.resize(locale.Size());
|
||||
|
||||
for(loc=0 ; loc < patterns.size() ; ++loc)
|
||||
{
|
||||
patterns[loc].resize(len);
|
||||
|
||||
for(pat=0 ; pat<len ; ++pat)
|
||||
patterns[loc][pat].Clear();
|
||||
}
|
||||
change_patterns.MarkAllToDelete();
|
||||
ReadChangeTemplates();
|
||||
change_patterns.DeleteMarked();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Templates::ReadTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
ReadLocale();
|
||||
patterns.Clear();
|
||||
|
||||
pat_index = patterns.Add(config->templates_index);
|
||||
pat_err_404 = patterns.Add(L"err_404.html");
|
||||
pat_err_per_denied = patterns.Add(L"err_per_denied.html");
|
||||
|
||||
ReadTemplatesForFunctions();
|
||||
ReadIndexTemplates();
|
||||
ReadChangeTemplates();
|
||||
|
||||
SetHtmlFilter();
|
||||
|
||||
log << log3 << "Templates: there are " << patterns.Size() << " patterns"
|
||||
<< " (" << (locale.Size() * patterns.Size()) << " for all locales)" << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Templates::Init()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
patterns.SetUTF8(config->utf8);
|
||||
patterns.SetDirectories(config->templates_dir, config->templates_dir_default);
|
||||
|
||||
pattern_cacher.SetWhenDelete(config->pattern_cacher_when_delete, config->pattern_cacher_how_many_delete);
|
||||
CreateFunctions(); // create functions first (functions will be cached by patterns)
|
||||
ReadIndexFileNames();
|
||||
ReadTemplates();
|
||||
}
|
||||
|
||||
|
||||
// index_patterns and patterns for items are not cleared here
|
||||
void Templates::ClearPatterns()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
ClearPatterns(patterns, pat_last);
|
||||
ClearPatterns(patterns_fun, functions->FunctionsSize());
|
||||
}
|
||||
|
||||
|
||||
// clearing at the end of a request
|
||||
@@ -734,44 +728,35 @@ using namespace TemplatesFunctions;
|
||||
void Templates::Generate()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
// !! locale beda w zaleznosci od uzytkownika
|
||||
if( locale.GetLang() >= patterns.size() )
|
||||
return;
|
||||
|
||||
Ezc::Pattern * index = 0;
|
||||
const std::wstring * index_file_local = 0;
|
||||
|
||||
if( cur->request->is_item )
|
||||
{
|
||||
if( !cur->request->item.html_template.empty() )
|
||||
index_file_local = &cur->request->item.html_template;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !cur->request->dir_tab.back()->html_template.empty() )
|
||||
index_file_local = &cur->request->dir_tab.back()->html_template;
|
||||
}
|
||||
|
||||
if( !cur->request->last_item->html_template.empty() )
|
||||
index_file_local = &cur->request->last_item->html_template;
|
||||
|
||||
if( !index_file_local )
|
||||
{
|
||||
const std::wstring & temp = TemplatesFunctions::system->mounts.pmount->FirstArg(
|
||||
TemplatesFunctions::system->mounts.MountParHtmlTemplate() );
|
||||
Mounts & mounts = TemplatesFunctions::system->mounts;
|
||||
const std::wstring & temp = cur->mount->FirstArg(mounts.MountParHtmlTemplate());
|
||||
|
||||
if( !temp.empty() )
|
||||
index_file_local = &temp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( index_file_local && *index_file_local != config->templates_index )
|
||||
index = index_patterns.GetPattern(*index_file_local, locale.GetLang());
|
||||
index = index_patterns.Get(*index_file_local, locale.GetLang());
|
||||
|
||||
if( !index )
|
||||
index = &patterns[locale.GetLang()][pat_index];
|
||||
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, locale.GetLang());
|
||||
|
||||
generator.Generate(cur->request->page, *index);
|
||||
if( !index )
|
||||
index = patterns.Get(pat_index, locale.GetLang());;
|
||||
|
||||
if( index )
|
||||
generator.Generate(cur->request->page, *index);
|
||||
else
|
||||
log << log1 << "Templates: I cannot find an index template" << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -804,7 +789,6 @@ using namespace TemplatesFunctions;
|
||||
void Templates::SetConfig(Config * pconfig)
|
||||
{
|
||||
TemplatesFunctions::config = pconfig;
|
||||
TemplatesFunctions::index_patterns.SetConfig(pconfig);
|
||||
}
|
||||
|
||||
|
||||
@@ -842,8 +826,14 @@ void Templates::SetSessionManager(SessionManager * psession_manager)
|
||||
Templates::Templates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
index_patterns.SetEzcFunctions(&ezc_functions);
|
||||
|
||||
patterns.SetEzcFunctions(&ezc_functions);
|
||||
patterns.SetLocale(&locale);
|
||||
patterns.SetLocaleFilter(&locale_filter);
|
||||
index_patterns.SetPatterns(&patterns);
|
||||
change_patterns.SetPatterns(&patterns);
|
||||
pattern_cacher.SetEzcFunctions(&ezc_functions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user