429 lines
10 KiB
C++
Executable File
429 lines
10 KiB
C++
Executable File
/*
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "templates.h"
|
|
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
{
|
|
Ezc::Pattern pat_index;
|
|
Ezc::Pattern pat_fun_cat;
|
|
Ezc::Pattern pat_fun_ls;
|
|
Ezc::Pattern pat_fun_emacs;
|
|
Ezc::Pattern pat_fun_mkdir;
|
|
Ezc::Pattern pat_fun_default;
|
|
Ezc::Pattern pat_fun_priv;
|
|
Ezc::Pattern pat_fun_rm;
|
|
Ezc::Pattern pat_fun_who;
|
|
Ezc::Pattern pat_fun_run;
|
|
Ezc::Pattern pat_fun_last;
|
|
Ezc::Pattern pat_fun_thread;
|
|
Ezc::Pattern pat_fun_createthread;
|
|
Ezc::Pattern pat_err_item_required;
|
|
Ezc::Pattern pat_err_404;
|
|
Ezc::Pattern pat_err_per_denied;
|
|
Ezc::Pattern pat_err_others;
|
|
Ezc::Pattern pat_item_info;
|
|
|
|
|
|
Ezc::Functions functions;
|
|
|
|
|
|
PatternCacher pattern_cacher;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// !! tymczasowa funkcja
|
|
void is_group_tv(Info & i)
|
|
{
|
|
long gid = data.groups.GetGroupId("tv");
|
|
|
|
if( request.session->puser && request.session->puser->IsMemberOf(gid) )
|
|
i.result = true;
|
|
}
|
|
|
|
|
|
|
|
|
|
Ezc::Pattern * content_for_function()
|
|
{
|
|
Ezc::Pattern * p = 0;
|
|
|
|
|
|
if( !request.pfunction )
|
|
{
|
|
log << log1 << "Templates: no function" << logend;
|
|
return p;
|
|
}
|
|
|
|
|
|
switch( request.pfunction->code )
|
|
{
|
|
case FUN_CAT:
|
|
p = &pat_fun_cat;
|
|
break;
|
|
|
|
case FUN_LS:
|
|
p = &pat_fun_ls;
|
|
break;
|
|
|
|
case FUN_RM:
|
|
p = &pat_fun_rm;
|
|
break;
|
|
|
|
case FUN_EMACS:
|
|
p = &pat_fun_emacs;
|
|
break;
|
|
|
|
case FUN_MKDIR:
|
|
p = &pat_fun_mkdir;
|
|
break;
|
|
|
|
case FUN_DEFAULT:
|
|
p = &pat_fun_default;
|
|
break;
|
|
|
|
case FUN_PRIV:
|
|
p = &pat_fun_priv;
|
|
break;
|
|
|
|
case FUN_RUN:
|
|
p = &pat_fun_run;
|
|
break;
|
|
|
|
case FUN_WHO:
|
|
p = &pat_fun_who;
|
|
break;
|
|
|
|
case FUN_LAST:
|
|
p = &pat_fun_last;
|
|
break;
|
|
|
|
case FUN_THREAD:
|
|
p = &pat_fun_thread;
|
|
break;
|
|
|
|
case FUN_CREATETHREAD:
|
|
p = &pat_fun_createthread;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
|
|
return p;
|
|
}
|
|
|
|
|
|
|
|
void content(Info & i)
|
|
{
|
|
Ezc::Pattern * p = 0;
|
|
|
|
switch( request.status )
|
|
{
|
|
case Error::ok:
|
|
p = content_for_function();
|
|
break;
|
|
|
|
case Error::item_required:
|
|
p = &pat_err_item_required;
|
|
break;
|
|
|
|
case Error::permision_denied:
|
|
p = &pat_err_per_denied;
|
|
break;
|
|
|
|
case Error::db_no_item:
|
|
case Error::no_function:
|
|
case Error::unknown_param:
|
|
p = &pat_err_404;
|
|
break;
|
|
|
|
default:
|
|
p = &pat_err_others;
|
|
break;
|
|
}
|
|
|
|
|
|
if( p )
|
|
{
|
|
Ezc::Generator gen(i.out, *p, functions);
|
|
gen.Generate();
|
|
}
|
|
else
|
|
{
|
|
i.out << "<!-- there are not any patterns -->";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|
|
|
|
|
|
void Templates::CreateFunctions()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
functions.Clear();
|
|
|
|
|
|
/*
|
|
sys
|
|
*/
|
|
functions.Insert("sys_ver_major", sys_ver_major);
|
|
functions.Insert("sys_ver_minor", sys_ver_minor);
|
|
functions.Insert("sys_ver_revision", sys_ver_revision);
|
|
|
|
|
|
/*
|
|
doc
|
|
*/
|
|
functions.Insert("doc_language", doc_language);
|
|
functions.Insert("doc_title", doc_title);
|
|
functions.Insert("doc_charset", doc_charset);
|
|
functions.Insert("doc_base_url", doc_base_url);
|
|
functions.Insert("doc_current_url", doc_current_url);
|
|
functions.Insert("doc_status_error", doc_status_error);
|
|
functions.Insert("doc_status_code", doc_status_code);
|
|
|
|
|
|
/*
|
|
item
|
|
*/
|
|
functions.Insert("item_is", item_is);
|
|
functions.Insert("item_id", item_id);
|
|
functions.Insert("item_subject", item_subject);
|
|
functions.Insert("item_subject_noescape", item_subject_noescape);
|
|
functions.Insert("item_content", item_content);
|
|
functions.Insert("item_content_noescape", item_content_noescape);
|
|
functions.Insert("item_privileges", item_privileges);
|
|
functions.Insert("item_dir", item_dir);
|
|
functions.Insert("item_url", item_url);
|
|
functions.Insert("item_link", item_link);
|
|
functions.Insert("item_can_read", item_can_read);
|
|
functions.Insert("item_info", item_info);
|
|
functions.Insert("item_user", item_user);
|
|
functions.Insert("item_date_creation", item_date_creation);
|
|
functions.Insert("item_date_modification", item_date_modification);
|
|
functions.Insert("item_dates_equal", item_dates_equal);
|
|
functions.Insert("item_run", item_run);
|
|
|
|
functions.Insert("item_old_id", item_old_id);
|
|
functions.Insert("item_old_subject", item_old_subject);
|
|
functions.Insert("item_old_subject_noescape", item_old_subject_noescape);
|
|
functions.Insert("item_old_content", item_old_content);
|
|
functions.Insert("item_old_content_noescape", item_old_content_noescape);
|
|
functions.Insert("item_old_privileges", item_old_privileges);
|
|
functions.Insert("item_old_dir", item_old_dir);
|
|
functions.Insert("item_old_url", item_old_url);
|
|
functions.Insert("item_old_link", item_old_link);
|
|
|
|
functions.Insert("item_tab", item_tab);
|
|
functions.Insert("item_tab_id", item_tab_id);
|
|
functions.Insert("item_tab_subject", item_tab_subject);
|
|
functions.Insert("item_tab_subject_noescape", item_tab_subject_noescape);
|
|
functions.Insert("item_tab_content", item_tab_content);
|
|
functions.Insert("item_tab_content_noescape", item_tab_content_noescape);
|
|
functions.Insert("item_tab_privileges", item_tab_privileges);
|
|
functions.Insert("item_tab_dir", item_tab_dir);
|
|
functions.Insert("item_tab_url", item_tab_url);
|
|
functions.Insert("item_tab_link", item_tab_link);
|
|
|
|
|
|
/*
|
|
dir
|
|
*/
|
|
functions.Insert("dir", dir);
|
|
functions.Insert("dir_can_read_exec", dir_can_read_exec);
|
|
|
|
functions.Insert("dir_childs_tab", dir_childs_tab);
|
|
functions.Insert("dir_childs_tab_url", dir_childs_tab_url);
|
|
|
|
functions.Insert("dir_tab", dir_tab);
|
|
functions.Insert("dir_tab_url", dir_tab_url);
|
|
functions.Insert("dir_tab_link", dir_tab_link);
|
|
|
|
functions.Insert("dir_last_default_item_dir", dir_last_default_item_dir);
|
|
functions.Insert("dir_last_default_item_url", dir_last_default_item_url);
|
|
|
|
functions.Insert("dir_old", dir_old);
|
|
|
|
/*
|
|
user
|
|
*/
|
|
functions.Insert("user_name", user_name);
|
|
functions.Insert("user_logged", user_logged);
|
|
functions.Insert("user_super_user", user_super_user);
|
|
|
|
|
|
/*
|
|
privileges
|
|
*/
|
|
functions.Insert("priv_user_tab", priv_user_tab);
|
|
functions.Insert("priv_user_tab_name", priv_user_tab_name);
|
|
functions.Insert("priv_user_tab_isdefault", priv_user_tab_isdefault);
|
|
|
|
functions.Insert("priv_group_tab", priv_group_tab);
|
|
functions.Insert("priv_group_tab_name", priv_group_tab_name);
|
|
functions.Insert("priv_group_tab_isdefault", priv_group_tab_isdefault);
|
|
|
|
|
|
/*
|
|
done
|
|
*/
|
|
functions.Insert("done_errors", done_errors);
|
|
functions.Insert("done_status", done_status);
|
|
functions.Insert("done_status_no_item", done_status_no_item);
|
|
functions.Insert("done_status_incorrect_dir", done_status_incorrect_dir);
|
|
functions.Insert("done_added_item", done_added_item);
|
|
functions.Insert("done_edited_item", done_edited_item);
|
|
functions.Insert("done_deleted_item", done_deleted_item);
|
|
functions.Insert("done_privileged_item", done_privileged_item);
|
|
functions.Insert("done_loggedout", done_loggedout);
|
|
functions.Insert("done_added_dir", done_added_dir);
|
|
functions.Insert("done_deleted_dir", done_deleted_dir);
|
|
functions.Insert("done_defaulted_dir", done_defaulted_dir);
|
|
|
|
|
|
/*
|
|
others
|
|
*/
|
|
functions.Insert("content", content);
|
|
|
|
|
|
/*
|
|
who
|
|
*/
|
|
functions.Insert("who_tab", who_tab);
|
|
functions.Insert("who_tab_lp", who_tab_lp);
|
|
functions.Insert("who_tab_user", who_tab_user);
|
|
functions.Insert("who_tab_time", who_tab_time);
|
|
functions.Insert("who_tab_last_time", who_tab_last_time);
|
|
|
|
|
|
/*
|
|
last
|
|
*/
|
|
functions.Insert("last_tab", last_tab);
|
|
functions.Insert("last_tab_name", last_tab_name);
|
|
functions.Insert("last_tab_ip", last_tab_ip);
|
|
functions.Insert("last_tab_start", last_tab_start);
|
|
functions.Insert("last_tab_end", last_tab_end);
|
|
|
|
|
|
/*
|
|
thread
|
|
*/
|
|
functions.Insert("thread_subject", thread_subject);
|
|
|
|
|
|
|
|
// !! tymczasowa
|
|
functions.Insert("is_group_tv", is_group_tv);
|
|
|
|
|
|
#ifdef APPTEMPLATES
|
|
AppTemplateFunctions::CreateAppFunctions(functions);
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Templates::Read()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
pat_index.Directory(data.templates);
|
|
pat_index.ParseFile(data.default_index);
|
|
|
|
pat_err_404.Directory(data.templates);
|
|
pat_err_404.ParseFile("err_404.html");
|
|
|
|
pat_err_per_denied.Directory(data.templates);
|
|
pat_err_per_denied.ParseFile("err_per_denied.html");
|
|
|
|
pat_fun_cat.Directory(data.templates);
|
|
pat_fun_cat.ParseFile("fun_cat.html");
|
|
|
|
pat_fun_ls.Directory(data.templates);
|
|
pat_fun_ls.ParseFile("fun_ls.html");
|
|
|
|
pat_fun_rm.Directory(data.templates);
|
|
pat_fun_rm.ParseFile("fun_rm.html");
|
|
|
|
pat_err_item_required.Directory(data.templates);
|
|
pat_err_item_required.ParseFile("err_item_required.html");
|
|
|
|
pat_fun_emacs.Directory(data.templates);
|
|
pat_fun_emacs.ParseFile("fun_emacs.html");
|
|
|
|
pat_fun_mkdir.Directory(data.templates);
|
|
pat_fun_mkdir.ParseFile("fun_mkdir.html");
|
|
|
|
pat_fun_default.Directory(data.templates);
|
|
pat_fun_default.ParseFile("fun_default.html");
|
|
|
|
pat_fun_priv.Directory(data.templates);
|
|
pat_fun_priv.ParseFile("fun_priv.html");
|
|
|
|
pat_err_others.Directory(data.templates);
|
|
pat_err_others.ParseFile("err_others.html");
|
|
|
|
pat_fun_who.Directory(data.templates);
|
|
pat_fun_who.ParseFile("fun_who.html");
|
|
|
|
pat_fun_run.Directory(data.templates);
|
|
pat_fun_run.ParseFile("fun_run.html");
|
|
|
|
pat_fun_last.Directory(data.templates);
|
|
pat_fun_last.ParseFile("fun_last.html");
|
|
|
|
pat_item_info.Directory(data.templates);
|
|
pat_item_info.ParseFile("item_info.html");
|
|
|
|
pat_fun_thread.Directory(data.templates);
|
|
pat_fun_thread.ParseFile("fun_thread.html");
|
|
|
|
pat_fun_createthread.Directory(data.templates);
|
|
pat_fun_createthread.ParseFile("fun_createthread.html");
|
|
|
|
CreateFunctions();
|
|
|
|
#ifdef APPTEMPLATES
|
|
AppTemplateFunctions::ReadAppPatterns();
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
void Templates::Generate()
|
|
{
|
|
using namespace TemplatesFunctions;
|
|
|
|
|
|
Ezc::Generator generator(request.page, pat_index, functions);
|
|
|
|
generator.Generate();
|
|
}
|
|
|