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:
26
templates/Makefile
Executable file
26
templates/Makefile
Executable file
@@ -0,0 +1,26 @@
|
||||
o = templates.o sys.o item.o doc.o user.o dir.o done.o priv.o
|
||||
|
||||
|
||||
all: templates.a
|
||||
|
||||
templates.a: $(o)
|
||||
ar rcs templates.a $(o)
|
||||
|
||||
.SUFFIXES: .cpp .o
|
||||
|
||||
.cpp.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -f- *.cpp > Makefile.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.a
|
||||
|
||||
|
||||
include Makefile.dep
|
||||
|
||||
|
82
templates/Makefile.dep
Executable file
82
templates/Makefile.dep
Executable file
@@ -0,0 +1,82 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
dir.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
dir.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
dir.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
dir.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
dir.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
dir.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
dir.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
dir.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
dir.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
dir.o: ../core/log.h
|
||||
doc.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
doc.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
doc.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
doc.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
doc.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
doc.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
doc.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
doc.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
doc.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
doc.o: ../core/log.h
|
||||
done.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
done.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
done.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
done.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
done.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
done.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
done.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
done.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
done.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
done.o: ../core/log.h
|
||||
item.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
item.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
item.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
item.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
item.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
item.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
item.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
item.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
item.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
item.o: ../core/log.h
|
||||
priv.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
priv.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
priv.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
priv.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
priv.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
priv.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
priv.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
priv.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
priv.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
priv.o: ../core/log.h
|
||||
sys.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
sys.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
sys.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
sys.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
sys.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
sys.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
sys.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
sys.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
sys.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
sys.o: ../core/log.h
|
||||
templates.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
templates.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
templates.o: ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
templates.o: ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||
templates.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||
templates.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
templates.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||
templates.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
templates.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
templates.o: ../core/users.h ../core/groups.h ../core/log.h
|
||||
user.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
user.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
user.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
user.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
user.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
user.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
user.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
user.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
user.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
user.o: ../core/log.h
|
104
templates/dir.cpp
Executable file
104
templates/dir.cpp
Executable file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
|
||||
|
||||
|
||||
void dir(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a<request.dir_table.size() ; ++a)
|
||||
{
|
||||
HtmlEscape(i.out, request.dir_table[a]->url);
|
||||
i.out << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static std::vector<Item*> dir_childs_table;
|
||||
static size_t dir_childs_index;
|
||||
|
||||
// request.id is never 0 and we can start dir_childs_reqid from 0
|
||||
static size_t dir_childs_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void dir_childs_tab(Info & i)
|
||||
{
|
||||
if( dir_childs_reqid != request.id )
|
||||
{
|
||||
dir_childs_reqid = request.id;
|
||||
dir_childs_table.clear();
|
||||
|
||||
if( !request.dir_table.empty() )
|
||||
data.dirs.GetDirChilds(request.dir_table.back()->id, dir_childs_table);
|
||||
}
|
||||
|
||||
dir_childs_index = i.iter;
|
||||
i.result = dir_childs_index < dir_childs_table.size();
|
||||
}
|
||||
|
||||
|
||||
void dir_childs_tab_url(Info & i)
|
||||
{
|
||||
if( dir_childs_index < dir_childs_table.size() )
|
||||
HtmlEscape(i.out, dir_childs_table[dir_childs_index]->url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t dir_index;
|
||||
|
||||
|
||||
void dir_tab(Info & i)
|
||||
{
|
||||
dir_index = i.iter;
|
||||
i.result = dir_index < request.dir_table.size();
|
||||
}
|
||||
|
||||
|
||||
void dir_tab_url(Info & i)
|
||||
{
|
||||
if( dir_index < request.dir_table.size() )
|
||||
HtmlEscape(i.out, request.dir_table[dir_index]->url);
|
||||
}
|
||||
|
||||
|
||||
void dir_tab_link(Info & i)
|
||||
{
|
||||
i.out << data.base_url;
|
||||
|
||||
for(size_t a = 0 ; a <= dir_index && a < request.dir_table.size() ; ++a)
|
||||
{
|
||||
HtmlEscape(i.out, request.dir_table[a]->url);
|
||||
i.out << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
79
templates/doc.cpp
Executable file
79
templates/doc.cpp
Executable file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void doc_language(Info & i)
|
||||
{
|
||||
// at the moment only Polish language
|
||||
i.out << "pl";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_title(Info & i)
|
||||
{
|
||||
size_t a = 0;
|
||||
|
||||
// from 1 means skipping the root directory
|
||||
for(a = 1 ; a<request.dir_table.size() ; ++a)
|
||||
i.out << " / " << request.dir_table[a]->url;
|
||||
|
||||
if( request.is_item )
|
||||
i.out << " / " << request.item.subject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_charset(Info & i)
|
||||
{
|
||||
i.out << "iso-8859-2";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void doc_base_url(Info & i)
|
||||
{
|
||||
i.out << data.base_url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_current_url(Info & i)
|
||||
{
|
||||
i.out << request.env_request_uri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_status_error(Info & i)
|
||||
{
|
||||
i.result = request.status != Error::ok;
|
||||
}
|
||||
|
||||
|
||||
void doc_status_code(Info & i)
|
||||
{
|
||||
i.out << static_cast<int>( request.status );
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
72
templates/done.cpp
Executable file
72
templates/done.cpp
Executable file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
|
||||
|
||||
|
||||
void done_errors(Info & i)
|
||||
{
|
||||
i.result = request.session->done_status != Error::ok;
|
||||
}
|
||||
|
||||
|
||||
void done_status(Info & i)
|
||||
{
|
||||
i.out << static_cast<int>( request.session->done_status );
|
||||
}
|
||||
|
||||
|
||||
void done_status_incorrect_dir(Info & i)
|
||||
{
|
||||
i.result = request.session->done_status == Error::incorrect_dir;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void done_added_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::added_item;
|
||||
}
|
||||
|
||||
|
||||
void done_edited_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::edited_item;
|
||||
}
|
||||
|
||||
|
||||
void done_deleted_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::deleted_item;
|
||||
}
|
||||
|
||||
|
||||
void done_privileged_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::privileged_item;
|
||||
}
|
||||
|
||||
|
||||
void done_loggedout(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::loggedout;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
248
templates/item.cpp
Executable file
248
templates/item.cpp
Executable file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void item_is(Info & i)
|
||||
{
|
||||
i.result = request.is_item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_id(Info & i)
|
||||
{
|
||||
i.out << request.item.id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_subject(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.item.subject);
|
||||
}
|
||||
|
||||
|
||||
void item_subject_noescape(Info & i)
|
||||
{
|
||||
i.out << request.item.subject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_content(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.item.content);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_content_noescape(Info & i)
|
||||
{
|
||||
i.out << request.item.content;
|
||||
}
|
||||
|
||||
|
||||
void item_privileges(Info & i)
|
||||
{
|
||||
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
||||
}
|
||||
|
||||
|
||||
void item_dir(Info & i)
|
||||
{
|
||||
dir(i);
|
||||
}
|
||||
|
||||
|
||||
void item_url(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.item.url);
|
||||
}
|
||||
|
||||
|
||||
void item_link(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, data.base_url);
|
||||
item_dir(i);
|
||||
item_url(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void item_old_id(Info & i)
|
||||
{
|
||||
i.out << request.session->item.id;
|
||||
}
|
||||
|
||||
|
||||
void item_old_subject(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.session->item.subject);
|
||||
}
|
||||
|
||||
|
||||
void item_old_subject_noescape(Info & i)
|
||||
{
|
||||
i.out << request.session->item.subject;
|
||||
}
|
||||
|
||||
|
||||
void item_old_content(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.session->item.content);
|
||||
}
|
||||
|
||||
|
||||
void item_old_content_noescape(Info & i)
|
||||
{
|
||||
i.out << request.session->item.content;
|
||||
}
|
||||
|
||||
|
||||
void item_old_privileges(Info & i)
|
||||
{
|
||||
i.out << std::setbase(8) << request.session->item.privileges << std::setbase(10);
|
||||
}
|
||||
|
||||
|
||||
void item_old_dir(Info & i)
|
||||
{
|
||||
std::string path;
|
||||
|
||||
if( data.dirs.MakePath(request.session->item.parent_id, path) )
|
||||
HtmlEscape(i.out, path);
|
||||
else
|
||||
i.out << "/the path does not exist/";
|
||||
}
|
||||
|
||||
|
||||
void item_old_url(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.session->item.url);
|
||||
}
|
||||
|
||||
|
||||
void item_old_link(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, data.base_url);
|
||||
item_old_dir(i);
|
||||
item_old_url(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t item_index;
|
||||
|
||||
|
||||
void item_tab(Info & i)
|
||||
{
|
||||
item_index = i.iter;
|
||||
i.result = item_index < request.item_table.size();
|
||||
}
|
||||
|
||||
|
||||
void item_tab_id(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
i.out << request.item_table[item_index].id;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_subject(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
HtmlEscape(i.out, request.item_table[item_index].subject);
|
||||
}
|
||||
|
||||
void item_tab_subject_noescape(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
i.out << request.item_table[item_index].subject;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_content(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
HtmlEscape(i.out, request.item_table[item_index].content);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_content_noescape(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
i.out << request.item_table[item_index].content;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_privileges(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
i.out << std::setbase(8) << request.item_table[item_index].privileges << std::setbase(10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_dir(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
{
|
||||
std::string path;
|
||||
|
||||
if( data.dirs.MakePath(request.item_table[item_index].parent_id, path) )
|
||||
HtmlEscape(i.out, path);
|
||||
else
|
||||
i.out << "/the path does not exist/";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_url(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
HtmlEscape(i.out, request.item_table[item_index].url);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_link(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
{
|
||||
HtmlEscape(i.out, data.base_url);
|
||||
item_tab_dir(i);
|
||||
item_tab_url(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
|
218
templates/priv.cpp
Executable file
218
templates/priv.cpp
Executable file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
|
||||
|
||||
static std::vector<long> priv_user_table;
|
||||
static size_t priv_user_index;
|
||||
static size_t priv_user_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_init()
|
||||
{
|
||||
priv_user_reqid = request.id;
|
||||
priv_user_table.clear();
|
||||
|
||||
if( !request.session->puser )
|
||||
{
|
||||
// not logged
|
||||
priv_user_table.push_back(request.item.user_id);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->super_user )
|
||||
{
|
||||
// super user is allowed to change to any user
|
||||
for(size_t i=0 ; i<data.users.Size() ; ++i)
|
||||
priv_user_table.push_back( data.users[i].id );
|
||||
|
||||
// as well to nobody (-1)
|
||||
priv_user_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// others
|
||||
priv_user_table.push_back(request.item.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_user_tab(Info & i)
|
||||
{
|
||||
if( priv_user_reqid != request.id )
|
||||
priv_user_tab_init();
|
||||
|
||||
priv_user_index = i.iter;
|
||||
i.result = priv_user_index < priv_user_table.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_name(Info & i)
|
||||
{
|
||||
if( priv_user_index < priv_user_table.size() )
|
||||
{
|
||||
long uid = priv_user_table[priv_user_index];
|
||||
|
||||
if( uid != -1 )
|
||||
{
|
||||
User * puser = data.users.GetUser( uid );
|
||||
|
||||
if( puser )
|
||||
HtmlEscape(i.out, puser->name);
|
||||
else
|
||||
i.out << "user_id: " << uid;
|
||||
}
|
||||
else
|
||||
{
|
||||
HtmlEscape(i.out, data.priv_no_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_isdefault(Info & i)
|
||||
{
|
||||
if( priv_user_index < priv_user_table.size() )
|
||||
{
|
||||
long uid = priv_user_table[priv_user_index];
|
||||
|
||||
if( uid == request.item.user_id )
|
||||
i.result = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static std::vector<long> priv_group_table;
|
||||
static size_t priv_group_index;
|
||||
static size_t priv_group_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_init()
|
||||
{
|
||||
priv_group_reqid = request.id;
|
||||
priv_group_table.clear();
|
||||
|
||||
if( !request.session->puser )
|
||||
{
|
||||
// not logged
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->super_user )
|
||||
{
|
||||
// super user is allowed to change to any group
|
||||
for(size_t i=0 ; i<data.groups.Size() ; ++i)
|
||||
priv_group_table.push_back( data.groups[i].id );
|
||||
|
||||
// as well to nogroup (-1)
|
||||
priv_group_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->id == request.item.user_id )
|
||||
{
|
||||
bool was_current_group = false;
|
||||
// owner of the item -- is allowed to change only to a group in which he belongs to
|
||||
for(size_t i=0 ; i<request.session->puser->groups.size() ; ++i)
|
||||
{
|
||||
priv_group_table.push_back( request.session->puser->groups[i] );
|
||||
|
||||
if( request.item.group_id == request.session->puser->groups[i] )
|
||||
was_current_group = true;
|
||||
}
|
||||
|
||||
// we're showing the item.group_id if it's different
|
||||
if( !was_current_group )
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
|
||||
// switching to -1 is allowed too
|
||||
priv_group_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not the owner and not a super user -- the same as not logged
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_group_tab(Info & i)
|
||||
{
|
||||
if( priv_group_reqid != request.id )
|
||||
priv_group_tab_init();
|
||||
|
||||
priv_group_index = i.iter;
|
||||
i.result = priv_group_index < priv_group_table.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_name(Info & i)
|
||||
{
|
||||
if( priv_group_index < priv_group_table.size() )
|
||||
{
|
||||
long gid = priv_group_table[priv_group_index];
|
||||
|
||||
if( gid != -1 )
|
||||
{
|
||||
Group * pgroup = data.groups.GetGroup( gid );
|
||||
|
||||
if( pgroup )
|
||||
HtmlEscape(i.out, pgroup->name);
|
||||
else
|
||||
i.out << "group_id: " << gid;
|
||||
}
|
||||
else
|
||||
{
|
||||
HtmlEscape(i.out, data.priv_no_group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_isdefault(Info & i)
|
||||
{
|
||||
if( priv_group_index < priv_group_table.size() )
|
||||
{
|
||||
long gid = priv_group_table[priv_group_index];
|
||||
|
||||
if( gid == request.item.group_id )
|
||||
i.result = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
40
templates/sys.cpp
Executable file
40
templates/sys.cpp
Executable file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
|
||||
|
||||
void sys_ver_major(Info & i)
|
||||
{
|
||||
i.out << MAJOR_VER;
|
||||
}
|
||||
|
||||
|
||||
void sys_ver_minor(Info & i)
|
||||
{
|
||||
i.out << MINOR_VER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void sys_ver_revision(Info & i)
|
||||
{
|
||||
i.out << REVISION_VER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
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();
|
||||
}
|
||||
|
165
templates/templates.h
Executable file
165
templates/templates.h
Executable file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfiletemplates
|
||||
#define headerfiletemplates
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "../../ezc/src/ezc.h"
|
||||
#include "../core/data.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/item.h"
|
||||
#include "../core/db.h"
|
||||
#include "../core/error.h"
|
||||
#include "../core/user.h"
|
||||
#include "../core/group.h"
|
||||
#include "../core/users.h"
|
||||
#include "../core/groups.h"
|
||||
#include "../core/log.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
using Ezc::Info;
|
||||
|
||||
/*
|
||||
sys
|
||||
*/
|
||||
void sys_ver_major(Info & i);
|
||||
void sys_ver_minor(Info & i);
|
||||
void sys_ver_revision(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
doc
|
||||
*/
|
||||
void doc_language(Info & i);
|
||||
void doc_title(Info & i);
|
||||
void doc_charset(Info & i);
|
||||
void doc_base_url(Info & i);
|
||||
void doc_current_url(Info & i);
|
||||
void doc_status_error(Info & i);
|
||||
void doc_status_code(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
item
|
||||
*/
|
||||
void item_is(Info & i);
|
||||
void item_id(Info & i);
|
||||
void item_subject(Info & i);
|
||||
void item_subject_noescape(Info & i);
|
||||
void item_content(Info & i);
|
||||
void item_content_noescape(Info & i);
|
||||
void item_privileges(Info & i);
|
||||
void item_dir(Info & i); // the same as full_dir()
|
||||
void item_url(Info & i);
|
||||
void item_link(Info & i);
|
||||
|
||||
// !! wprowadzic item_old_is ?
|
||||
void item_old_id(Info & i);
|
||||
void item_old_subject(Info & i);
|
||||
void item_old_subject_noescape(Info & i);
|
||||
void item_old_content(Info & i);
|
||||
void item_old_content_noescape(Info & i);
|
||||
void item_old_privileges(Info & i);
|
||||
void item_old_dir(Info & i);
|
||||
void item_old_url(Info & i);
|
||||
void item_old_link(Info & i);
|
||||
|
||||
void item_tab(Info & i);
|
||||
void item_tab_id(Info & i);
|
||||
void item_tab_subject(Info & i);
|
||||
void item_tab_subject_noescape(Info & i);
|
||||
void item_tab_content(Info & i);
|
||||
void item_tab_content_noescape(Info & i);
|
||||
void item_tab_privileges(Info & i);
|
||||
void item_tab_dir(Info & i);
|
||||
void item_tab_url(Info & i);
|
||||
void item_tab_link(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
dir
|
||||
*/
|
||||
void dir(Info & i);
|
||||
|
||||
void dir_childs_tab(Info & i);
|
||||
void dir_childs_tab_url(Info & i);
|
||||
|
||||
void dir_tab(Info & i);
|
||||
void dir_tab_url(Info & i);
|
||||
void dir_tab_link(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
user
|
||||
*/
|
||||
void user_name(Info & i);
|
||||
void user_logged(Info & i);
|
||||
void user_super_user(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
privileges
|
||||
*/
|
||||
void priv_user_tab(Info & i);
|
||||
void priv_user_tab_name(Info & i);
|
||||
void priv_user_tab_isdefault(Info & i);
|
||||
|
||||
void priv_group_tab(Info & i);
|
||||
void priv_group_tab_name(Info & i);
|
||||
void priv_group_tab_isdefault(Info & i);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
done
|
||||
*/
|
||||
void done_errors(Info & i);
|
||||
void done_status(Info & i);
|
||||
void done_status_incorrect_dir(Info & i);
|
||||
|
||||
void done_added_item(Info & i);
|
||||
void done_edited_item(Info & i);
|
||||
void done_deleted_item(Info & i);
|
||||
void done_privileged_item(Info & i);
|
||||
void done_loggedout(Info & i);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
class Templates
|
||||
{
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void Read();
|
||||
void Generate();
|
||||
|
||||
void CreateFunctions();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
49
templates/user.cpp
Executable file
49
templates/user.cpp
Executable file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
|
||||
|
||||
|
||||
void user_logged(Info & i)
|
||||
{
|
||||
i.result = request.session->puser != 0;
|
||||
}
|
||||
|
||||
|
||||
void user_name(Info & i)
|
||||
{
|
||||
if( !request.session->puser )
|
||||
return;
|
||||
|
||||
i.out << request.session->puser->name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void user_super_user(Info & i)
|
||||
{
|
||||
if( request.session->puser && request.session->puser->super_user )
|
||||
i.result = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user