changed: rename cmslu to winix
changed: html templates are a part of winix now and the user can provide special html templates for its site added: locales added: html templates are using HtmlFilter now (locales) changed: now we have html templates for each language git-svn-id: svn://ttmath.org/publicrep/winix/trunk@560 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "localefilter.h"
|
||||
#include "../core/data.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/misc.h"
|
||||
@@ -16,37 +17,11 @@
|
||||
|
||||
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_reload;
|
||||
Ezc::Pattern pat_fun_createthread;
|
||||
Ezc::Pattern pat_fun_upload;
|
||||
Ezc::Pattern pat_fun_ticket;
|
||||
Ezc::Pattern pat_fun_createticket;
|
||||
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::Pattern pat_item_tab_info;
|
||||
Ezc::Pattern pat_dir_last_info;
|
||||
|
||||
|
||||
TemplatesMisc::Patterns patterns;
|
||||
Ezc::Functions functions;
|
||||
|
||||
|
||||
PatternCacher pattern_cacher;
|
||||
|
||||
PatternCacher pattern_cacher;
|
||||
LocaleFilter locale_filter;
|
||||
|
||||
|
||||
|
||||
@@ -60,86 +35,44 @@ Ezc::Pattern * content_for_function()
|
||||
{
|
||||
Ezc::Pattern * p = 0;
|
||||
|
||||
|
||||
if( !request.pfunction )
|
||||
{
|
||||
log << log1 << "Templates: no function" << logend;
|
||||
return p;
|
||||
}
|
||||
|
||||
static PatName pat_name_tab[] = {
|
||||
{FUN_CAT, pat_fun_cat},
|
||||
{FUN_LS, pat_fun_ls},
|
||||
{FUN_RM, pat_fun_rm},
|
||||
{FUN_EMACS, pat_fun_emacs},
|
||||
{FUN_MKDIR, pat_fun_mkdir},
|
||||
{FUN_DEFAULT, pat_fun_default},
|
||||
{FUN_PRIV, pat_fun_priv},
|
||||
{FUN_RUN, pat_fun_run},
|
||||
{FUN_WHO, pat_fun_who},
|
||||
{FUN_LAST, pat_fun_last},
|
||||
{FUN_THREAD, pat_fun_thread},
|
||||
{FUN_RELOAD, pat_fun_reload},
|
||||
{FUN_CREATETHREAD, pat_fun_createthread},
|
||||
{FUN_TICKET, pat_fun_ticket},
|
||||
{FUN_CREATETICKET, pat_fun_createticket},
|
||||
{FUN_EDITTICKET, pat_fun_createticket},
|
||||
{FUN_UPLOAD, pat_fun_upload}
|
||||
};
|
||||
|
||||
switch( request.pfunction->code )
|
||||
size_t i, len = sizeof(pat_name_tab)/sizeof(PatName);
|
||||
|
||||
for(i=0 ; i<len ; ++i)
|
||||
{
|
||||
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_RELOAD:
|
||||
p = &pat_fun_reload;
|
||||
break;
|
||||
|
||||
case FUN_CREATETHREAD:
|
||||
p = &pat_fun_createthread;
|
||||
break;
|
||||
|
||||
case FUN_TICKET:
|
||||
p = &pat_fun_ticket;
|
||||
break;
|
||||
|
||||
case FUN_CREATETICKET:
|
||||
case FUN_EDITTICKET:
|
||||
p = &pat_fun_createticket;
|
||||
break;
|
||||
|
||||
case FUN_UPLOAD:
|
||||
p = &pat_fun_upload;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
if( pat_name_tab[i].fun_code == request.pfunction->code )
|
||||
{
|
||||
// !! data.locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = &patterns[data.locale.GetLang()][pat_name_tab[i].pat];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -149,6 +82,13 @@ void content(Info & i)
|
||||
{
|
||||
Ezc::Pattern * p = 0;
|
||||
|
||||
if( static_cast<size_t>(data.locale.GetLang()) >= patterns.size() )
|
||||
{
|
||||
log << log1 << "Templates: there is no such a language in patterns" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch( request.status )
|
||||
{
|
||||
case Error::ok:
|
||||
@@ -165,17 +105,20 @@ Ezc::Pattern * p = 0;
|
||||
case Error::cant_change_user:
|
||||
case Error::cant_change_group:
|
||||
case Error::cant_change_privileges:
|
||||
p = &pat_err_per_denied;
|
||||
// !! data.locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = &patterns[data.locale.GetLang()][pat_err_per_denied];
|
||||
break;
|
||||
|
||||
case Error::no_item:
|
||||
case Error::no_function:
|
||||
case Error::unknown_param:
|
||||
p = &pat_err_404;
|
||||
// !! data.locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = &patterns[data.locale.GetLang()][pat_err_404];
|
||||
break;
|
||||
|
||||
default:
|
||||
p = &pat_err_others;
|
||||
// !! data.locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = &patterns[data.locale.GetLang()][pat_err_others];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -218,9 +161,7 @@ void Templates::CreateFunctions()
|
||||
/*
|
||||
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_base_url_static", doc_base_url_static);
|
||||
functions.Insert("doc_base_url_static_auth", doc_base_url_static_auth);
|
||||
@@ -482,90 +423,59 @@ void Templates::CreateFunctions()
|
||||
|
||||
|
||||
|
||||
|
||||
void Templates::ReadTemplates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
pat_index.Directory(data.templates);
|
||||
pat_index.ParseFile("index.html");
|
||||
|
||||
pat_err_404.Directory(data.templates);
|
||||
pat_err_404.ParseFile("err_404.html");
|
||||
using namespace TemplatesFunctions;
|
||||
using namespace TemplatesMisc;
|
||||
|
||||
pat_err_per_denied.Directory(data.templates);
|
||||
pat_err_per_denied.ParseFile("err_per_denied.html");
|
||||
ClearPatterns();
|
||||
|
||||
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_item_tab_info.Directory(data.templates);
|
||||
pat_item_tab_info.ParseFile("item_tab_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");
|
||||
|
||||
pat_dir_last_info.Directory(data.templates);
|
||||
pat_dir_last_info.ParseFile("dir_last_info.html");
|
||||
|
||||
pat_fun_reload.Directory(data.templates);
|
||||
pat_fun_reload.ParseFile("fun_reload.html");
|
||||
|
||||
pat_fun_upload.Directory(data.templates);
|
||||
pat_fun_upload.ParseFile("fun_upload.html");
|
||||
|
||||
pat_fun_ticket.Directory(data.templates);
|
||||
pat_fun_ticket.ParseFile("fun_ticket.html");
|
||||
|
||||
pat_fun_createticket.Directory(data.templates);
|
||||
pat_fun_createticket.ParseFile("fun_createticket.html");
|
||||
Read(patterns, pat_index, locale_filter, "index.html");
|
||||
Read(patterns, pat_err_404, locale_filter, "err_404.html");
|
||||
Read(patterns, pat_err_per_denied, locale_filter, "err_per_denied.html");
|
||||
Read(patterns, pat_fun_cat, locale_filter, "fun_cat.html");
|
||||
Read(patterns, pat_fun_ls, locale_filter, "fun_ls.html");
|
||||
Read(patterns, pat_fun_rm, locale_filter, "fun_rm.html");
|
||||
Read(patterns, pat_fun_emacs, locale_filter, "fun_emacs.html");
|
||||
Read(patterns, pat_fun_mkdir, locale_filter, "fun_mkdir.html");
|
||||
Read(patterns, pat_fun_default, locale_filter, "fun_default.html");
|
||||
Read(patterns, pat_fun_priv, locale_filter, "fun_priv.html");
|
||||
Read(patterns, pat_err_others, locale_filter, "err_others.html");
|
||||
Read(patterns, pat_fun_who, locale_filter, "fun_who.html");
|
||||
Read(patterns, pat_fun_run, locale_filter, "fun_run.html");
|
||||
Read(patterns, pat_fun_last, locale_filter, "fun_last.html");
|
||||
Read(patterns, pat_item_info, locale_filter, "item_info.html");
|
||||
Read(patterns, pat_item_tab_info, locale_filter, "item_tab_info.html");
|
||||
Read(patterns, pat_fun_thread, locale_filter, "fun_thread.html");
|
||||
Read(patterns, pat_fun_createthread,locale_filter, "fun_createthread.html");
|
||||
Read(patterns, pat_dir_last_info, locale_filter, "dir_last_info.html");
|
||||
Read(patterns, pat_fun_reload, locale_filter, "fun_reload.html");
|
||||
Read(patterns, pat_fun_upload, locale_filter, "fun_upload.html");
|
||||
Read(patterns, pat_fun_ticket, locale_filter, "fun_ticket.html");
|
||||
Read(patterns, pat_fun_createticket,locale_filter, "fun_createticket.html");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Templates::ClearPatterns()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
TemplatesMisc::ClearPatterns(patterns, pat_last);
|
||||
}
|
||||
|
||||
|
||||
void Templates::Generate()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Ezc::Generator generator(request.page, pat_index, functions);
|
||||
// !! locale beda w zaleznosci od uzytkownika
|
||||
if( static_cast<size_t>(data.locale.GetLang()) >= patterns.size() )
|
||||
return;
|
||||
|
||||
Ezc::Generator generator(request.page, patterns[data.locale.GetLang()][pat_index], functions);
|
||||
generator.Generate();
|
||||
}
|
||||
|
||||
@@ -582,3 +492,10 @@ using namespace TemplatesFunctions;
|
||||
item_run(info);
|
||||
}
|
||||
|
||||
|
||||
Templates::Templates()
|
||||
{
|
||||
ClearPatterns();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user