948 lines
33 KiB
C++
Executable File
948 lines
33 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2012, 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
|
|
{
|
|
|
|
size_t pat_index; // main index pattern
|
|
size_t pat_index_fullscreen; // an empty pattern (without menus etc. but with all rest html tags, used for ckeditor images browser)
|
|
size_t pat_index_rawcontent; // completly empty pattern (only content, without html tags such as <html>, <body>)
|
|
size_t pat_err_404; // 404 error
|
|
size_t pat_err_per_denied; // permission denied error
|
|
|
|
Patterns patterns; // all html patterns
|
|
IndexPatterns index_patterns; // patterns for main index template (those from mountpoint)
|
|
// index_patterns 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;
|
|
const HtmlTextStream empty_stream;
|
|
|
|
// en empty stack item for templates functions
|
|
Ezc::Stack empty_stack;
|
|
|
|
Db * db;
|
|
Cur * cur;
|
|
Config * config;
|
|
System * system;
|
|
Functions * functions;
|
|
SessionManager * session_manager;
|
|
|
|
|
|
// generator used by content() function
|
|
static EzcGen content_gen;
|
|
|
|
|
|
|
|
Ezc::Pattern * GetPatternForFunction()
|
|
{
|
|
static std::wstring fun_file;
|
|
|
|
if( !cur->request->function )
|
|
{
|
|
log << log1 << "Templates: cannot get a template for a function (there is not a function)" << logend;
|
|
return 0;
|
|
}
|
|
|
|
fun_file = config->templates_fun_prefix;
|
|
fun_file += cur->request->function->fun.url;
|
|
fun_file += config->templates_fun_postfix;
|
|
|
|
Ezc::Pattern * p = change_patterns.Get(cur->mount->dir_id, fun_file, locale.GetLang());
|
|
|
|
if( p )
|
|
return p;
|
|
|
|
return patterns.Get(cur->request->function->template_index, locale.GetLang());
|
|
}
|
|
|
|
|
|
|
|
void content(Info & i)
|
|
{
|
|
Ezc::Pattern * p = 0;
|
|
|
|
switch( cur->request->status )
|
|
{
|
|
//case WINIX_ERR_NO_ITEM: !! we need something like 'error::item_required'
|
|
//p = &pat_err_item_required;
|
|
//break;
|
|
|
|
case WINIX_ERR_INCORRECT_URI: // !!temporarily
|
|
case WINIX_ERR_INTERNAL_ERROR: // !! temprarily
|
|
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.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.Get(pat_err_404, locale.GetLang());
|
|
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 = GetPatternForFunction();
|
|
break;
|
|
}
|
|
|
|
|
|
if( p )
|
|
{
|
|
content_gen.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
|
|
content_gen.Generate(i.out, *p);
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "Templates: content: 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);
|
|
|
|
|
|
/*
|
|
config
|
|
*/
|
|
ezc_functions.Insert("config_use_ssl", config_use_ssl);
|
|
ezc_functions.Insert("config_use_ssl_static", config_use_ssl_static);
|
|
ezc_functions.Insert("config_use_ssl_common", config_use_ssl_common);
|
|
ezc_functions.Insert("config_url_proto", config_url_proto);
|
|
ezc_functions.Insert("config_url_ssl_proto", config_url_ssl_proto);
|
|
ezc_functions.Insert("config_base_url", config_base_url);
|
|
ezc_functions.Insert("config_base_url_static", config_base_url_static);
|
|
ezc_functions.Insert("config_base_url_common", config_base_url_common);
|
|
|
|
|
|
/*
|
|
dir
|
|
*/
|
|
ezc_functions.Insert("dir", dir);
|
|
ezc_functions.Insert("dir_without_slash", dir_without_slash);
|
|
ezc_functions.Insert("dir_is_root", dir_is_root);
|
|
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_is", dir_is);
|
|
ezc_functions.Insert("dir_has_parents", dir_has_parents);
|
|
|
|
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_link_to", dir_last_link_to);
|
|
ezc_functions.Insert("dir_last_is_link_redirect", dir_last_is_link_redirect);
|
|
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);
|
|
ezc_functions.Insert("dir_last_meta_str", dir_last_meta_str);
|
|
|
|
|
|
/*
|
|
env
|
|
*/
|
|
ezc_functions.Insert("env_user_admin_env_str", env_user_admin_env_str);
|
|
ezc_functions.Insert("env_user_env_str", env_user_env_str);
|
|
ezc_functions.Insert("env_user_id", env_user_id);
|
|
ezc_functions.Insert("env_user_name", env_user_name);
|
|
ezc_functions.Insert("env_user_tab", env_user_tab);
|
|
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);
|
|
|
|
|
|
/*
|
|
filters
|
|
*/
|
|
ezc_functions.Insert("fil_urlencode", fil_urlencode);
|
|
ezc_functions.Insert("fil_qencode", fil_qencode);
|
|
ezc_functions.Insert("fil_capitalize", fil_capitalize);
|
|
ezc_functions.Insert("fil_tosmall", fil_tosmall);
|
|
ezc_functions.Insert("fil_firstup", fil_firstup);
|
|
ezc_functions.Insert("fil_first_wordup", fil_first_wordup);
|
|
|
|
|
|
/*
|
|
doc
|
|
*/
|
|
ezc_functions.Insert("doc_title", doc_title);
|
|
ezc_functions.Insert("doc_proto", doc_proto);
|
|
ezc_functions.Insert("doc_proto_static", doc_proto_static);
|
|
ezc_functions.Insert("doc_proto_common", doc_proto_common);
|
|
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);
|
|
ezc_functions.Insert("doc_css_tab", doc_css_tab);
|
|
ezc_functions.Insert("doc_css_tab_file", doc_css_tab_file);
|
|
ezc_functions.Insert("doc_css_tab_file_is_global", doc_css_tab_file_is_global);
|
|
ezc_functions.Insert("doc_css_tab_has_next", doc_css_tab_has_next);
|
|
ezc_functions.Insert("doc_css_is_empty", doc_css_is_empty);
|
|
ezc_functions.Insert("doc_css_is_one", doc_css_is_one);
|
|
ezc_functions.Insert("doc_css_more_than_one", doc_css_more_than_one);
|
|
|
|
|
|
/*
|
|
insert
|
|
*/
|
|
ezc_functions.Insert("insert_page", insert_page);
|
|
|
|
|
|
/*
|
|
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_has_static_file", item_has_static_file);
|
|
ezc_functions.Insert("item_has_thumb", item_has_thumb);
|
|
|
|
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_type_is_dir", item_type_is_dir);
|
|
ezc_functions.Insert("item_type_is_file", item_type_is_file);
|
|
ezc_functions.Insert("item_type_is_symlink", item_type_is_symlink);
|
|
ezc_functions.Insert("item_is_link_to", item_is_link_to);
|
|
ezc_functions.Insert("item_link_to", item_link_to);
|
|
ezc_functions.Insert("item_is_link_redirect", item_is_link_redirect);
|
|
ezc_functions.Insert("item_file_size", item_file_size);
|
|
ezc_functions.Insert("item_sort", item_sort);
|
|
ezc_functions.Insert("item_meta_str", item_meta_str);
|
|
ezc_functions.Insert("item_meta", item_meta);
|
|
ezc_functions.Insert("item_meta_tab", item_meta_tab);
|
|
ezc_functions.Insert("item_meta_tab_value", item_meta_tab_value);
|
|
ezc_functions.Insert("item_meta_tab_has_next", item_meta_tab_has_next);
|
|
|
|
ezc_functions.Insert("item_tab", item_tab);
|
|
ezc_functions.Insert("item_tab_index", item_tab_index);
|
|
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_filetype_is_none", item_tab_filetype_is_none);
|
|
ezc_functions.Insert("item_tab_filetype_is_image", item_tab_filetype_is_image);
|
|
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);
|
|
ezc_functions.Insert("item_tab_has_static_file", item_tab_has_static_file);
|
|
ezc_functions.Insert("item_tab_has_thumb", item_tab_has_thumb);
|
|
ezc_functions.Insert("item_tab_type_is_dir", item_tab_type_is_dir);
|
|
ezc_functions.Insert("item_tab_type_is_file", item_tab_type_is_file);
|
|
ezc_functions.Insert("item_tab_type_is_symlink", item_tab_type_is_symlink);
|
|
ezc_functions.Insert("item_tab_is_link_to", item_tab_is_link_to);
|
|
ezc_functions.Insert("item_tab_link_to", item_tab_link_to);
|
|
ezc_functions.Insert("item_tab_is_link_redirect", item_tab_is_link_redirect);
|
|
ezc_functions.Insert("item_tab_file_size", item_tab_file_size);
|
|
ezc_functions.Insert("item_tab_sort", item_tab_sort);
|
|
ezc_functions.Insert("item_tab_has_next", item_tab_has_next);
|
|
|
|
|
|
/*
|
|
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);
|
|
|
|
|
|
/*
|
|
login
|
|
*/
|
|
ezc_functions.Insert("login_path", login_path);
|
|
|
|
|
|
/*
|
|
man
|
|
*/
|
|
ezc_functions.Insert("man_winixfun_tab", man_winixfun_tab);
|
|
ezc_functions.Insert("man_winixfun_tab_index", man_winixfun_tab_index);
|
|
ezc_functions.Insert("man_winixfun_tab_name", man_winixfun_tab_name);
|
|
ezc_functions.Insert("man_ezcfun_tab", man_ezcfun_tab);
|
|
ezc_functions.Insert("man_ezcfun_tab_index", man_ezcfun_tab_index);
|
|
ezc_functions.Insert("man_ezcfun_tab_name", man_ezcfun_tab_name);
|
|
|
|
|
|
/*
|
|
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_lang_arg", mount_lang_arg);
|
|
ezc_functions.Insert("mount_lang_arg_is", mount_lang_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("mount_css_tab", mount_css_tab);
|
|
ezc_functions.Insert("mount_css_tab_file", mount_css_tab_file);
|
|
ezc_functions.Insert("mount_css_tab_file_is_global", mount_css_tab_file_is_global);
|
|
ezc_functions.Insert("mount_css_tab_has_next", mount_css_tab_has_next);
|
|
ezc_functions.Insert("mount_css_is_empty", mount_css_is_empty);
|
|
ezc_functions.Insert("mount_css_is_one", mount_css_is_one);
|
|
ezc_functions.Insert("mount_css_more_than_one", mount_css_more_than_one);
|
|
ezc_functions.Insert("mount_cur_type", mount_cur_type);
|
|
ezc_functions.Insert("mount_cur_dir", mount_cur_dir);
|
|
ezc_functions.Insert("mount_cur_fs", mount_cur_fs);
|
|
ezc_functions.Insert("mount_cur_parlist", mount_cur_parlist);
|
|
ezc_functions.Insert("mount_tab", mount_tab);
|
|
ezc_functions.Insert("mount_tab_type", mount_tab_type);
|
|
ezc_functions.Insert("mount_tab_dir", mount_tab_dir);
|
|
ezc_functions.Insert("mount_tab_fs", mount_tab_fs);
|
|
ezc_functions.Insert("mount_tab_parlist", mount_tab_parlist);
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
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);
|
|
|
|
|
|
/*
|
|
pw
|
|
*/
|
|
ezc_functions.Insert("pw_users_change_password_code", pw_users_change_password_code);
|
|
ezc_functions.Insert("pw_change_password_login", pw_change_password_login);
|
|
|
|
|
|
/*
|
|
rebus
|
|
*/
|
|
ezc_functions.Insert("rebus_question", rebus_question);
|
|
|
|
|
|
/*
|
|
slog
|
|
*/
|
|
ezc_functions.Insert("slog_tab", slog_tab);
|
|
ezc_functions.Insert("slog_tab_is_info", slog_tab_is_info);
|
|
ezc_functions.Insert("slog_tab_is_warning", slog_tab_is_warning);
|
|
ezc_functions.Insert("slog_tab_is_error", slog_tab_is_error);
|
|
ezc_functions.Insert("slog_tab_print", slog_tab_print);
|
|
|
|
|
|
/*
|
|
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);
|
|
ezc_functions.Insert("sys_plugin_tab", sys_plugin_tab);
|
|
ezc_functions.Insert("sys_plugin_tab_has_name", sys_plugin_tab_has_name);
|
|
ezc_functions.Insert("sys_plugin_tab_name", sys_plugin_tab_name);
|
|
|
|
|
|
/*
|
|
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_id", user_id);
|
|
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);
|
|
ezc_functions.Insert("user_tab", user_tab);
|
|
ezc_functions.Insert("user_tab_index", user_tab_index);
|
|
ezc_functions.Insert("user_tab_id", user_tab_id);
|
|
ezc_functions.Insert("user_tab_name", user_tab_name);
|
|
ezc_functions.Insert("user_tab_is_super_user", user_tab_is_super_user);
|
|
ezc_functions.Insert("user_tab_is_active", user_tab_is_active);
|
|
ezc_functions.Insert("user_tab_is_suspended", user_tab_is_suspended);
|
|
ezc_functions.Insert("user_tab_is_blocked", user_tab_is_blocked);
|
|
ezc_functions.Insert("user_tab_is_current", user_tab_is_current);
|
|
|
|
|
|
/*
|
|
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);
|
|
|
|
|
|
/*
|
|
winix
|
|
*/
|
|
ezc_functions.Insert("winix_account_need_email_verification", winix_account_need_email_verification);
|
|
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_function_param_is_not", winix_function_param_is_not);
|
|
ezc_functions.Insert("winix_function_param_value", winix_function_param_value);
|
|
ezc_functions.Insert("winix_function_param_value_is", winix_function_param_value_is);
|
|
ezc_functions.Insert("winix_function_param_value_is_not", winix_function_param_value_is_not);
|
|
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("false", winix_false);
|
|
ezc_functions.Insert("true", winix_true);
|
|
ezc_functions.Insert("winix_has_postvar", winix_has_postvar);
|
|
ezc_functions.Insert("winix_postvar", winix_postvar);
|
|
ezc_functions.Insert("winix_postvar_value_is", winix_postvar_value_is);
|
|
ezc_functions.Insert("winix_postvar_value_is_not", winix_postvar_value_is_not);
|
|
ezc_functions.Insert("str", str);
|
|
ezc_functions.Insert("strnc", strnc);
|
|
|
|
|
|
/*
|
|
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((Session*)0, WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions);
|
|
log << log3 << "Templates: there are " << ezc_functions.Size() << " ezc functions" << logend;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Templates::ReadLocale()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
locale.UTF8(config->utf8);
|
|
locale.SetLocaleFiles(config->locale_files);
|
|
// !! tutaj nie potrzeba ustawiac locali SetLang/SetLangDef (nie odczytujemy kluczy)
|
|
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::ReadTemplatesForFunctions()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
Functions::Iterator i = functions->Begin();
|
|
|
|
for(; i != functions->End() ; ++i)
|
|
{
|
|
const std::wstring & fun_name = i->first;
|
|
|
|
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 )
|
|
{
|
|
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;
|
|
|
|
html_filter.TrimWhite(config->html_filter_trim_white);
|
|
html_filter.BreakWord(config->html_filter_break_word);
|
|
html_filter.WrapLine(config->html_filter_wrap_line);
|
|
html_filter.InsertTabs(config->html_filter_tabs);
|
|
html_filter.ClearOrphans();
|
|
|
|
if( config->html_filter_orphans )
|
|
{
|
|
html_filter.OrphansMode(config->html_filter_orphans_mode);
|
|
|
|
for(size_t i=0 ; i<locale.Size() ; ++i)
|
|
{
|
|
if( locale.IsKeyLang(L"html_lang_attr_value", i) &&
|
|
locale.IsKeyLangList(L"language_orphans", i) )
|
|
{
|
|
html_filter.AssignOrphans(locale.Get(L"html_lang_attr_value", i),
|
|
locale.GetList(L"language_orphans", i));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
if( change_id < mount.param.size() && mount.param[change_id].defined )
|
|
{
|
|
const std::vector<std::wstring> & arg = mount.param[change_id].arg;
|
|
|
|
for(size_t a=0 ; a+1 < arg.size() ; a += 2)
|
|
change_patterns.Add(mount.dir_id, arg[a], arg[a+1]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
reading only new 'change' templates
|
|
those which are exists are not touched
|
|
the rest are deleted
|
|
*/
|
|
void Templates::ReadNewChangeTemplates()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
change_patterns.MarkAllToDelete();
|
|
ReadChangeTemplates();
|
|
change_patterns.DeleteMarked();
|
|
}
|
|
|
|
|
|
|
|
|
|
void Templates::ReadTemplates()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
ReadLocale();
|
|
patterns.Clear();
|
|
index_patterns.Clear();
|
|
change_patterns.Clear();
|
|
|
|
pat_index = patterns.Add(config->templates_index);
|
|
pat_index_fullscreen = patterns.Add(L"index_fullscreen.html");
|
|
pat_index_rawcontent = patterns.Add(L"index_rawcontent.html");
|
|
pat_err_404 = patterns.Add(L"err_404.html");
|
|
pat_err_per_denied = patterns.Add(L"err_per_denied.html");
|
|
|
|
ReadTemplatesForFunctions();
|
|
ReadIndexTemplates();
|
|
ReadChangeTemplates();
|
|
|
|
plugin.Call((Session*)0, WINIX_ADD_TEMPLATE);
|
|
|
|
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)
|
|
ReadTemplates();
|
|
}
|
|
|
|
|
|
|
|
|
|
// clearing at the end of a request
|
|
void Templates::RequestEnd()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
log << log4 << "Templates: patterns cache size: " << pattern_cacher.Size() << logend;
|
|
pattern_cacher.DeleteOldPatterns();
|
|
}
|
|
|
|
|
|
|
|
// can return a null pointer
|
|
Ezc::Pattern * Templates::SelectIndexPatternFromItemAndMountPoint()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
Ezc::Pattern * index = 0;
|
|
const std::wstring * index_file_local = 0;
|
|
|
|
// first we try to get an index template from 'template' item parameter (template winix function)
|
|
// if such a parameter is not defined then we try to get an index from the mount point
|
|
if( !cur->request->last_item->html_template.empty() )
|
|
{
|
|
index_file_local = &cur->request->last_item->html_template;
|
|
}
|
|
else
|
|
{
|
|
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.Get(*index_file_local, locale.GetLang());
|
|
|
|
return index;
|
|
}
|
|
|
|
|
|
|
|
|
|
// can return a null pointer
|
|
Ezc::Pattern * Templates::SelectIndexPattern()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
Ezc::Pattern * index = 0;
|
|
|
|
if( cur->request->IsParam(L"rawcontent") )
|
|
index = patterns.Get(pat_index_rawcontent, locale.GetLang());
|
|
else
|
|
if( cur->request->IsParam(L"fullscreen") )
|
|
index = patterns.Get(pat_index_fullscreen, locale.GetLang());
|
|
else
|
|
index = SelectIndexPatternFromItemAndMountPoint();
|
|
|
|
if( !index )
|
|
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, locale.GetLang());
|
|
|
|
if( !index )
|
|
index = patterns.Get(pat_index, locale.GetLang());;
|
|
|
|
return index;
|
|
}
|
|
|
|
|
|
|
|
void Templates::Generate()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
Ezc::Pattern * index = SelectIndexPattern();
|
|
|
|
if( index )
|
|
generator.Generate(cur->request->page, *index);
|
|
else
|
|
log << log1 << "Templates: I cannot find an index template" << logend;
|
|
}
|
|
|
|
|
|
|
|
void Templates::GenerateRunRaw()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
if( !empty_pars.empty() )
|
|
empty_pars.clear();
|
|
|
|
Info info(cur->request->page, empty_pars, empty_string, empty_stream);
|
|
|
|
info.iter = 0;
|
|
info.res = false;
|
|
|
|
item_run(info);
|
|
}
|
|
|
|
|
|
void Templates::Generate(Ezc::Pattern & pattern)
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
generator.Generate(cur->request->page, pattern);
|
|
}
|
|
|
|
|
|
|
|
void Templates::SetConfig(Config * pconfig)
|
|
{
|
|
TemplatesFunctions::config = pconfig;
|
|
}
|
|
|
|
|
|
void Templates::SetCur(Cur * pcur)
|
|
{
|
|
TemplatesFunctions::cur = pcur;
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
patterns.SetEzcFunctions(&ezc_functions);
|
|
patterns.SetLocale(&locale);
|
|
patterns.SetLocaleFilter(&locale_filter);
|
|
index_patterns.SetPatterns(&patterns);
|
|
change_patterns.SetPatterns(&patterns);
|
|
pattern_cacher.SetEzcFunctions(&ezc_functions);
|
|
}
|
|
|
|
|
|
|