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:
@@ -40,8 +40,9 @@ dir.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
|
||||
dir.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
|
||||
dir.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
|
||||
dir.o: ../functions/funthread.h ../core/thread.h ../functions/funticket.h
|
||||
dir.o: ../core/ticket.h ../functions/tinymce.h ../functions/uname.h
|
||||
dir.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
|
||||
dir.o: ../core/ticket.h ../functions/template.h ../functions/tinymce.h
|
||||
dir.o: ../functions/uname.h ../functions/upload.h ../functions/uptime.h
|
||||
dir.o: ../functions/who.h
|
||||
doc.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h misc.h
|
||||
doc.o: localefilter.h ../core/locale.h ../core/confparser.h
|
||||
doc.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
|
||||
@@ -127,7 +128,7 @@ mount.o: ../core/ugcontainer.h ../core/ticket.h ../core/system.h
|
||||
mount.o: ../core/dirs.h ../core/db.h ../core/request.h ../core/mounts.h
|
||||
mount.o: ../core/mount.h ../core/users.h ../core/lastcontainer.h
|
||||
mount.o: ../core/groups.h ../core/loadavg.h ../core/sessionmanager.h
|
||||
mount.o: ../core/sessioncontainer.h ../core/system.h
|
||||
mount.o: ../core/sessioncontainer.h ../core/system.h ../core/misc.h
|
||||
patterncacher.o: patterncacher.h ../core/item.h ../../ezc/src/ezc.h
|
||||
patterncacher.o: ../core/log.h
|
||||
priv.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h misc.h
|
||||
@@ -156,9 +157,9 @@ priv.o: ../functions/logout.h ../functions/ls.h ../functions/mkdir.h
|
||||
priv.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
|
||||
priv.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
|
||||
priv.o: ../functions/subject.h ../functions/funthread.h ../core/thread.h
|
||||
priv.o: ../functions/funticket.h ../core/ticket.h ../functions/tinymce.h
|
||||
priv.o: ../functions/uname.h ../functions/upload.h ../functions/uptime.h
|
||||
priv.o: ../functions/who.h
|
||||
priv.o: ../functions/funticket.h ../core/ticket.h ../functions/template.h
|
||||
priv.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
|
||||
priv.o: ../functions/uptime.h ../functions/who.h
|
||||
rebus.o: ../core/request.h templates.h ../../ezc/src/ezc.h patterncacher.h
|
||||
rebus.o: ../core/item.h misc.h localefilter.h ../core/locale.h
|
||||
rebus.o: ../core/confparser.h ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
@@ -185,6 +186,20 @@ sys.o: ../core/db.h ../core/request.h ../core/mounts.h ../core/mount.h
|
||||
sys.o: ../core/users.h ../core/lastcontainer.h ../core/groups.h
|
||||
sys.o: ../core/loadavg.h ../core/sessionmanager.h ../core/sessioncontainer.h
|
||||
sys.o: ../core/system.h ../core/request.h ../core/version.h
|
||||
template.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
|
||||
template.o: misc.h localefilter.h ../core/locale.h ../core/confparser.h
|
||||
template.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
|
||||
template.o: indexpatterns.h ../core/locale.h ../core/config.h
|
||||
template.o: ../core/htmlfilter.h ../core/request.h ../core/requesttypes.h
|
||||
template.o: ../core/session.h ../core/item.h ../core/error.h ../core/log.h
|
||||
template.o: ../core/user.h ../core/plugindata.h ../core/rebus.h
|
||||
template.o: ../core/config.h ../core/db.h ../core/group.h ../core/thread.h
|
||||
template.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
|
||||
template.o: ../core/system.h ../core/dirs.h ../core/db.h ../core/request.h
|
||||
template.o: ../core/mounts.h ../core/mount.h ../core/users.h
|
||||
template.o: ../core/lastcontainer.h ../core/groups.h ../core/loadavg.h
|
||||
template.o: ../core/sessionmanager.h ../core/sessioncontainer.h
|
||||
template.o: ../core/system.h ../core/misc.h
|
||||
templates.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
|
||||
templates.o: misc.h localefilter.h ../core/locale.h ../core/confparser.h
|
||||
templates.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
|
||||
@@ -215,7 +230,8 @@ templates.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
|
||||
templates.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
|
||||
templates.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
|
||||
templates.o: ../functions/funthread.h ../core/thread.h
|
||||
templates.o: ../functions/funticket.h ../core/ticket.h ../functions/tinymce.h
|
||||
templates.o: ../functions/funticket.h ../core/ticket.h
|
||||
templates.o: ../functions/template.h ../functions/tinymce.h
|
||||
templates.o: ../functions/uname.h ../functions/upload.h ../functions/uptime.h
|
||||
templates.o: ../functions/who.h ../templates/templates.h
|
||||
thread.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
|
||||
@@ -246,8 +262,8 @@ thread.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
|
||||
thread.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
|
||||
thread.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
|
||||
thread.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
|
||||
thread.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
|
||||
thread.o: ../functions/uptime.h ../functions/who.h
|
||||
thread.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
|
||||
thread.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
|
||||
ticket.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
|
||||
ticket.o: misc.h localefilter.h ../core/locale.h ../core/confparser.h
|
||||
ticket.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
|
||||
@@ -276,8 +292,8 @@ ticket.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
|
||||
ticket.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
|
||||
ticket.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
|
||||
ticket.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
|
||||
ticket.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
|
||||
ticket.o: ../functions/uptime.h ../functions/who.h
|
||||
ticket.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
|
||||
ticket.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
|
||||
upload.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
|
||||
upload.o: misc.h localefilter.h ../core/locale.h ../core/confparser.h
|
||||
upload.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
|
||||
@@ -360,5 +376,5 @@ winix.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
|
||||
winix.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
|
||||
winix.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
|
||||
winix.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
|
||||
winix.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
|
||||
winix.o: ../functions/uptime.h ../functions/who.h
|
||||
winix.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
|
||||
winix.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
|
||||
|
||||
@@ -1 +1 @@
|
||||
o = adduser.o dir.o doc.o indexpatterns.o item.o last.o localefilter.o ls.o misc.o mount.o patterncacher.o priv.o rebus.o sys.o templates.o thread.o ticket.o upload.o uptime.o user.o who.o winix.o
|
||||
o = adduser.o dir.o doc.o indexpatterns.o item.o last.o localefilter.o ls.o misc.o mount.o patterncacher.o priv.o rebus.o sys.o template.o templates.o thread.o ticket.o upload.o uptime.o user.o who.o winix.o
|
||||
|
||||
@@ -317,7 +317,7 @@ void dir_last_subject(Info & i)
|
||||
HtmlEscape(i.out, request->dir_tab.back()->subject);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void dir_last_info(Info & i)
|
||||
{
|
||||
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
|
||||
@@ -326,7 +326,7 @@ void dir_last_info(Info & i)
|
||||
Ezc::Generator gen(i.out, patterns[locale.GetLang()][pat_dir_last_info], ezc_functions);
|
||||
gen.Generate();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void dir_last_user(Info & i)
|
||||
{
|
||||
@@ -388,6 +388,18 @@ void dir_last_dates_equal(Info & i)
|
||||
}
|
||||
|
||||
|
||||
void dir_last_html_template(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request->dir_tab.back()->html_template);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_has_html_template(Info & i)
|
||||
{
|
||||
i.res = !request->dir_tab.back()->html_template.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ void item_can_remove(Info & i)
|
||||
i.res = system->HasWriteAccess(*request->dir_tab.back());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void item_info(Info & i)
|
||||
{
|
||||
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
|
||||
@@ -227,7 +227,7 @@ void item_info(Info & i)
|
||||
Ezc::Generator gen(i.out, patterns[locale.GetLang()][pat_item_info], ezc_functions);
|
||||
gen.Generate();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void item_user(Info & i)
|
||||
{
|
||||
@@ -325,6 +325,18 @@ void item_guest_name(Info & i)
|
||||
}
|
||||
|
||||
|
||||
void item_html_template(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request->item.html_template);
|
||||
}
|
||||
|
||||
|
||||
void item_has_html_template(Info & i)
|
||||
{
|
||||
i.res = !request->item.html_template.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -456,7 +468,7 @@ void item_tab_can_write(Info & i)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void item_tab_info(Info & i)
|
||||
{
|
||||
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
|
||||
@@ -465,7 +477,7 @@ void item_tab_info(Info & i)
|
||||
Ezc::Generator gen(i.out, patterns[locale.GetLang()][pat_item_tab_info], ezc_functions);
|
||||
gen.Generate();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void item_tab_user(Info & i)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
#include "core/misc.h"
|
||||
|
||||
|
||||
|
||||
@@ -47,8 +47,20 @@ void mount_type_is_cms(Info & i)
|
||||
i.res = system->mounts.pmount->type == Mount::cms;
|
||||
}
|
||||
|
||||
void mount_has_html_template(Info & i)
|
||||
{
|
||||
i.res = system->mounts.pmount->param[Mount::par_html_template].defined;
|
||||
}
|
||||
|
||||
|
||||
void mount_first_html_template(Info & i)
|
||||
{
|
||||
Mount::ParamRow & par = system->mounts.pmount->param[Mount::par_html_template];
|
||||
|
||||
if( par.defined && !par.arg.empty() )
|
||||
HtmlEscape(i.out, par.arg[0]);
|
||||
}
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
113
templates/template.cpp
Executable file
113
templates/template.cpp
Executable file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "templates.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void template_index(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, config->templates_index);
|
||||
}
|
||||
|
||||
|
||||
static std::vector<std::string> temp_tab;
|
||||
static size_t temp_req_id = 0;
|
||||
static size_t temp_def;
|
||||
static size_t temp_index;
|
||||
|
||||
|
||||
|
||||
void template_set_def()
|
||||
{
|
||||
temp_def = (size_t)-1; // none
|
||||
const std::string * html_file;
|
||||
|
||||
if( request->is_item )
|
||||
html_file = &request->item.html_template;
|
||||
else
|
||||
html_file = &request->dir_tab.back()->html_template;
|
||||
|
||||
|
||||
if( html_file->empty() )
|
||||
{
|
||||
// the first default item should be selected (that first in html source with value="")
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(size_t i=0 ; i<temp_tab.size() ; ++i)
|
||||
{
|
||||
if( temp_tab[i] == *html_file )
|
||||
{
|
||||
temp_def = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void template_init()
|
||||
{
|
||||
// the first item in the html template is an empty string
|
||||
// added in the html template
|
||||
temp_tab.clear();
|
||||
temp_tab.push_back(config->templates_index);
|
||||
|
||||
Mount::ParamRow & par = system->mounts.pmount->param[Mount::par_html_template];
|
||||
|
||||
if( par.defined )
|
||||
{
|
||||
size_t len = par.arg.size();
|
||||
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
temp_tab.push_back(par.arg[i]);
|
||||
}
|
||||
|
||||
template_set_def();
|
||||
}
|
||||
|
||||
|
||||
void template_tab(Info & i)
|
||||
{
|
||||
if( request->id != temp_req_id )
|
||||
{
|
||||
temp_req_id = request->id;
|
||||
template_init();
|
||||
}
|
||||
|
||||
temp_index = i.iter;
|
||||
i.res = temp_index < temp_tab.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void template_tab_isdefault(Info & i)
|
||||
{
|
||||
if( temp_index < temp_tab.size() )
|
||||
i.res = (temp_index == temp_def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void template_tab_file_name(Info & i)
|
||||
{
|
||||
if( temp_index < temp_tab.size() )
|
||||
HtmlEscape(i.out, temp_tab[temp_index]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,9 +60,9 @@ namespace TemplatesFunctions
|
||||
pat_fun_adduser,
|
||||
pat_err_404,
|
||||
pat_err_per_denied,
|
||||
pat_item_info,
|
||||
pat_item_tab_info,
|
||||
pat_dir_last_info,
|
||||
//pat_item_info,
|
||||
//pat_item_tab_info,
|
||||
//pat_dir_last_info,
|
||||
pat_fun_subject,
|
||||
pat_fun_cp,
|
||||
pat_fun_tinymce,
|
||||
@@ -79,6 +79,7 @@ namespace TemplatesFunctions
|
||||
|
||||
extern IndexPatterns index_patterns;
|
||||
extern Patterns patterns;
|
||||
extern Patterns patterns_fun;
|
||||
extern PatternCacher pattern_cacher;
|
||||
extern Locale locale;
|
||||
extern Ezc::Functions ezc_functions;
|
||||
@@ -144,7 +145,7 @@ namespace TemplatesFunctions
|
||||
void item_can_read(Info & i);
|
||||
void item_can_write(Info & i);
|
||||
void item_can_remove(Info & i);
|
||||
void item_info(Info & i);
|
||||
//void item_info(Info & i);
|
||||
void item_user(Info & i);
|
||||
void item_modification_user(Info & i);
|
||||
void item_users_different(Info & i);
|
||||
@@ -155,6 +156,9 @@ namespace TemplatesFunctions
|
||||
void item_dates_equal(Info & i);
|
||||
void item_run(Info & i);
|
||||
void item_guest_name(Info & i);
|
||||
void item_html_template(Info & i);
|
||||
void item_has_html_template(Info & i);
|
||||
|
||||
|
||||
void item_tab(Info & i);
|
||||
void item_tab_id(Info & i);
|
||||
@@ -170,7 +174,7 @@ namespace TemplatesFunctions
|
||||
void item_tab_link_auth(Info & i);
|
||||
void item_tab_can_read(Info & i);
|
||||
void item_tab_can_write(Info & i);
|
||||
void item_tab_info(Info & i);
|
||||
//void item_tab_info(Info & i);
|
||||
void item_tab_user(Info & i);
|
||||
void item_tab_modification_user(Info & i);
|
||||
void item_tab_users_different(Info & i);
|
||||
@@ -211,14 +215,16 @@ namespace TemplatesFunctions
|
||||
void dir_last_default_item_dir(Info &);
|
||||
void dir_last_default_item_url(Info & i);
|
||||
void dir_last_subject(Info & i);
|
||||
void dir_last_info(Info & i);
|
||||
//void dir_last_info(Info & i);
|
||||
void dir_last_user(Info & i);
|
||||
void dir_last_url(Info & i);
|
||||
void dir_last_url_is(Info & i);
|
||||
void dir_last_date_creation(Info & i);
|
||||
void dir_last_date_modification(Info & i);
|
||||
void dir_last_dates_equal(Info & i);
|
||||
|
||||
void dir_last_html_template(Info & i);
|
||||
void dir_last_has_html_template(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
user
|
||||
@@ -360,6 +366,8 @@ namespace TemplatesFunctions
|
||||
void mount_type_is_thread(Info & i);
|
||||
void mount_type_is_ticket(Info & i);
|
||||
void mount_type_is_cms(Info & i);
|
||||
void mount_has_html_template(Info & i);
|
||||
void mount_first_html_template(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
@@ -404,6 +412,15 @@ namespace TemplatesFunctions
|
||||
void winix_err_msg_from_locales(Info & i);
|
||||
void winix_show_content_in_full_window(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
template (html templates)
|
||||
*/
|
||||
void template_index(Info & i);
|
||||
void template_tab(Info & i);
|
||||
void template_tab_isdefault(Info & i);
|
||||
void template_tab_file_name(Info & i);
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
@@ -425,7 +442,7 @@ public:
|
||||
void ClearPatterns();
|
||||
void ReadTemplates();
|
||||
void ReadNewIndexTemplates();
|
||||
void ReadIndexFileNames();
|
||||
void ReadIndexFileNames(bool add_pattern = false);
|
||||
void CreateFunctions();
|
||||
void Generate();
|
||||
void GenerateRunRaw();
|
||||
@@ -433,9 +450,12 @@ public:
|
||||
private:
|
||||
|
||||
void ReadFile(TemplatesFunctions::Pat pat, const char * file);
|
||||
void ReadFileFun(size_t index, const char * file);
|
||||
void ReadFunctionsTemplates();
|
||||
void SetLocale();
|
||||
|
||||
std::string temp;
|
||||
|
||||
std::string fun_file;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user