679 lines
22 KiB
C++
Executable File
679 lines
22 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "templates.h"
|
|
#include "core/misc.h"
|
|
#include "core/plugin.h"
|
|
#include "core/textstream.h"
|
|
#include "functions/functions.h"
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
{
|
|
|
|
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
|
|
PatternCacher pattern_cacher; // patterns for user items (files with an executable bit set)
|
|
Locale locale;
|
|
EzcFun ezc_functions;
|
|
LocaleFilter locale_filter;
|
|
CKEditorGetParser ckeditor_getparser;
|
|
|
|
// used by GenerateRunRaw()
|
|
std::vector<std::wstring> empty_pars;
|
|
const std::wstring empty_string;
|
|
|
|
Config * config;
|
|
Request * request;
|
|
Db * db;
|
|
System * system;
|
|
Functions * functions;
|
|
SessionManager * session_manager;
|
|
|
|
|
|
|
|
Ezc::Pattern * content_for_function()
|
|
{
|
|
if( !request->function )
|
|
{
|
|
log << log1 << "Templates: no function" << logend;
|
|
return 0;
|
|
}
|
|
|
|
const size_t loc_index = static_cast<size_t>(locale.GetLang());
|
|
const size_t fun_id = static_cast<size_t>(request->function->id);
|
|
|
|
if( loc_index >= patterns_fun.size() || fun_id >= patterns_fun[loc_index].size() )
|
|
{
|
|
log << log1 << "Templates: incorrect function index" << logend;
|
|
return 0;
|
|
}
|
|
|
|
return &patterns_fun[loc_index][fun_id];
|
|
}
|
|
|
|
|
|
|
|
void content(Info & i)
|
|
{
|
|
Ezc::Pattern * p = 0;
|
|
|
|
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
|
|
{
|
|
log << log1 << "Templates: there is no such a language in patterns" << logend;
|
|
return;
|
|
}
|
|
|
|
|
|
switch( request->status )
|
|
{
|
|
//case WINIX_ERR_NO_ITEM: !! we need something like 'error::item_required'
|
|
//p = &pat_err_item_required;
|
|
//break;
|
|
|
|
case WINIX_ERR_PERMISSION_DENIED:
|
|
case WINIX_ERR_CANT_CHANGE_USER:
|
|
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];
|
|
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];
|
|
break;
|
|
|
|
//default:
|
|
// !! locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
|
//p = &patterns[locale.GetLang()][pat_err_others];
|
|
//break;
|
|
|
|
//case WINIX_ERR_OK:
|
|
//case WINIX_ERR_SPAM:
|
|
//case WINIX_ERR_INCORRECT_REBUS:
|
|
default:
|
|
p = content_for_function();
|
|
break;
|
|
}
|
|
|
|
|
|
if( p )
|
|
{
|
|
EzcGen gen;
|
|
//gen.Generate(i.out, *p, ezc_functions);
|
|
gen.Generate(i.out, *p);
|
|
}
|
|
else
|
|
{
|
|
i.out << "<!-- there are not any patterns -->";
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|
|
|
|
|
|
void Templates::CreateFunctions()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
ezc_functions.Clear();
|
|
|
|
|
|
/*
|
|
adduser
|
|
*/
|
|
ezc_functions.Insert("adduser_last_login", adduser_last_login);
|
|
ezc_functions.Insert("adduser_last_email", adduser_last_email);
|
|
|
|
|
|
/*
|
|
dir
|
|
*/
|
|
ezc_functions.Insert("dir", dir);
|
|
ezc_functions.Insert("dir_without_slash", dir_without_slash);
|
|
ezc_functions.Insert("dir_parent", dir_parent);
|
|
ezc_functions.Insert("dir_parent_without_slash", dir_parent_without_slash);
|
|
ezc_functions.Insert("dir_can_read_exec", dir_can_read_exec);
|
|
ezc_functions.Insert("dir_can_write", dir_can_write);
|
|
ezc_functions.Insert("dir_can_remove", dir_can_remove);
|
|
ezc_functions.Insert("dir_can_use_emacs", dir_can_use_emacs);
|
|
ezc_functions.Insert("dir_can_use_mkdir", dir_can_use_mkdir);
|
|
|
|
ezc_functions.Insert("dir_childs_tab", dir_childs_tab);
|
|
ezc_functions.Insert("dir_childs_is_parent", dir_childs_is_parent);
|
|
ezc_functions.Insert("dir_childs_tab_url", dir_childs_tab_url);
|
|
ezc_functions.Insert("dir_childs_tab_privileges", dir_childs_tab_privileges);
|
|
ezc_functions.Insert("dir_childs_tab_user", dir_childs_tab_user);
|
|
ezc_functions.Insert("dir_childs_tab_group", dir_childs_tab_group);
|
|
|
|
ezc_functions.Insert("dir_tab", dir_tab);
|
|
ezc_functions.Insert("dir_tab_url", dir_tab_url);
|
|
ezc_functions.Insert("dir_tab_link", dir_tab_link);
|
|
|
|
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_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_date_creation_nice", dir_last_date_creation_nice);
|
|
ezc_functions.Insert("dir_last_date_modification_nice", dir_last_date_modification_nice);
|
|
ezc_functions.Insert("dir_last_dates_equal", dir_last_dates_equal);
|
|
ezc_functions.Insert("dir_last_users_different", dir_last_users_different);
|
|
ezc_functions.Insert("dir_last_modification_user", dir_last_modification_user);
|
|
ezc_functions.Insert("dir_last_html_template", dir_last_html_template);
|
|
ezc_functions.Insert("dir_last_has_html_template", dir_last_has_html_template);
|
|
|
|
|
|
/*
|
|
doc
|
|
*/
|
|
ezc_functions.Insert("doc_title", doc_title);
|
|
ezc_functions.Insert("doc_base_url", doc_base_url);
|
|
ezc_functions.Insert("doc_base_url_static", doc_base_url_static);
|
|
ezc_functions.Insert("doc_base_url_common", doc_base_url_common);
|
|
ezc_functions.Insert("doc_current_url", doc_current_url);
|
|
|
|
|
|
/*
|
|
item
|
|
*/
|
|
ezc_functions.Insert("item_is", item_is);
|
|
ezc_functions.Insert("item_id", item_id);
|
|
ezc_functions.Insert("item_subject", item_subject);
|
|
ezc_functions.Insert("item_subject_noescape", item_subject_noescape);
|
|
ezc_functions.Insert("item_content_is_empty", item_content_is_empty);
|
|
ezc_functions.Insert("item_content", item_content);
|
|
ezc_functions.Insert("item_content_noescape", item_content_noescape);
|
|
ezc_functions.Insert("item_content_type_is", item_content_type_is);
|
|
ezc_functions.Insert("item_print_content", item_print_content);
|
|
ezc_functions.Insert("item_privileges", item_privileges);
|
|
ezc_functions.Insert("item_dir", item_dir);
|
|
ezc_functions.Insert("item_url", item_url);
|
|
ezc_functions.Insert("item_url_is", item_url_is);
|
|
ezc_functions.Insert("item_link", item_link);
|
|
ezc_functions.Insert("item_filetype_is_none", item_filetype_is_none);
|
|
ezc_functions.Insert("item_filetype_is_image", item_filetype_is_image);
|
|
|
|
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_user", item_user);
|
|
ezc_functions.Insert("item_modification_user", item_modification_user);
|
|
ezc_functions.Insert("item_users_different", item_users_different);
|
|
ezc_functions.Insert("item_date_creation", item_date_creation);
|
|
ezc_functions.Insert("item_date_modification", item_date_modification);
|
|
ezc_functions.Insert("item_date_creation_nice", item_date_creation_nice);
|
|
ezc_functions.Insert("item_date_modification_nice",item_date_modification_nice);
|
|
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);
|
|
ezc_functions.Insert("item_tab_subject", item_tab_subject);
|
|
ezc_functions.Insert("item_tab_subject_noescape", item_tab_subject_noescape);
|
|
ezc_functions.Insert("item_tab_content", item_tab_content);
|
|
ezc_functions.Insert("item_tab_content_noescape", item_tab_content_noescape);
|
|
ezc_functions.Insert("item_tab_print_content", item_tab_print_content);
|
|
ezc_functions.Insert("item_tab_privileges", item_tab_privileges);
|
|
ezc_functions.Insert("item_tab_dir", item_tab_dir);
|
|
ezc_functions.Insert("item_tab_url", item_tab_url);
|
|
ezc_functions.Insert("item_tab_link", item_tab_link);
|
|
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_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);
|
|
ezc_functions.Insert("item_tab_group", item_tab_group);
|
|
ezc_functions.Insert("item_tab_date_creation", item_tab_date_creation);
|
|
ezc_functions.Insert("item_tab_date_modification", item_tab_date_modification);
|
|
ezc_functions.Insert("item_tab_date_creation_nice", item_tab_date_creation_nice);
|
|
ezc_functions.Insert("item_tab_date_modification_nice", item_tab_date_modification_nice);
|
|
ezc_functions.Insert("item_tab_dates_equal", item_tab_dates_equal);
|
|
ezc_functions.Insert("item_tab_run", item_tab_run);
|
|
ezc_functions.Insert("item_tab_can_use_emacs", item_tab_can_use_emacs);
|
|
|
|
|
|
/*
|
|
last
|
|
*/
|
|
ezc_functions.Insert("last_tab", last_tab);
|
|
ezc_functions.Insert("last_tab_name", last_tab_name);
|
|
ezc_functions.Insert("last_tab_ip", last_tab_ip);
|
|
ezc_functions.Insert("last_tab_start", last_tab_start);
|
|
ezc_functions.Insert("last_tab_end", last_tab_end);
|
|
|
|
|
|
/*
|
|
mount
|
|
*/
|
|
ezc_functions.Insert("mount_type_is", mount_type_is);
|
|
ezc_functions.Insert("mount_page_arg_is", mount_page_arg_is);
|
|
ezc_functions.Insert("mount_thread_arg_is", mount_thread_arg_is);
|
|
ezc_functions.Insert("mount_has_html_template", mount_has_html_template);
|
|
ezc_functions.Insert("mount_first_html_template", mount_first_html_template);
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
ezc_functions.Insert("ls_ckeditor_funnum_browse", ls_ckeditor_funnum_browse);
|
|
|
|
|
|
/*
|
|
privileges
|
|
*/
|
|
ezc_functions.Insert("priv_user_tab", priv_user_tab);
|
|
ezc_functions.Insert("priv_user_tab_name", priv_user_tab_name);
|
|
ezc_functions.Insert("priv_user_tab_isdefault", priv_user_tab_isdefault);
|
|
|
|
ezc_functions.Insert("priv_group_tab", priv_group_tab);
|
|
ezc_functions.Insert("priv_group_tab_name", priv_group_tab_name);
|
|
ezc_functions.Insert("priv_group_tab_isdefault", priv_group_tab_isdefault);
|
|
|
|
ezc_functions.Insert("priv_privileges", priv_privileges);
|
|
ezc_functions.Insert("priv_privileges_for_files", priv_privileges_for_files);
|
|
ezc_functions.Insert("priv_privileges_for_dirs", priv_privileges_for_dirs);
|
|
ezc_functions.Insert("priv_show_form_chown", priv_show_form_chown);
|
|
ezc_functions.Insert("priv_show_form_chmod", priv_show_form_chmod);
|
|
|
|
|
|
/*
|
|
rebus
|
|
*/
|
|
ezc_functions.Insert("rebus_question", rebus_question);
|
|
|
|
|
|
/*
|
|
stat
|
|
*/
|
|
ezc_functions.Insert("stat_item_type_is_file", stat_item_type_is_file);
|
|
ezc_functions.Insert("stat_item_type_is_static_file", stat_item_type_is_static_file);
|
|
ezc_functions.Insert("stat_item_type_is_dir", stat_item_type_is_dir);
|
|
ezc_functions.Insert("stat_item_inode", stat_item_inode);
|
|
ezc_functions.Insert("stat_item_user", stat_item_user);
|
|
ezc_functions.Insert("stat_item_group", stat_item_group);
|
|
ezc_functions.Insert("stat_item_privileges", stat_item_privileges);
|
|
ezc_functions.Insert("stat_item_date_creation", stat_item_date_creation);
|
|
ezc_functions.Insert("stat_item_date_modification", stat_item_date_modification);
|
|
ezc_functions.Insert("stat_item_template", stat_item_template);
|
|
ezc_functions.Insert("stat_item_is_template_from_mount_point", stat_item_is_template_from_mount_point);
|
|
|
|
|
|
/*
|
|
sys
|
|
*/
|
|
ezc_functions.Insert("sys_ver_major", sys_ver_major);
|
|
ezc_functions.Insert("sys_ver_minor", sys_ver_minor);
|
|
ezc_functions.Insert("sys_ver_revision", sys_ver_revision);
|
|
|
|
|
|
/*
|
|
upload
|
|
*/
|
|
ezc_functions.Insert("upload_ckeditor_funnum", upload_ckeditor_funnum);
|
|
|
|
|
|
/*
|
|
uptime
|
|
*/
|
|
ezc_functions.Insert("uptime_more_than_one_day", uptime_more_than_one_day);
|
|
ezc_functions.Insert("uptime_days", uptime_days);
|
|
ezc_functions.Insert("uptime_hours", uptime_hours);
|
|
|
|
|
|
/*
|
|
user
|
|
*/
|
|
ezc_functions.Insert("user_name", user_name);
|
|
ezc_functions.Insert("user_logged", user_logged);
|
|
ezc_functions.Insert("user_super_user", user_super_user);
|
|
ezc_functions.Insert("user_is_in_group", user_is_in_group);
|
|
ezc_functions.Insert("user_is_in_all_groups", user_is_in_all_groups);
|
|
ezc_functions.Insert("user_can_use_html", user_can_use_html);
|
|
ezc_functions.Insert("user_can_use_bbcode", user_can_use_bbcode);
|
|
ezc_functions.Insert("user_can_use_raw", user_can_use_raw);
|
|
|
|
|
|
/*
|
|
template
|
|
*/
|
|
ezc_functions.Insert("template_index", template_index);
|
|
ezc_functions.Insert("template_tab", template_tab);
|
|
ezc_functions.Insert("template_tab_index", template_tab_index);
|
|
ezc_functions.Insert("template_tab_isdefault", template_tab_isdefault);
|
|
ezc_functions.Insert("template_tab_file_name", template_tab_file_name);
|
|
|
|
|
|
/*
|
|
thread
|
|
*/
|
|
ezc_functions.Insert("thread_is", thread_is);
|
|
ezc_functions.Insert("thread_tab", thread_tab);
|
|
ezc_functions.Insert("thread_tab_url", thread_tab_url);
|
|
ezc_functions.Insert("thread_tab_subject", thread_tab_subject);
|
|
ezc_functions.Insert("thread_tab_author", thread_tab_author);
|
|
ezc_functions.Insert("thread_tab_answers", thread_tab_answers);
|
|
ezc_functions.Insert("thread_tab_last_item_date_modification", thread_tab_last_item_date_modification);
|
|
ezc_functions.Insert("thread_tab_last_item_date_modification_nice", thread_tab_last_item_date_modification_nice);
|
|
ezc_functions.Insert("thread_tab_last_item_user", thread_tab_last_item_user);
|
|
ezc_functions.Insert("thread_can_create", thread_can_create);
|
|
|
|
|
|
/*
|
|
winix
|
|
*/
|
|
ezc_functions.Insert("winix_cur_time", winix_cur_time);
|
|
ezc_functions.Insert("winix_how_many_sessions", winix_how_many_sessions);
|
|
ezc_functions.Insert("winix_users_logged", winix_users_logged);
|
|
ezc_functions.Insert("winix_function", winix_function);
|
|
ezc_functions.Insert("winix_function_is", winix_function_is);
|
|
ezc_functions.Insert("winix_function_param_is", winix_function_param_is);
|
|
ezc_functions.Insert("winix_has_plugin", winix_has_plugin);
|
|
ezc_functions.Insert("winix_loadavg_now", winix_loadavg_now);
|
|
ezc_functions.Insert("winix_loadavg_1", winix_loadavg_1);
|
|
ezc_functions.Insert("winix_loadavg_5", winix_loadavg_5);
|
|
ezc_functions.Insert("winix_loadavg_15", winix_loadavg_15);
|
|
ezc_functions.Insert("winix_req_per_sec_now", winix_req_per_sec_now);
|
|
ezc_functions.Insert("winix_req_per_sec_1", winix_req_per_sec_1);
|
|
ezc_functions.Insert("winix_req_per_sec_5", winix_req_per_sec_5);
|
|
ezc_functions.Insert("winix_req_per_sec_15", winix_req_per_sec_15);
|
|
ezc_functions.Insert("winix_err_is", winix_err_is);
|
|
ezc_functions.Insert("winix_err_code", winix_err_code);
|
|
ezc_functions.Insert("winix_is_err_in_locales", winix_is_err_in_locales);
|
|
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);
|
|
ezc_functions.Insert("winix_false", winix_false);
|
|
ezc_functions.Insert("winix_true", winix_true);
|
|
|
|
|
|
/*
|
|
who
|
|
*/
|
|
ezc_functions.Insert("who_tab", who_tab);
|
|
ezc_functions.Insert("who_tab_lp", who_tab_lp);
|
|
ezc_functions.Insert("who_tab_user", who_tab_user);
|
|
ezc_functions.Insert("who_tab_time", who_tab_time);
|
|
ezc_functions.Insert("who_tab_last_time", who_tab_last_time);
|
|
|
|
|
|
|
|
/*
|
|
others
|
|
*/
|
|
ezc_functions.Insert("content", content);
|
|
|
|
|
|
plugin.Call(WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions);
|
|
log << log3 << "Templates: there are " << ezc_functions.Size() << " ezc functions" << logend;
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
Locale::Lang lang = Locale::StrToLang(config->locale_str);
|
|
|
|
if( lang != Locale::lang_unknown )
|
|
locale.SetLang(lang);
|
|
else
|
|
locale.SetLang(Locale::lang_en);
|
|
|
|
locale.UTF8(config->utf8);
|
|
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::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;
|
|
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, 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);
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
{
|
|
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 Mount & mount = i->second;
|
|
int html_id = TemplatesFunctions::system->mounts.MountParHtmlTemplate();
|
|
|
|
if( mount.param[html_id].defined )
|
|
{
|
|
size_t len = mount.param[html_id].arg.size();
|
|
size_t a;
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// index_patterns and patterns for items are not cleared here
|
|
void Templates::ClearPatterns()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
TemplatesFunctions::ClearPatterns(patterns, pat_last);
|
|
TemplatesFunctions::ClearPatterns(patterns_fun, functions->FunctionsSize());
|
|
}
|
|
|
|
|
|
void Templates::Generate()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
// !! locale beda w zaleznosci od uzytkownika
|
|
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
|
|
return;
|
|
|
|
Ezc::Pattern * index = 0;
|
|
const std::wstring * index_file_local = 0;
|
|
|
|
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 )
|
|
{
|
|
const std::wstring & temp = TemplatesFunctions::system->mounts.pmount->FirstArg(
|
|
TemplatesFunctions::system->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());
|
|
|
|
if( !index )
|
|
index = &patterns[locale.GetLang()][pat_index];
|
|
|
|
EzcGen generator;
|
|
//generator.Generate(request->page, *index, ezc_functions);
|
|
generator.Generate(request->page, *index);
|
|
}
|
|
|
|
|
|
|
|
void Templates::GenerateRunRaw()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
if( !empty_pars.empty() )
|
|
empty_pars.clear();
|
|
|
|
Info info(request->page, empty_pars, empty_string);
|
|
|
|
info.iter = 0;
|
|
info.res = false;
|
|
|
|
item_run(info);
|
|
}
|
|
|
|
|
|
void Templates::SetConfig(Config * pconfig)
|
|
{
|
|
TemplatesFunctions::config = pconfig;
|
|
TemplatesFunctions::index_patterns.SetConfig(pconfig);
|
|
}
|
|
|
|
|
|
void Templates::SetRequest(Request * prequest)
|
|
{
|
|
TemplatesFunctions::request = prequest;
|
|
}
|
|
|
|
|
|
void Templates::SetDb(Db * pdb)
|
|
{
|
|
TemplatesFunctions::db = pdb;
|
|
}
|
|
|
|
|
|
void Templates::SetSystem(System * psystem)
|
|
{
|
|
TemplatesFunctions::system = psystem;
|
|
}
|
|
|
|
|
|
void Templates::SetFunctions(Functions * pfunctions)
|
|
{
|
|
TemplatesFunctions::functions = pfunctions;
|
|
}
|
|
|
|
|
|
void Templates::SetSessionManager(SessionManager * psession_manager)
|
|
{
|
|
TemplatesFunctions::session_manager = psession_manager;
|
|
}
|
|
|
|
|
|
Templates::Templates()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
index_patterns.SetEzcFunctions(&ezc_functions);
|
|
pattern_cacher.SetEzcFunctions(&ezc_functions);
|
|
}
|
|
|
|
|