some improvement in templates
(now we have O(1) time for selecting the right html template) added: winix function: template for selecting a template for an item (file or dir) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@636 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -20,6 +20,7 @@ namespace TemplatesFunctions
|
||||
|
||||
IndexPatterns index_patterns;
|
||||
Patterns patterns;
|
||||
Patterns patterns_fun;
|
||||
Ezc::Functions ezc_functions;
|
||||
PatternCacher pattern_cacher;
|
||||
Locale locale;
|
||||
@@ -41,58 +42,22 @@ SessionManager * session_manager;
|
||||
|
||||
Ezc::Pattern * content_for_function()
|
||||
{
|
||||
Ezc::Pattern * p = 0;
|
||||
|
||||
if( !request->function )
|
||||
{
|
||||
log << log1 << "Templates: no function" << logend;
|
||||
return p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PatName pat_name_tab[] = {
|
||||
{"cat", pat_fun_cat},
|
||||
{"ls", pat_fun_ls},
|
||||
{"rm", pat_fun_rm},
|
||||
{"emacs", pat_fun_emacs},
|
||||
{"mkdir", pat_fun_mkdir},
|
||||
{"default", pat_fun_default},
|
||||
{"priv", pat_fun_priv},
|
||||
{"chmod", pat_fun_priv},
|
||||
{"chown", pat_fun_priv},
|
||||
{"run", pat_fun_run},
|
||||
{"who", pat_fun_who},
|
||||
{"last", pat_fun_last},
|
||||
{"thread", pat_fun_thread},
|
||||
{"reload", pat_fun_reload},
|
||||
{"createthread",pat_fun_createthread},
|
||||
{"ticket", pat_fun_ticket},
|
||||
{"createticket",pat_fun_createticket},
|
||||
{"editticket", pat_fun_createticket},
|
||||
{"upload", pat_fun_upload},
|
||||
{"uptime", pat_fun_uptime},
|
||||
{"login", pat_fun_login},
|
||||
{"mv", pat_fun_mv},
|
||||
{"uname", pat_fun_uname},
|
||||
{"ckeditor", pat_fun_ckeditor},
|
||||
{"subject", pat_fun_subject},
|
||||
{"adduser", pat_fun_adduser},
|
||||
{"cp", pat_fun_cp},
|
||||
{"tinymce", pat_fun_tinymce},
|
||||
};
|
||||
const size_t loc_index = static_cast<size_t>(locale.GetLang());
|
||||
const size_t fun_id = static_cast<size_t>(request->function->id);
|
||||
|
||||
size_t i, len = sizeof(pat_name_tab)/sizeof(PatName);
|
||||
|
||||
for(i=0 ; i<len ; ++i)
|
||||
if( loc_index >= patterns_fun.size() || fun_id >= patterns_fun[loc_index].size() )
|
||||
{
|
||||
if( strcmp(pat_name_tab[i].fun_name, request->function->fun.url.c_str()) == 0 )
|
||||
{
|
||||
// !! locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = &patterns[locale.GetLang()][pat_name_tab[i].pat];
|
||||
break;
|
||||
}
|
||||
log << log1 << "Templates: incorrect function index" << logend;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return p;
|
||||
|
||||
return &patterns_fun[loc_index][fun_id];
|
||||
}
|
||||
|
||||
|
||||
@@ -152,12 +117,9 @@ Ezc::Pattern * p = 0;
|
||||
{
|
||||
i.out << "<!-- there are not any patterns -->";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
@@ -219,7 +181,7 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("item_can_read", item_can_read);
|
||||
ezc_functions.Insert("item_can_write", item_can_write);
|
||||
ezc_functions.Insert("item_can_remove", item_can_remove);
|
||||
ezc_functions.Insert("item_info", item_info);
|
||||
//ezc_functions.Insert("item_info", item_info);
|
||||
ezc_functions.Insert("item_user", item_user);
|
||||
ezc_functions.Insert("item_modification_user", item_modification_user);
|
||||
ezc_functions.Insert("item_users_different", item_users_different);
|
||||
@@ -230,6 +192,9 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("item_dates_equal", item_dates_equal);
|
||||
ezc_functions.Insert("item_run", item_run);
|
||||
ezc_functions.Insert("item_guest_name", item_guest_name);
|
||||
ezc_functions.Insert("item_html_template", item_html_template);
|
||||
ezc_functions.Insert("item_has_html_template", item_has_html_template);
|
||||
|
||||
|
||||
ezc_functions.Insert("item_tab", item_tab);
|
||||
ezc_functions.Insert("item_tab_id", item_tab_id);
|
||||
@@ -245,7 +210,7 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("item_tab_link_auth", item_tab_link_auth);
|
||||
ezc_functions.Insert("item_tab_can_read", item_tab_can_read);
|
||||
ezc_functions.Insert("item_tab_can_write", item_tab_can_write);
|
||||
ezc_functions.Insert("item_tab_info", item_tab_info);
|
||||
//ezc_functions.Insert("item_tab_info", item_tab_info);
|
||||
ezc_functions.Insert("item_tab_user", item_tab_user);
|
||||
ezc_functions.Insert("item_tab_modification_user", item_tab_modification_user);
|
||||
ezc_functions.Insert("item_tab_users_different", item_tab_users_different);
|
||||
@@ -285,13 +250,15 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("dir_last_default_item_dir", dir_last_default_item_dir);
|
||||
ezc_functions.Insert("dir_last_default_item_url", dir_last_default_item_url);
|
||||
ezc_functions.Insert("dir_last_subject", dir_last_subject);
|
||||
ezc_functions.Insert("dir_last_info", dir_last_info);
|
||||
//ezc_functions.Insert("dir_last_info", dir_last_info);
|
||||
ezc_functions.Insert("dir_last_user", dir_last_user);
|
||||
ezc_functions.Insert("dir_last_url", dir_last_url);
|
||||
ezc_functions.Insert("dir_last_url_is", dir_last_url_is);
|
||||
ezc_functions.Insert("dir_last_date_creation", dir_last_date_creation);
|
||||
ezc_functions.Insert("dir_last_date_modification", dir_last_date_modification);
|
||||
ezc_functions.Insert("dir_last_dates_equal", dir_last_dates_equal);
|
||||
ezc_functions.Insert("dir_last_html_template", dir_last_html_template);
|
||||
ezc_functions.Insert("dir_last_has_html_template", dir_last_has_html_template);
|
||||
|
||||
|
||||
|
||||
@@ -441,6 +408,8 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("mount_type_is_thread", mount_type_is_thread);
|
||||
ezc_functions.Insert("mount_type_is_ticket", mount_type_is_ticket);
|
||||
ezc_functions.Insert("mount_type_is_cms", mount_type_is_cms);
|
||||
ezc_functions.Insert("mount_has_html_template", mount_has_html_template);
|
||||
ezc_functions.Insert("mount_first_html_template", mount_first_html_template);
|
||||
|
||||
|
||||
/*
|
||||
@@ -485,6 +454,16 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("winix_err_msg_from_locales",winix_err_msg_from_locales);
|
||||
ezc_functions.Insert("winix_show_content_in_full_window", winix_show_content_in_full_window);
|
||||
|
||||
|
||||
/*
|
||||
template
|
||||
*/
|
||||
ezc_functions.Insert("template_index", template_index);
|
||||
ezc_functions.Insert("template_tab", template_tab);
|
||||
ezc_functions.Insert("template_tab_isdefault", template_tab_isdefault);
|
||||
ezc_functions.Insert("template_tab_file_name", template_tab_file_name);
|
||||
|
||||
|
||||
plugin.Call(WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions);
|
||||
}
|
||||
|
||||
@@ -499,7 +478,15 @@ using namespace TemplatesFunctions;
|
||||
}
|
||||
|
||||
|
||||
void Templates::ReadTemplates()
|
||||
void Templates::ReadFileFun(size_t index, const char * file)
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Read(patterns_fun, index, locale, locale_filter, file);
|
||||
}
|
||||
|
||||
|
||||
void Templates::SetLocale()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
@@ -511,41 +498,48 @@ using namespace TemplatesFunctions;
|
||||
locale.SetLang(Locale::lang_en);
|
||||
|
||||
locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
}
|
||||
|
||||
|
||||
void Templates::ReadFunctionsTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Functions::Iterator i = functions->Begin();
|
||||
|
||||
for(; i != functions->End() ; ++i)
|
||||
{
|
||||
const std::string & 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;
|
||||
ReadFileFun(index, fun_file.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Templates: function index too large, fun: "
|
||||
<< fun_name << ", index: " << index << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Templates::ReadTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
SetLocale();
|
||||
ClearPatterns();
|
||||
|
||||
ReadFile(pat_index, "index.html");
|
||||
|
||||
ReadFile(pat_index, config->templates_index.c_str());
|
||||
ReadFile(pat_err_404, "err_404.html");
|
||||
ReadFile(pat_err_per_denied, "err_per_denied.html");
|
||||
ReadFile(pat_fun_cat, "fun_cat.html");
|
||||
ReadFile(pat_fun_ls, "fun_ls.html");
|
||||
ReadFile(pat_fun_rm, "fun_rm.html");
|
||||
ReadFile(pat_fun_emacs, "fun_emacs.html");
|
||||
ReadFile(pat_fun_mkdir, "fun_mkdir.html");
|
||||
ReadFile(pat_fun_default, "fun_default.html");
|
||||
ReadFile(pat_fun_priv, "fun_priv.html");
|
||||
ReadFile(pat_fun_who, "fun_who.html");
|
||||
ReadFile(pat_fun_run, "fun_run.html");
|
||||
ReadFile(pat_fun_last, "fun_last.html");
|
||||
ReadFile(pat_item_info, "item_info.html");
|
||||
ReadFile(pat_item_tab_info, "item_tab_info.html");
|
||||
ReadFile(pat_fun_thread, "fun_thread.html");
|
||||
ReadFile(pat_fun_createthread, "fun_createthread.html");
|
||||
ReadFile(pat_dir_last_info, "dir_last_info.html");
|
||||
ReadFile(pat_fun_reload, "fun_reload.html");
|
||||
ReadFile(pat_fun_upload, "fun_upload.html");
|
||||
ReadFile(pat_fun_ticket, "fun_ticket.html");
|
||||
ReadFile(pat_fun_createticket, "fun_createticket.html");
|
||||
ReadFile(pat_fun_uptime, "fun_uptime.html");
|
||||
ReadFile(pat_fun_login, "fun_login.html");
|
||||
ReadFile(pat_fun_mv, "fun_mv.html");
|
||||
ReadFile(pat_fun_uname, "fun_uname.html");
|
||||
ReadFile(pat_fun_ckeditor, "fun_ckeditor.html");
|
||||
ReadFile(pat_fun_adduser, "fun_adduser.html");
|
||||
ReadFile(pat_fun_subject, "fun_subject.html");
|
||||
ReadFile(pat_fun_cp, "fun_cp.html");
|
||||
ReadFile(pat_fun_tinymce, "fun_tinymce.html");
|
||||
|
||||
ReadFunctionsTemplates();
|
||||
index_patterns.ReloadPatterns(locale, locale_filter, false);
|
||||
}
|
||||
|
||||
@@ -556,39 +550,45 @@ using namespace TemplatesFunctions;
|
||||
// the rest are deleted
|
||||
void Templates::ReadNewIndexTemplates()
|
||||
{
|
||||
Mounts::MountTab::const_iterator i;
|
||||
|
||||
using namespace TemplatesFunctions;
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
index_patterns.MarkAllToDelete();
|
||||
const Mounts::MountTab * pmount_tab = TemplatesFunctions::system->mounts.GetMountTab();
|
||||
|
||||
for(i=pmount_tab->begin() ; i!=pmount_tab->end() ; ++i)
|
||||
{
|
||||
const std::string * file = i->second.HtmlTemplate();
|
||||
|
||||
if( file )
|
||||
index_patterns.AddPatternIfNotExists(*file, locale, locale_filter, false); // file pattern will be unmarked
|
||||
}
|
||||
|
||||
ReadIndexFileNames(true);
|
||||
index_patterns.DeleteMarked();
|
||||
}
|
||||
|
||||
|
||||
// reading only index file names (without parsing the files)
|
||||
void Templates::ReadIndexFileNames()
|
||||
// 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)
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Mounts::MountTab::const_iterator i;
|
||||
const Mounts::MountTab * pmount_tab = TemplatesFunctions::system->mounts.GetMountTab();
|
||||
|
||||
// loop through all mount points
|
||||
for(i=pmount_tab->begin() ; i!=pmount_tab->end() ; ++i)
|
||||
{
|
||||
const std::string * file = i->second.HtmlTemplate();
|
||||
const Mount & mount = i->second;
|
||||
|
||||
if( file )
|
||||
index_patterns.AddFileName(*file);
|
||||
if( mount.param[Mount::par_html_template].defined )
|
||||
{
|
||||
size_t len = mount.param[Mount::par_html_template].arg.size();
|
||||
size_t a;
|
||||
|
||||
// loop through all html_templates() values
|
||||
for(a=0 ; a<len ; ++a)
|
||||
{
|
||||
const std::string & file_name = mount.param[Mount::par_html_template].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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,6 +599,7 @@ void Templates::ClearPatterns()
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
TemplatesFunctions::ClearPatterns(patterns, pat_last);
|
||||
TemplatesFunctions::ClearPatterns(patterns_fun, functions->FunctionsSize());
|
||||
}
|
||||
|
||||
|
||||
@@ -611,11 +612,27 @@ using namespace TemplatesFunctions;
|
||||
return;
|
||||
|
||||
Ezc::Pattern * index = 0;
|
||||
const std::string * index_file_local = TemplatesFunctions::system->mounts.pmount->HtmlTemplate();
|
||||
const std::string * index_file_local = 0;
|
||||
|
||||
if( index_file_local )
|
||||
if( request->is_item )
|
||||
{
|
||||
if( !request->item.html_template.empty() )
|
||||
index_file_local = &request->item.html_template;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !request->dir_tab.back()->html_template.empty() )
|
||||
index_file_local = &request->dir_tab.back()->html_template;
|
||||
}
|
||||
|
||||
|
||||
if( !index_file_local )
|
||||
index_file_local = TemplatesFunctions::system->mounts.pmount->FirstHtmlTemplate();
|
||||
|
||||
|
||||
if( index_file_local && *index_file_local != config->templates_index )
|
||||
index = index_patterns.GetPattern(*index_file_local, locale.GetLang());
|
||||
|
||||
|
||||
if( !index )
|
||||
index = &patterns[locale.GetLang()][pat_index];
|
||||
|
||||
@@ -680,7 +697,6 @@ void Templates::SetSessionManager(SessionManager * psession_manager)
|
||||
|
||||
Templates::Templates()
|
||||
{
|
||||
ClearPatterns();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user