added: created directory 'content' which has Content:: files
added: created directory 'templates' which has Templates:: and TemplatesFunctions:: files changed: content.cpp split into many files (directory 'content') changed: templates.cpp split into many files (directory 'templates') added: full permissions changed: building of the program (GNU make is used now) Makefile and Makefile.dep added into directories added: a parser 'FunctionParser' is used to parse the GET string it recognizes directories, items, functions, functions parameters added: other classes: Function, Functions added: function: ls, privileges changed: function 'id' to 'node' changed: version: to 0.2.0 added/changed: a lot of work have been done git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@469 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
312
templates/templates.cpp
Executable file
312
templates/templates.cpp
Executable file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* 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_privileges;
|
||||
Ezc::Pattern pat_fun_rm;
|
||||
Ezc::Pattern pat_err_item_required;
|
||||
Ezc::Pattern pat_err_404;
|
||||
Ezc::Pattern pat_err_per_denied;
|
||||
Ezc::Pattern pat_err_others;
|
||||
|
||||
|
||||
|
||||
Ezc::Functions functions;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// !! 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 Function::cat:
|
||||
p = &pat_fun_cat;
|
||||
break;
|
||||
|
||||
case Function::ls:
|
||||
p = &pat_fun_ls;
|
||||
break;
|
||||
|
||||
case Function::rm:
|
||||
p = &pat_fun_rm;
|
||||
break;
|
||||
|
||||
case Function::emacs:
|
||||
p = &pat_fun_emacs;
|
||||
break;
|
||||
|
||||
case Function::privileges:
|
||||
p = &pat_fun_privileges;
|
||||
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:
|
||||
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_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_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);
|
||||
|
||||
|
||||
/*
|
||||
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_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);
|
||||
|
||||
|
||||
/*
|
||||
others
|
||||
*/
|
||||
functions.Insert("content", content);
|
||||
|
||||
|
||||
// !! tymczasowa
|
||||
functions.Insert("is_group_tv", is_group_tv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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_privileges.Directory(data.templates);
|
||||
pat_fun_privileges.ParseFile("fun_privileges.html");
|
||||
|
||||
pat_err_others.Directory(data.templates);
|
||||
pat_err_others.ParseFile("err_others.html");
|
||||
|
||||
CreateFunctions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Templates::Generate()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
|
||||
Ezc::Generator generator(request.page, pat_index, functions);
|
||||
|
||||
generator.Generate();
|
||||
}
|
||||
|
Reference in New Issue
Block a user