some improvement in templates

(now we have O(1) time for selecting the right html template)
added: winix function: template
for selecting a template for an item (file or dir)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@636 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2010-08-13 20:04:57 +00:00
parent 9a199cd834
commit f3cd3b88b9
40 changed files with 756 additions and 228 deletions

View File

@ -22,10 +22,10 @@ app.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
app.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
app.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
app.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
app.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
app.o: ../functions/uptime.h ../functions/who.h ../templates/templates.h
app.o: ../templates/patterncacher.h ../core/item.h misc.h
app.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
app.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
app.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
app.o: ../templates/templates.h ../templates/patterncacher.h ../core/item.h
app.o: misc.h ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
app.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
app.o: compress.h getparser.h httpsimpleparser.h postparser.h cookieparser.h
app.o: postmultiparser.h acceptencodingparser.h acceptbaseparser.h plugin.h
@ -51,13 +51,13 @@ config.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
config.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
config.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
config.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
config.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
config.o: ../functions/uptime.h ../functions/who.h ../templates/templates.h
config.o: ../templates/patterncacher.h ../core/item.h misc.h
config.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
config.o: ../core/log.h ../templates/indexpatterns.h
config.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
config.o: ../core/sessionmanager.h
config.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
config.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
config.o: ../templates/templates.h ../templates/patterncacher.h
config.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
config.o: ../core/httpsimpleparser.h ../core/log.h
config.o: ../templates/indexpatterns.h ../templates/localefilter.h
config.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
confparser.o: confparser.h misc.h item.h
db.o: db.h item.h user.h group.h thread.h error.h log.h dircontainer.h
db.o: ugcontainer.h ticket.h misc.h
@ -111,13 +111,13 @@ plugin.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
plugin.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
plugin.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
plugin.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
plugin.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
plugin.o: ../functions/uptime.h ../functions/who.h ../templates/templates.h
plugin.o: ../templates/patterncacher.h ../core/item.h misc.h
plugin.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
plugin.o: ../core/log.h ../templates/indexpatterns.h
plugin.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
plugin.o: ../core/sessionmanager.h
plugin.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
plugin.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
plugin.o: ../templates/templates.h ../templates/patterncacher.h
plugin.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
plugin.o: ../core/httpsimpleparser.h ../core/log.h
plugin.o: ../templates/indexpatterns.h ../templates/localefilter.h
plugin.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
plugindata.o: plugindata.h plugin.h pluginmsg.h log.h config.h confparser.h
plugindata.o: htmlfilter.h request.h requesttypes.h session.h item.h error.h
plugindata.o: user.h rebus.h system.h dirs.h dircontainer.h db.h group.h
@ -140,8 +140,9 @@ plugindata.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
plugindata.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
plugindata.o: ../functions/funthread.h ../core/thread.h
plugindata.o: ../functions/funticket.h ../core/ticket.h
plugindata.o: ../functions/tinymce.h ../functions/uname.h
plugindata.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
plugindata.o: ../functions/template.h ../functions/tinymce.h
plugindata.o: ../functions/uname.h ../functions/upload.h
plugindata.o: ../functions/uptime.h ../functions/who.h
plugindata.o: ../templates/templates.h ../templates/patterncacher.h
plugindata.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
plugindata.o: ../core/httpsimpleparser.h ../core/log.h
@ -170,8 +171,9 @@ request.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
request.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
request.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
request.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
request.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
request.o: ../functions/uptime.h ../functions/who.h ../templates/templates.h
request.o: ../functions/template.h ../functions/tinymce.h
request.o: ../functions/uname.h ../functions/upload.h ../functions/uptime.h
request.o: ../functions/who.h ../templates/templates.h
request.o: ../templates/patterncacher.h ../core/item.h misc.h
request.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
request.o: ../core/log.h ../templates/indexpatterns.h
@ -203,14 +205,14 @@ sessionmanager.o: ../functions/node.h ../functions/priv.h
sessionmanager.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
sessionmanager.o: ../functions/subject.h ../functions/funthread.h
sessionmanager.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
sessionmanager.o: ../functions/tinymce.h ../functions/uname.h
sessionmanager.o: ../functions/upload.h ../functions/uptime.h
sessionmanager.o: ../functions/who.h ../templates/templates.h
sessionmanager.o: ../templates/patterncacher.h ../core/item.h misc.h
sessionmanager.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
sessionmanager.o: ../core/log.h ../templates/indexpatterns.h
sessionmanager.o: ../templates/localefilter.h ../core/locale.h
sessionmanager.o: ../core/locale.h ../core/sessionmanager.h
sessionmanager.o: ../functions/template.h ../functions/tinymce.h
sessionmanager.o: ../functions/uname.h ../functions/upload.h
sessionmanager.o: ../functions/uptime.h ../functions/who.h
sessionmanager.o: ../templates/templates.h ../templates/patterncacher.h
sessionmanager.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
sessionmanager.o: ../core/httpsimpleparser.h ../core/log.h
sessionmanager.o: ../templates/indexpatterns.h ../templates/localefilter.h
sessionmanager.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
sessionparser.o: sessionparser.h session.h item.h error.h log.h user.h
sessionparser.o: plugindata.h rebus.h sessioncontainer.h lastcontainer.h
sessionparser.o: users.h ugcontainer.h request.h requesttypes.h config.h

View File

@ -144,7 +144,7 @@ bool App::Init()
if( !notify.Init() )
return false;
// init templates after functions are created
templates.ReadIndexFileNames();
templates.ReadTemplates();
templates.CreateFunctions();

View File

@ -107,6 +107,11 @@ void Config::AssignValues(bool stdout_is_closed)
templates_dir = Text("templates_dir");
templates_dir_default = Text("templates_dir_default");
templates_fun_prefix = Text("templates_fun_prefix", "fun_");
templates_fun_postfix = Text("templates_fun_postfix", ".html");
templates_index = Text("templates_index", "index.html");
template_only_root_use_template_fun = Bool("template_only_root_use_template_fun", false);
http_session_id_name = Text("http_session_id_name");
db_database = Text("db_database");
db_user = Text("db_user");

View File

@ -57,6 +57,21 @@ public:
std::string templates_dir;
std::string templates_dir_default; // templates from winix
// prefix and postfix for functions templates
// default:
// prefix: "fun_"
// postfix: ".html"
std::string templates_fun_prefix;
std::string templates_fun_postfix;
// main html template
// default: index.html
std::string templates_index;
// if true then only root can use 'template' function
// default: false
bool template_only_root_use_template_fun;
std::string db_database;
std::string db_user;
std::string db_pass;

View File

@ -456,7 +456,7 @@ Error Db::AddItemIntoItem(Item & item)
AssertConnection();
std::ostringstream query;
query << "insert into core.item (user_id, modification_user_id, group_id, privileges, date_creation, date_modification, type, "
"parent_id, content_id, auth, auth_path, default_item, subject, guest_name, url) values (";
"parent_id, content_id, auth, auth_path, default_item, subject, guest_name, template, url) values (";
query << '\'' << item.user_id << "', ";
query << '\'' << item.modification_user_id << "', ";
query << '\'' << item.group_id << "', ";
@ -471,6 +471,7 @@ Error Db::AddItemIntoItem(Item & item)
query << '\'' << item.default_item << "', ";
query << '\'' << Escape(item.subject) << "', ";
query << '\'' << Escape(item.guest_name) << "', ";
query << '\'' << Escape(item.html_template) << "', ";
url_without_id = AddItemCreateUrlSubject(item);
@ -564,7 +565,7 @@ Error Db::EditItemInItem(Item & item, bool with_url)
AssertConnection();
std::ostringstream query;
query << "update core.item set (user_id, modification_user_id, group_id, privileges, date_creation, date_modification, type, "
"default_item, parent_id, subject, guest_name, auth, auth_path";
"default_item, parent_id, subject, guest_name, auth, auth_path, template";
if( with_url )
query << ", url";
@ -582,7 +583,8 @@ Error Db::EditItemInItem(Item & item, bool with_url)
query << '\'' << Escape(item.subject) << "', ";
query << '\'' << Escape(item.guest_name) << "', ";
query << '\'' << static_cast<int>(item.auth) << "', ";
query << '\'' << Escape(item.auth_path) << "' ";
query << '\'' << Escape(item.auth_path) << "', ";
query << '\'' << Escape(item.html_template) << "' ";
if( with_url )
{
@ -789,6 +791,42 @@ return result;
}
Error Db::EditTemplateItemById(long id, const std::string & new_html_template)
{
PGresult * r = 0;
Error result = WINIX_ERR_OK;
try
{
AssertConnection();
std::ostringstream query;
query << "update core.item set (template) = ('" << Escape(new_html_template) << "') where id='" << id << "';";
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
char * rows_str = PQcmdTuples(r);
long rows = 0;
if( rows_str )
rows = atol(rows_str);
if( rows == 0 )
{
result = WINIX_ERR_NO_ITEM;
log << log1 << "Db: EditTemplateItemById: no such item, id: " << id << logend;
}
}
catch(const Error & e)
{
result = e;
}
ClearResult(r);
return result;
}
PGresult * Db::GetItemsQuery(const ItemQuery & iq, bool skip_other_sel)
@ -810,6 +848,7 @@ PGresult * Db::GetItemsQuery(const ItemQuery & iq, bool skip_other_sel)
if( iq.sel_type ) query << " ,type";
if( iq.sel_default_item ) query << " ,default_item";
if( iq.sel_auth ) query << " ,auth, auth_path";
if( iq.sel_html_template ) query << " ,template";
}
query << " from core.item";

View File

@ -67,6 +67,7 @@ public:
bool sel_type; // type (dir, file, none)
bool sel_default_item; // default_item
bool sel_auth; // auth, auth_path
bool sel_html_template; // template
bool where_id; //
bool where_parent_id; //
@ -96,6 +97,7 @@ public:
sel_type = sel;
sel_default_item= sel;
sel_auth = sel;
sel_html_template= sel;
}
void SetAllWhere(bool where_)
@ -161,7 +163,8 @@ public:
Error GetItemById(long item_id, Item & item);
Error GetItem(long parent_id, const std::string & url, Item & item);
Error EditDefaultItem(long id, long new_default_item);
Error EditTemplateItemById(long id, const std::string & new_html_template);
long GetItemId(long parent_id, const std::string & url, Item::Type type);
long GetFileId(long parent_id, const std::string & url);
long GetDirId(long parent_id, const std::string & url);
@ -231,7 +234,8 @@ protected:
struct ItemColumns
{
int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id,
content_id, default_item, subject, content, content_type, guest_name, auth, auth_path, modification_user_id;
content_id, default_item, subject, content, content_type, guest_name, auth, auth_path,
modification_user_id, html_template;
void SetColumns(PGresult * r);
void SetItem(PGresult * r, long row, Item & item);

View File

@ -31,6 +31,7 @@ void Db::ItemColumns::SetColumns(PGresult * r)
guest_name = PQfnumber(r, "guest_name");
auth = PQfnumber(r, "auth");
auth_path = PQfnumber(r, "auth_path");
html_template = PQfnumber(r, "template");
modification_user_id = PQfnumber(r, "modification_user_id");
}
@ -55,6 +56,7 @@ void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item)
if( guest_name != -1 ) item.guest_name = Db::AssertValue(r, row, guest_name);
if( auth != -1 ) item.auth = static_cast<Item::Auth>( atoi(Db::AssertValue(r, row, auth)) );
if( auth_path != -1 ) item.auth_path = Db::AssertValue(r, row, auth_path);
if( html_template != -1 ) item.html_template = Db::AssertValue(r, row, html_template);
if( modification_user_id != -1 ) item.modification_user_id = atol( Db::AssertValue(r, row, modification_user_id) );
}

View File

@ -81,6 +81,8 @@ Auth auth;
std::string auth_path; // path to a file (if auth!=auth_none)
std::string html_template;
// methods
Item()
@ -130,6 +132,8 @@ void Clear()
auth = auth_none;
auth_path.clear();
html_template.clear();
SetDateToNow();
}

View File

@ -178,12 +178,12 @@ return false;
const std::string * Mount::HtmlTemplate() const
const std::string * Mount::FirstHtmlTemplate() const
{
if( !param[par_html_template].defined )
return 0;
if( param[par_html_template].arg.size() != 1 )
if( param[par_html_template].arg.empty() )
return 0;
return & param[par_html_template].arg[0];

View File

@ -101,7 +101,7 @@ public:
bool IsArg(Mount::ParamCode code, int arg);
// returning a name to html template (can be null if not defined)
const std::string * HtmlTemplate() const;
const std::string * FirstHtmlTemplate() const;
};

View File

@ -107,7 +107,9 @@ struct Request
// send as attachment (causing header: content-disposition: attachment)
bool send_as_attachment;
// !! moze dolozyc pole Item * last_item
// i ono bedzie wskazywalo na albo item (jesli jest) albo na ostatni katalog
// ?
Request();

View File

@ -70,7 +70,7 @@ ckeditor.o: privchanger.h chown.h cp.h createthread.h createticket.h
ckeditor.o: default.h download.h editticket.h emacs.h last.h login.h logout.h
ckeditor.o: ls.h mkdir.h mv.h node.h priv.h reload.h rm.h run.h subject.h
ckeditor.o: funthread.h ../core/thread.h funticket.h ../core/ticket.h
ckeditor.o: tinymce.h uname.h upload.h uptime.h who.h
ckeditor.o: template.h tinymce.h uname.h upload.h uptime.h who.h
cp.o: cp.h functionbase.h ../core/item.h ../core/db.h ../core/item.h
cp.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
cp.o: ../core/log.h ../core/dircontainer.h ../core/ugcontainer.h
@ -87,8 +87,8 @@ cp.o: ../core/system.h ../core/misc.h functions.h functionparser.h adduser.h
cp.o: cat.h chmod.h privchanger.h chown.h ckeditor.h createthread.h
cp.o: createticket.h default.h download.h editticket.h emacs.h last.h login.h
cp.o: logout.h ls.h mkdir.h mv.h node.h priv.h reload.h rm.h run.h subject.h
cp.o: funthread.h ../core/thread.h funticket.h ../core/ticket.h tinymce.h
cp.o: uname.h upload.h uptime.h who.h
cp.o: funthread.h ../core/thread.h funticket.h ../core/ticket.h template.h
cp.o: tinymce.h uname.h upload.h uptime.h who.h
createthread.o: createthread.h functionbase.h ../core/item.h ../core/db.h
createthread.o: ../core/item.h ../core/user.h ../core/group.h
createthread.o: ../core/thread.h ../core/error.h ../core/log.h
@ -108,7 +108,8 @@ createthread.o: privchanger.h chown.h ckeditor.h cp.h createticket.h
createthread.o: default.h download.h editticket.h emacs.h last.h login.h
createthread.o: logout.h ls.h mkdir.h mv.h node.h priv.h reload.h rm.h run.h
createthread.o: subject.h funthread.h ../core/thread.h funticket.h
createthread.o: ../core/ticket.h tinymce.h uname.h upload.h uptime.h who.h
createthread.o: ../core/ticket.h template.h tinymce.h uname.h upload.h
createthread.o: uptime.h who.h
createticket.o: createticket.h functionbase.h ../core/item.h ../core/db.h
createticket.o: ../core/item.h ../core/user.h ../core/group.h
createticket.o: ../core/thread.h ../core/error.h ../core/log.h
@ -128,7 +129,8 @@ createticket.o: adduser.h cat.h chmod.h privchanger.h chown.h ckeditor.h cp.h
createticket.o: createthread.h default.h download.h editticket.h emacs.h
createticket.o: last.h login.h logout.h ls.h mkdir.h mv.h node.h priv.h
createticket.o: reload.h rm.h run.h subject.h funthread.h ../core/thread.h
createticket.o: funticket.h tinymce.h uname.h upload.h uptime.h who.h
createticket.o: funticket.h template.h tinymce.h uname.h upload.h uptime.h
createticket.o: who.h
default.o: default.h functionbase.h ../core/item.h ../core/db.h
default.o: ../core/item.h ../core/user.h ../core/group.h ../core/thread.h
default.o: ../core/error.h ../core/log.h ../core/dircontainer.h
@ -173,8 +175,8 @@ editticket.o: privchanger.h chown.h ckeditor.h cp.h createthread.h
editticket.o: createticket.h default.h download.h emacs.h last.h login.h
editticket.o: logout.h ls.h mkdir.h mv.h node.h priv.h reload.h rm.h run.h
editticket.o: subject.h funthread.h ../core/thread.h funticket.h
editticket.o: ../core/ticket.h tinymce.h uname.h upload.h uptime.h who.h
editticket.o: readticket.h
editticket.o: ../core/ticket.h template.h tinymce.h uname.h upload.h uptime.h
editticket.o: who.h readticket.h
emacs.o: emacs.h functionbase.h ../core/item.h ../core/db.h ../core/item.h
emacs.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
emacs.o: ../core/log.h ../core/dircontainer.h ../core/ugcontainer.h
@ -196,7 +198,7 @@ emacs.o: cat.h chmod.h privchanger.h chown.h ckeditor.h cp.h createthread.h
emacs.o: createticket.h default.h download.h editticket.h last.h login.h
emacs.o: logout.h ls.h mkdir.h mv.h node.h priv.h reload.h rm.h run.h
emacs.o: subject.h funthread.h ../core/thread.h funticket.h ../core/ticket.h
emacs.o: tinymce.h uname.h upload.h uptime.h who.h
emacs.o: template.h tinymce.h uname.h upload.h uptime.h who.h
functionbase.o: functionbase.h ../core/item.h ../core/db.h ../core/item.h
functionbase.o: ../core/user.h ../core/group.h ../core/thread.h
functionbase.o: ../core/error.h ../core/log.h ../core/dircontainer.h
@ -216,7 +218,8 @@ functionbase.o: chown.h ckeditor.h cp.h createthread.h createticket.h
functionbase.o: default.h download.h editticket.h emacs.h last.h login.h
functionbase.o: logout.h ls.h mkdir.h mv.h node.h priv.h reload.h rm.h run.h
functionbase.o: subject.h funthread.h ../core/thread.h funticket.h
functionbase.o: ../core/ticket.h tinymce.h uname.h upload.h uptime.h who.h
functionbase.o: ../core/ticket.h template.h tinymce.h uname.h upload.h
functionbase.o: uptime.h who.h
functionparser.o: functionparser.h ../core/request.h ../core/requesttypes.h
functionparser.o: ../core/session.h ../core/item.h ../core/error.h
functionparser.o: ../core/log.h ../core/user.h ../core/plugindata.h
@ -237,7 +240,8 @@ functionparser.o: chown.h ckeditor.h cp.h createthread.h createticket.h
functionparser.o: default.h download.h editticket.h emacs.h last.h login.h
functionparser.o: logout.h ls.h mkdir.h mv.h node.h priv.h reload.h rm.h
functionparser.o: run.h subject.h funthread.h ../core/thread.h funticket.h
functionparser.o: ../core/ticket.h tinymce.h uname.h upload.h uptime.h who.h
functionparser.o: ../core/ticket.h template.h tinymce.h uname.h upload.h
functionparser.o: uptime.h who.h
functions.o: functions.h functionbase.h ../core/item.h ../core/db.h
functions.o: ../core/item.h ../core/user.h ../core/group.h ../core/thread.h
functions.o: ../core/error.h ../core/log.h ../core/dircontainer.h
@ -256,8 +260,8 @@ functions.o: ckeditor.h cp.h createthread.h createticket.h default.h
functions.o: download.h editticket.h emacs.h last.h login.h logout.h ls.h
functions.o: mkdir.h mv.h node.h priv.h reload.h rm.h run.h subject.h
functions.o: funthread.h ../core/thread.h funticket.h ../core/ticket.h
functions.o: tinymce.h uname.h upload.h uptime.h who.h ../core/log.h
functions.o: ../core/misc.h ../templates/templates.h
functions.o: template.h tinymce.h uname.h upload.h uptime.h who.h
functions.o: ../core/log.h ../core/misc.h ../templates/templates.h
functions.o: ../templates/patterncacher.h ../core/item.h ../templates/misc.h
functions.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
functions.o: ../core/log.h ../templates/indexpatterns.h
@ -359,7 +363,7 @@ mkdir.o: chmod.h privchanger.h chown.h ckeditor.h cp.h createthread.h
mkdir.o: createticket.h default.h download.h editticket.h emacs.h last.h
mkdir.o: login.h logout.h ls.h mv.h node.h priv.h reload.h rm.h run.h
mkdir.o: subject.h funthread.h ../core/thread.h funticket.h ../core/ticket.h
mkdir.o: tinymce.h uname.h upload.h uptime.h who.h
mkdir.o: template.h tinymce.h uname.h upload.h uptime.h who.h
mv.o: mv.h functionbase.h ../core/item.h ../core/db.h ../core/item.h
mv.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
mv.o: ../core/log.h ../core/dircontainer.h ../core/ugcontainer.h
@ -376,8 +380,8 @@ mv.o: ../core/system.h functions.h functionparser.h adduser.h cat.h chmod.h
mv.o: privchanger.h chown.h ckeditor.h cp.h createthread.h createticket.h
mv.o: default.h download.h editticket.h emacs.h last.h login.h logout.h ls.h
mv.o: mkdir.h node.h priv.h reload.h rm.h run.h subject.h funthread.h
mv.o: ../core/thread.h funticket.h ../core/ticket.h tinymce.h uname.h
mv.o: upload.h uptime.h who.h
mv.o: ../core/thread.h funticket.h ../core/ticket.h template.h tinymce.h
mv.o: uname.h upload.h uptime.h who.h
node.o: node.h functionbase.h ../core/item.h ../core/db.h ../core/item.h
node.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
node.o: ../core/log.h ../core/dircontainer.h ../core/ugcontainer.h
@ -458,8 +462,8 @@ rm.o: ../functions/functions.h functionparser.h adduser.h cat.h chmod.h
rm.o: privchanger.h chown.h ckeditor.h cp.h createthread.h createticket.h
rm.o: default.h download.h editticket.h emacs.h last.h login.h logout.h ls.h
rm.o: mkdir.h mv.h node.h priv.h reload.h run.h subject.h funthread.h
rm.o: ../core/thread.h funticket.h ../core/ticket.h tinymce.h uname.h
rm.o: upload.h uptime.h who.h ../templates/templates.h
rm.o: ../core/thread.h funticket.h ../core/ticket.h template.h tinymce.h
rm.o: uname.h upload.h uptime.h who.h ../templates/templates.h
rm.o: ../templates/patterncacher.h ../core/item.h ../templates/misc.h
rm.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
rm.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
@ -489,6 +493,20 @@ subject.o: ../core/groups.h ../core/loadavg.h ../core/notify.h
subject.o: ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
subject.o: ../core/mount.h ../core/locale.h ../templates/misc.h
subject.o: ../templates/localefilter.h ../core/locale.h ../core/system.h
template.o: template.h functionbase.h ../core/item.h ../core/db.h
template.o: ../core/item.h ../core/user.h ../core/group.h ../core/thread.h
template.o: ../core/error.h ../core/log.h ../core/dircontainer.h
template.o: ../core/ugcontainer.h ../core/ticket.h ../core/request.h
template.o: ../core/requesttypes.h ../core/session.h ../core/plugindata.h
template.o: ../core/rebus.h ../core/config.h ../core/confparser.h
template.o: ../core/htmlfilter.h ../core/config.h ../core/system.h
template.o: ../core/dirs.h ../core/db.h ../core/request.h ../core/mounts.h
template.o: ../core/mount.h ../core/users.h ../core/lastcontainer.h
template.o: ../core/groups.h ../core/loadavg.h ../core/notify.h
template.o: ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
template.o: ../core/mount.h ../core/locale.h ../templates/misc.h
template.o: ../templates/localefilter.h ../core/locale.h ../core/system.h
template.o: ../core/misc.h
tinymce.o: tinymce.h functionbase.h ../core/item.h ../core/db.h
tinymce.o: ../core/item.h ../core/user.h ../core/group.h ../core/thread.h
tinymce.o: ../core/error.h ../core/log.h ../core/dircontainer.h
@ -506,8 +524,8 @@ tinymce.o: functions.h functionparser.h adduser.h cat.h chmod.h privchanger.h
tinymce.o: chown.h ckeditor.h cp.h createthread.h createticket.h default.h
tinymce.o: download.h editticket.h emacs.h last.h login.h logout.h ls.h
tinymce.o: mkdir.h mv.h node.h priv.h reload.h rm.h run.h subject.h
tinymce.o: funthread.h ../core/thread.h funticket.h ../core/ticket.h uname.h
tinymce.o: upload.h uptime.h who.h
tinymce.o: funthread.h ../core/thread.h funticket.h ../core/ticket.h
tinymce.o: template.h uname.h upload.h uptime.h who.h
uname.o: uname.h functionbase.h ../core/item.h ../core/db.h ../core/item.h
uname.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
uname.o: ../core/log.h ../core/dircontainer.h ../core/ugcontainer.h
@ -538,8 +556,8 @@ upload.o: functionparser.h adduser.h cat.h chmod.h privchanger.h chown.h
upload.o: ckeditor.h cp.h createthread.h createticket.h default.h download.h
upload.o: editticket.h emacs.h last.h login.h logout.h ls.h mkdir.h mv.h
upload.o: node.h priv.h reload.h rm.h run.h subject.h funthread.h
upload.o: ../core/thread.h funticket.h ../core/ticket.h tinymce.h uname.h
upload.o: uptime.h who.h
upload.o: ../core/thread.h funticket.h ../core/ticket.h template.h tinymce.h
upload.o: uname.h uptime.h who.h
uptime.o: uptime.h functionbase.h ../core/item.h ../core/db.h ../core/item.h
uptime.o: ../core/user.h ../core/group.h ../core/thread.h ../core/error.h
uptime.o: ../core/log.h ../core/dircontainer.h ../core/ugcontainer.h

View File

@ -1 +1 @@
o = adduser.o cat.o chmod.o chown.o ckeditor.o cp.o createthread.o createticket.o default.o download.o editticket.o emacs.o functionbase.o functionparser.o functions.o funthread.o funticket.o last.o login.o logout.o ls.o mkdir.o mv.o node.o priv.o privchanger.o readticket.o reload.o rm.o run.o subject.o tinymce.o uname.o upload.o uptime.o who.o
o = adduser.o cat.o chmod.o chown.o ckeditor.o cp.o createthread.o createticket.o default.o download.o editticket.o emacs.o functionbase.o functionparser.o functions.o funthread.o funticket.o last.o login.o logout.o ls.o mkdir.o mv.o node.o priv.o privchanger.o readticket.o reload.o rm.o run.o subject.o template.o tinymce.o uname.o upload.o uptime.o who.o

View File

@ -14,6 +14,8 @@
FunctionBase::FunctionBase()
{
id = -1;
fun.user_id = -1;
fun.group_id = -1;
fun.privileges = 0755;

View File

@ -30,6 +30,11 @@ class FunctionBase
{
public:
// function id
// it is set automatically when you add the function to functions list
// is used to load a template (in templates)
long id;
FunctionBase();
// user, group, permissions, url (function name)

View File

@ -37,16 +37,37 @@ void Functions::SetSystem(System * psystem)
system = psystem;
}
void Functions::SetTemplates(Templates * ptemplates)
{
templates = ptemplates;
}
void Functions::SetNotify(Notify * pnotify)
{
notify = pnotify;
}
size_t Functions::FunctionsSize()
{
return table.size();
}
Functions::Iterator Functions::Begin()
{
return table.begin();
}
Functions::Iterator Functions::End()
{
return table.end();
}
FunctionBase * Functions::Find(const std::string & function_name)
{
Table::iterator i = table.find(function_name);
@ -129,8 +150,9 @@ void Functions::Add(FunctionBase * fun)
return;
}
table[fun->fun.url] = fun;
fun->id = table.size();
SetObjects(fun);
table[fun->fun.url] = fun;
}
@ -145,6 +167,8 @@ void Functions::Add(FunctionBase & fun)
void Functions::Create()
{
Add(fun_template);
Add(fun_adduser);
Add(fun_cat);
Add(fun_chmod);
@ -281,7 +305,7 @@ void Functions::MakeGet()
return;
}
if( !request->function->HasAccess() )
if( !system->HasReadExecAccess(request->function->fun) || !request->function->HasAccess() )
{
request->status = WINIX_ERR_PERMISSION_DENIED;
return;
@ -310,7 +334,7 @@ void Functions::MakePost()
return;
}
if( !request->function->HasAccess() )
if( !system->HasReadExecAccess(request->function->fun) || !request->function->HasAccess() )
{
request->status = WINIX_ERR_PERMISSION_DENIED;
return;

View File

@ -39,6 +39,7 @@
#include "subject.h"
#include "funthread.h"
#include "funticket.h"
#include "template.h"
#include "tinymce.h"
#include "uname.h"
#include "upload.h"
@ -80,16 +81,22 @@ public:
Fun::Subject fun_subject;
Fun::FunThread fun_thread;
Fun::FunTicket fun_ticket;
Fun::Template fun_template;
Fun::Tinymce fun_tinymce;
Fun::Uname fun_uname;
Fun::Upload fun_upload;
Fun::Uptime fun_uptime;
Fun::Who fun_who;
typedef std::map<std::string, FunctionBase*> Table;
typedef Table::iterator Iterator;
void Create();
void Parse();
size_t FunctionsSize();
Iterator Begin();
Iterator End();
void MakeGet();
void MakePost();
@ -133,7 +140,6 @@ private:
bool ReadItemUrlSubject(Item & item, Item::Type item_type);
typedef std::map<std::string, FunctionBase*> Table;
Table table;
FunctionParser function_parser;

70
functions/template.cpp Executable file
View File

@ -0,0 +1,70 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "template.h"
#include "core/misc.h"
namespace Fun
{
Template::Template()
{
fun.url = "template";
}
bool Template::HasAccess()
{
if( config->template_only_root_use_template_fun )
{
// only root is allowed to change the template
return (request->session->puser && request->session->puser->super_user);
}
if( request->is_item )
return system->HasWriteAccess(request->item);
else
return system->HasWriteAccess(*request->dir_tab.back());
}
void Template::EditTemplate(Item & item)
{
html_file = request->PostVar("template");
TrimWhite(html_file);
request->status = db->EditTemplateItemById(item.id, html_file);
if( request->status == WINIX_ERR_OK )
item.html_template = html_file;
}
void Template::MakePost()
{
if( request->is_item )
{
EditTemplate(request->item);
}
else
{
EditTemplate(*request->dir_tab.back());
}
system->RedirectToLastItem();
}
} // namespace

38
functions/template.h Executable file
View File

@ -0,0 +1,38 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucontenttemplate
#define headerfilecmslucontenttemplate
#include "functionbase.h"
namespace Fun
{
class Template : public FunctionBase
{
public:
Template();
bool HasAccess();
void MakePost();
private:
std::string html_file;
void EditTemplate(Item & item);
};
} // namespace
#endif

View File

@ -1,5 +1,5 @@
[if mount_page_is "subject"][if mount_page_is "info"]<h1 class="withinfo">[else]<h1>[end][item_subject]</h1>[end]
[if mount_page_is "info"][item_info][end]
[if mount_page_is "info"][include "item_info.html"][end]
[if-one item_auth_is_image]
<img class="catimage" src="[item_link]/download/thumb" alt="[item_subject]">
@ -14,6 +14,7 @@
[end]
[include "item_options.html"]

View File

@ -0,0 +1,2 @@
[include "fun_priv.html"]

View File

@ -0,0 +1 @@
[include "fun_priv.html"]

View File

@ -12,7 +12,7 @@
[end]
[if mount_page_is "info"]
[item_info]
[include "item_info.html"]
[end]
[item_run]

65
html/fun_template.html Executable file
View File

@ -0,0 +1,65 @@
<h1>{template_header}</h1>
[include "error.html"]
<p>
[if item_is]
{template_info_file}:
[if item_has_html_template]
[item_html_template]
[else]
{template_from_mount_point}
[if mount_has_html_template]
([mount_first_html_template])
[else]
([template_index])
[end]
[end]
[else]
{template_info_dir}:
[if dir_last_has_html_template]
[dir_last_html_template]
[else]
{template_from_mount_point}
[if mount_has_html_template]
([mount_first_html_template])
[else]
([template_index])
[end]
[end]
[end]
</p>
<form id="additem" method="post" action="[doc_base_url][dir][if-one item_is][item_url]/[end]template">
<fieldset>
<legend>{template_form_legend}</legend>
{template_form_info}:
<select name="template" class="template">
[# the first should be an empty string (value="") which means: a first template from the mount point]
<option value="">({template_form_from_mount_point})</option>
[for template_tab]
<option[if-one template_tab_isdefault] selected[end]>[template_tab_file_name]</option>
[end]
</select>
<input class="submit" type="submit" value="{change}">
</fieldset>
</form>

View File

@ -1,5 +1,5 @@
[if mount_page_is "subject"]<h1[if mount_page_is "info"] class="withinfo"[end]>[dir_last_subject]</h1>[end]
[if mount_page_is "info"][dir_last_info][end]
[if mount_page_is "info"][include "dir_last_info.html"][end]
[if-one thread_can_create]
<ul class="itemmenu">
@ -34,7 +34,7 @@
<div class="threadbox[if-index item_tab odd] threadboxcolor[end]">
[if-one item_tab_can_use_emacs]<a class="threadedit" href="[item_tab_link]/emacs">\[{edit}\]</a>[end]
[if mount_thread_is "subject"]<h2[if mount_thread_is "info"] class="withinfo"[end]>[item_tab_subject]</h2>[end]
[if mount_thread_is "info"][item_tab_info][end]
[if mount_thread_is "info"][include "item_tab_info.html"][end]
[item_tab_print_content]
</div>
[end]

View File

@ -1,5 +1,5 @@
[if mount_page_is "subject"]<h1[if mount_page_is "info"] class="withinfo"[end]>[dir_last_subject]</h1>[end]
[if mount_page_is "info"][dir_last_info][end]
[if mount_page_is "info"][include "dir_last_info.html"][end]
[if-one ticket_can_create]
@ -56,7 +56,7 @@
[for item_tab]
<div class="threadbox[if-index item_tab odd] threadboxcolor[end]">
[if mount_thread_is "subject"]<h2[if mount_thread_is "info"] class="withinfo"[end]>[item_tab_subject]</h2>[end]
[if mount_thread_is "info"][item_tab_info][end]
[if mount_thread_is "info"][include "item_tab_info.html"][end]
[item_tab_print_content]
</div>
[end]

View File

@ -149,6 +149,14 @@ ticket_info_expected = Expected in
ticket_info_progress = Progress
ticket_reply_in_this_thread = Replay in this thread
template_header = Template
template_info_file = Current html template for this file
template_info_dir = Current html template for this directory
template_from_mount_point = is taken from the mount point
template_form_legend = Template form
template_form_info = Select a new template
template_form_from_mount_point = from the mount point
upload_header = Upload a file
upload_form_file = Browse for a file
upload_form_file_multi = Browse for files

View File

@ -152,6 +152,15 @@ ticket_info_expected = Oczekiwany w
ticket_info_progress = Postêp prac
ticket_reply_in_this_thread = Odpowiedz w tym w±tku
template_header = Szablon
template_info_file = Bie¿±cy szablon dla tego pliku
template_info_dir = Bie¿±cy szablon dla tego katalogu
template_from_mount_point = jest brany z punktu montowania
template_form_legend = Formularz zmiany szablonu
template_form_info = Wybierz nowy szablon
template_form_from_mount_point = z punktu montowania
upload_header = Prze¶lij plik
upload_form_file = Wybierz plik
upload_form_file_multi = Wybierz pliki

View File

@ -25,12 +25,13 @@ main.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
main.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
main.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
main.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
main.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
main.o: ../functions/uptime.h ../functions/who.h ../templates/templates.h
main.o: ../templates/patterncacher.h ../core/item.h ../templates/misc.h
main.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
main.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
main.o: ../core/compress.h ../core/getparser.h ../core/httpsimpleparser.h
main.o: ../core/postparser.h ../core/cookieparser.h ../core/postmultiparser.h
main.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
main.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
main.o: ../templates/templates.h ../templates/patterncacher.h ../core/item.h
main.o: ../templates/misc.h ../templates/ckeditorgetparser.h
main.o: ../core/httpsimpleparser.h ../core/log.h ../templates/indexpatterns.h
main.o: ../core/sessionmanager.h ../core/compress.h ../core/getparser.h
main.o: ../core/httpsimpleparser.h ../core/postparser.h
main.o: ../core/cookieparser.h ../core/postmultiparser.h
main.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
main.o: ../core/plugin.h ../core/pluginmsg.h

View File

@ -32,14 +32,14 @@ init.o: ../../functions/priv.h ../../functions/reload.h ../../functions/rm.h
init.o: ../../functions/run.h ../../functions/subject.h
init.o: ../../functions/funthread.h ../../core/thread.h
init.o: ../../functions/funticket.h ../../core/ticket.h
init.o: ../../functions/tinymce.h ../../functions/uname.h
init.o: ../../functions/upload.h ../../functions/uptime.h
init.o: ../../functions/who.h ../../templates/templates.h
init.o: ../../templates/patterncacher.h ../../core/item.h
init.o: ../../templates/misc.h ../../templates/ckeditorgetparser.h
init.o: ../../core/httpsimpleparser.h ../../core/log.h
init.o: ../../templates/indexpatterns.h ../../core/sessionmanager.h
init.o: statssession.h ../../core/plugindata.h
init.o: ../../functions/template.h ../../functions/tinymce.h
init.o: ../../functions/uname.h ../../functions/upload.h
init.o: ../../functions/uptime.h ../../functions/who.h
init.o: ../../templates/templates.h ../../templates/patterncacher.h
init.o: ../../core/item.h ../../templates/misc.h
init.o: ../../templates/ckeditorgetparser.h ../../core/httpsimpleparser.h
init.o: ../../core/log.h ../../templates/indexpatterns.h
init.o: ../../core/sessionmanager.h statssession.h ../../core/plugindata.h
stats.o: stats.h ../../core/config.h ../../core/log.h
templates.o: templates.h ../../core/plugin.h ../../core/pluginmsg.h
templates.o: ../../core/log.h ../../core/plugindata.h ../../core/config.h
@ -74,11 +74,12 @@ templates.o: ../../functions/reload.h ../../functions/rm.h
templates.o: ../../functions/run.h ../../functions/subject.h
templates.o: ../../functions/funthread.h ../../core/thread.h
templates.o: ../../functions/funticket.h ../../core/ticket.h
templates.o: ../../functions/tinymce.h ../../functions/uname.h
templates.o: ../../functions/upload.h ../../functions/uptime.h
templates.o: ../../functions/who.h ../../templates/templates.h
templates.o: ../../templates/patterncacher.h ../../core/item.h
templates.o: ../../templates/misc.h ../../templates/ckeditorgetparser.h
templates.o: ../../functions/template.h ../../functions/tinymce.h
templates.o: ../../functions/uname.h ../../functions/upload.h
templates.o: ../../functions/uptime.h ../../functions/who.h
templates.o: ../../templates/templates.h ../../templates/patterncacher.h
templates.o: ../../core/item.h ../../templates/misc.h
templates.o: ../../templates/ckeditorgetparser.h
templates.o: ../../core/httpsimpleparser.h ../../core/log.h
templates.o: ../../templates/indexpatterns.h ../../core/sessionmanager.h
templates.o: ../../core/misc.h stats.h

View File

@ -455,9 +455,12 @@ margin: 0.3em 0 0.3em 0;
#additem select.contenttype {
border: 1px solid #dedede;
width: 150px;
margin: 0.3em 0 0.3em 0;
}
#additem select.template {
width: 200px;
}

View File

@ -40,8 +40,9 @@ dir.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
dir.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
dir.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
dir.o: ../functions/funthread.h ../core/thread.h ../functions/funticket.h
dir.o: ../core/ticket.h ../functions/tinymce.h ../functions/uname.h
dir.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
dir.o: ../core/ticket.h ../functions/template.h ../functions/tinymce.h
dir.o: ../functions/uname.h ../functions/upload.h ../functions/uptime.h
dir.o: ../functions/who.h
doc.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h misc.h
doc.o: localefilter.h ../core/locale.h ../core/confparser.h
doc.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
@ -127,7 +128,7 @@ mount.o: ../core/ugcontainer.h ../core/ticket.h ../core/system.h
mount.o: ../core/dirs.h ../core/db.h ../core/request.h ../core/mounts.h
mount.o: ../core/mount.h ../core/users.h ../core/lastcontainer.h
mount.o: ../core/groups.h ../core/loadavg.h ../core/sessionmanager.h
mount.o: ../core/sessioncontainer.h ../core/system.h
mount.o: ../core/sessioncontainer.h ../core/system.h ../core/misc.h
patterncacher.o: patterncacher.h ../core/item.h ../../ezc/src/ezc.h
patterncacher.o: ../core/log.h
priv.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h misc.h
@ -156,9 +157,9 @@ priv.o: ../functions/logout.h ../functions/ls.h ../functions/mkdir.h
priv.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
priv.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
priv.o: ../functions/subject.h ../functions/funthread.h ../core/thread.h
priv.o: ../functions/funticket.h ../core/ticket.h ../functions/tinymce.h
priv.o: ../functions/uname.h ../functions/upload.h ../functions/uptime.h
priv.o: ../functions/who.h
priv.o: ../functions/funticket.h ../core/ticket.h ../functions/template.h
priv.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
priv.o: ../functions/uptime.h ../functions/who.h
rebus.o: ../core/request.h templates.h ../../ezc/src/ezc.h patterncacher.h
rebus.o: ../core/item.h misc.h localefilter.h ../core/locale.h
rebus.o: ../core/confparser.h ckeditorgetparser.h ../core/httpsimpleparser.h
@ -185,6 +186,20 @@ sys.o: ../core/db.h ../core/request.h ../core/mounts.h ../core/mount.h
sys.o: ../core/users.h ../core/lastcontainer.h ../core/groups.h
sys.o: ../core/loadavg.h ../core/sessionmanager.h ../core/sessioncontainer.h
sys.o: ../core/system.h ../core/request.h ../core/version.h
template.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
template.o: misc.h localefilter.h ../core/locale.h ../core/confparser.h
template.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
template.o: indexpatterns.h ../core/locale.h ../core/config.h
template.o: ../core/htmlfilter.h ../core/request.h ../core/requesttypes.h
template.o: ../core/session.h ../core/item.h ../core/error.h ../core/log.h
template.o: ../core/user.h ../core/plugindata.h ../core/rebus.h
template.o: ../core/config.h ../core/db.h ../core/group.h ../core/thread.h
template.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
template.o: ../core/system.h ../core/dirs.h ../core/db.h ../core/request.h
template.o: ../core/mounts.h ../core/mount.h ../core/users.h
template.o: ../core/lastcontainer.h ../core/groups.h ../core/loadavg.h
template.o: ../core/sessionmanager.h ../core/sessioncontainer.h
template.o: ../core/system.h ../core/misc.h
templates.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
templates.o: misc.h localefilter.h ../core/locale.h ../core/confparser.h
templates.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
@ -215,7 +230,8 @@ templates.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
templates.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
templates.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
templates.o: ../functions/funthread.h ../core/thread.h
templates.o: ../functions/funticket.h ../core/ticket.h ../functions/tinymce.h
templates.o: ../functions/funticket.h ../core/ticket.h
templates.o: ../functions/template.h ../functions/tinymce.h
templates.o: ../functions/uname.h ../functions/upload.h ../functions/uptime.h
templates.o: ../functions/who.h ../templates/templates.h
thread.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
@ -246,8 +262,8 @@ thread.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
thread.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
thread.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
thread.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
thread.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
thread.o: ../functions/uptime.h ../functions/who.h
thread.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
thread.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
ticket.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
ticket.o: misc.h localefilter.h ../core/locale.h ../core/confparser.h
ticket.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
@ -276,8 +292,8 @@ ticket.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
ticket.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
ticket.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
ticket.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
ticket.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
ticket.o: ../functions/uptime.h ../functions/who.h
ticket.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
ticket.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
upload.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
upload.o: misc.h localefilter.h ../core/locale.h ../core/confparser.h
upload.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
@ -360,5 +376,5 @@ winix.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
winix.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
winix.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
winix.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
winix.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
winix.o: ../functions/uptime.h ../functions/who.h
winix.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
winix.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h

View File

@ -1 +1 @@
o = adduser.o dir.o doc.o indexpatterns.o item.o last.o localefilter.o ls.o misc.o mount.o patterncacher.o priv.o rebus.o sys.o templates.o thread.o ticket.o upload.o uptime.o user.o who.o winix.o
o = adduser.o dir.o doc.o indexpatterns.o item.o last.o localefilter.o ls.o misc.o mount.o patterncacher.o priv.o rebus.o sys.o template.o templates.o thread.o ticket.o upload.o uptime.o user.o who.o winix.o

View File

@ -317,7 +317,7 @@ void dir_last_subject(Info & i)
HtmlEscape(i.out, request->dir_tab.back()->subject);
}
/*
void dir_last_info(Info & i)
{
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
@ -326,7 +326,7 @@ void dir_last_info(Info & i)
Ezc::Generator gen(i.out, patterns[locale.GetLang()][pat_dir_last_info], ezc_functions);
gen.Generate();
}
*/
void dir_last_user(Info & i)
{
@ -388,6 +388,18 @@ void dir_last_dates_equal(Info & i)
}
void dir_last_html_template(Info & i)
{
HtmlEscape(i.out, request->dir_tab.back()->html_template);
}
void dir_last_has_html_template(Info & i)
{
i.res = !request->dir_tab.back()->html_template.empty();
}

View File

@ -218,7 +218,7 @@ void item_can_remove(Info & i)
i.res = system->HasWriteAccess(*request->dir_tab.back());
}
/*
void item_info(Info & i)
{
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
@ -227,7 +227,7 @@ void item_info(Info & i)
Ezc::Generator gen(i.out, patterns[locale.GetLang()][pat_item_info], ezc_functions);
gen.Generate();
}
*/
void item_user(Info & i)
{
@ -325,6 +325,18 @@ void item_guest_name(Info & i)
}
void item_html_template(Info & i)
{
HtmlEscape(i.out, request->item.html_template);
}
void item_has_html_template(Info & i)
{
i.res = !request->item.html_template.empty();
}
@ -456,7 +468,7 @@ void item_tab_can_write(Info & i)
}
}
/*
void item_tab_info(Info & i)
{
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
@ -465,7 +477,7 @@ void item_tab_info(Info & i)
Ezc::Generator gen(i.out, patterns[locale.GetLang()][pat_item_tab_info], ezc_functions);
gen.Generate();
}
*/
void item_tab_user(Info & i)
{

View File

@ -8,7 +8,7 @@
*/
#include "templates.h"
#include "core/misc.h"
@ -47,8 +47,20 @@ void mount_type_is_cms(Info & i)
i.res = system->mounts.pmount->type == Mount::cms;
}
void mount_has_html_template(Info & i)
{
i.res = system->mounts.pmount->param[Mount::par_html_template].defined;
}
void mount_first_html_template(Info & i)
{
Mount::ParamRow & par = system->mounts.pmount->param[Mount::par_html_template];
if( par.defined && !par.arg.empty() )
HtmlEscape(i.out, par.arg[0]);
}
} // namespace TemplatesFunctions

113
templates/template.cpp Executable file
View File

@ -0,0 +1,113 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <vector>
#include <string>
#include "templates.h"
#include "core/misc.h"
namespace TemplatesFunctions
{
void template_index(Info & i)
{
HtmlEscape(i.out, config->templates_index);
}
static std::vector<std::string> temp_tab;
static size_t temp_req_id = 0;
static size_t temp_def;
static size_t temp_index;
void template_set_def()
{
temp_def = (size_t)-1; // none
const std::string * html_file;
if( request->is_item )
html_file = &request->item.html_template;
else
html_file = &request->dir_tab.back()->html_template;
if( html_file->empty() )
{
// the first default item should be selected (that first in html source with value="")
return;
}
for(size_t i=0 ; i<temp_tab.size() ; ++i)
{
if( temp_tab[i] == *html_file )
{
temp_def = i;
break;
}
}
}
void template_init()
{
// the first item in the html template is an empty string
// added in the html template
temp_tab.clear();
temp_tab.push_back(config->templates_index);
Mount::ParamRow & par = system->mounts.pmount->param[Mount::par_html_template];
if( par.defined )
{
size_t len = par.arg.size();
for(size_t i=0 ; i<len ; ++i)
temp_tab.push_back(par.arg[i]);
}
template_set_def();
}
void template_tab(Info & i)
{
if( request->id != temp_req_id )
{
temp_req_id = request->id;
template_init();
}
temp_index = i.iter;
i.res = temp_index < temp_tab.size();
}
void template_tab_isdefault(Info & i)
{
if( temp_index < temp_tab.size() )
i.res = (temp_index == temp_def);
}
void template_tab_file_name(Info & i)
{
if( temp_index < temp_tab.size() )
HtmlEscape(i.out, temp_tab[temp_index]);
}
} // namespace

View File

@ -20,6 +20,7 @@ namespace TemplatesFunctions
IndexPatterns index_patterns;
Patterns patterns;
Patterns patterns_fun;
Ezc::Functions ezc_functions;
PatternCacher pattern_cacher;
Locale locale;
@ -41,58 +42,22 @@ SessionManager * session_manager;
Ezc::Pattern * content_for_function()
{
Ezc::Pattern * p = 0;
if( !request->function )
{
log << log1 << "Templates: no function" << logend;
return p;
return 0;
}
static PatName pat_name_tab[] = {
{"cat", pat_fun_cat},
{"ls", pat_fun_ls},
{"rm", pat_fun_rm},
{"emacs", pat_fun_emacs},
{"mkdir", pat_fun_mkdir},
{"default", pat_fun_default},
{"priv", pat_fun_priv},
{"chmod", pat_fun_priv},
{"chown", pat_fun_priv},
{"run", pat_fun_run},
{"who", pat_fun_who},
{"last", pat_fun_last},
{"thread", pat_fun_thread},
{"reload", pat_fun_reload},
{"createthread",pat_fun_createthread},
{"ticket", pat_fun_ticket},
{"createticket",pat_fun_createticket},
{"editticket", pat_fun_createticket},
{"upload", pat_fun_upload},
{"uptime", pat_fun_uptime},
{"login", pat_fun_login},
{"mv", pat_fun_mv},
{"uname", pat_fun_uname},
{"ckeditor", pat_fun_ckeditor},
{"subject", pat_fun_subject},
{"adduser", pat_fun_adduser},
{"cp", pat_fun_cp},
{"tinymce", pat_fun_tinymce},
};
const size_t loc_index = static_cast<size_t>(locale.GetLang());
const size_t fun_id = static_cast<size_t>(request->function->id);
size_t i, len = sizeof(pat_name_tab)/sizeof(PatName);
for(i=0 ; i<len ; ++i)
if( loc_index >= patterns_fun.size() || fun_id >= patterns_fun[loc_index].size() )
{
if( strcmp(pat_name_tab[i].fun_name, request->function->fun.url.c_str()) == 0 )
{
// !! locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
p = &patterns[locale.GetLang()][pat_name_tab[i].pat];
break;
}
log << log1 << "Templates: incorrect function index" << logend;
return 0;
}
return p;
return &patterns_fun[loc_index][fun_id];
}
@ -152,12 +117,9 @@ Ezc::Pattern * p = 0;
{
i.out << "<!-- there are not any patterns -->";
}
}
} // namespace TemplatesFunctions
@ -219,7 +181,7 @@ void Templates::CreateFunctions()
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_info", item_info);
//ezc_functions.Insert("item_info", item_info);
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);
@ -230,6 +192,9 @@ void Templates::CreateFunctions()
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_tab", item_tab);
ezc_functions.Insert("item_tab_id", item_tab_id);
@ -245,7 +210,7 @@ void Templates::CreateFunctions()
ezc_functions.Insert("item_tab_link_auth", item_tab_link_auth);
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_info", item_tab_info);
//ezc_functions.Insert("item_tab_info", item_tab_info);
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);
@ -285,13 +250,15 @@ void Templates::CreateFunctions()
ezc_functions.Insert("dir_last_default_item_dir", dir_last_default_item_dir);
ezc_functions.Insert("dir_last_default_item_url", dir_last_default_item_url);
ezc_functions.Insert("dir_last_subject", dir_last_subject);
ezc_functions.Insert("dir_last_info", dir_last_info);
//ezc_functions.Insert("dir_last_info", dir_last_info);
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_dates_equal", dir_last_dates_equal);
ezc_functions.Insert("dir_last_html_template", dir_last_html_template);
ezc_functions.Insert("dir_last_has_html_template", dir_last_has_html_template);
@ -441,6 +408,8 @@ void Templates::CreateFunctions()
ezc_functions.Insert("mount_type_is_thread", mount_type_is_thread);
ezc_functions.Insert("mount_type_is_ticket", mount_type_is_ticket);
ezc_functions.Insert("mount_type_is_cms", mount_type_is_cms);
ezc_functions.Insert("mount_has_html_template", mount_has_html_template);
ezc_functions.Insert("mount_first_html_template", mount_first_html_template);
/*
@ -485,6 +454,16 @@ void Templates::CreateFunctions()
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);
/*
template
*/
ezc_functions.Insert("template_index", template_index);
ezc_functions.Insert("template_tab", template_tab);
ezc_functions.Insert("template_tab_isdefault", template_tab_isdefault);
ezc_functions.Insert("template_tab_file_name", template_tab_file_name);
plugin.Call(WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions);
}
@ -499,7 +478,15 @@ using namespace TemplatesFunctions;
}
void Templates::ReadTemplates()
void Templates::ReadFileFun(size_t index, const char * file)
{
using namespace TemplatesFunctions;
Read(patterns_fun, index, locale, locale_filter, file);
}
void Templates::SetLocale()
{
using namespace TemplatesFunctions;
@ -511,41 +498,48 @@ using namespace TemplatesFunctions;
locale.SetLang(Locale::lang_en);
locale.Read(config->locale_dir, config->locale_dir_default);
}
void Templates::ReadFunctionsTemplates()
{
using namespace TemplatesFunctions;
Functions::Iterator i = functions->Begin();
for(; i != functions->End() ; ++i)
{
const std::string & fun_name = i->first;
const size_t index = i->second->id;
if( index < functions->FunctionsSize() )
{
fun_file = config->templates_fun_prefix;
fun_file += fun_name;
fun_file += config->templates_fun_postfix;
ReadFileFun(index, fun_file.c_str());
}
else
{
log << log1 << "Templates: function index too large, fun: "
<< fun_name << ", index: " << index << logend;
}
}
}
void Templates::ReadTemplates()
{
using namespace TemplatesFunctions;
SetLocale();
ClearPatterns();
ReadFile(pat_index, "index.html");
ReadFile(pat_index, config->templates_index.c_str());
ReadFile(pat_err_404, "err_404.html");
ReadFile(pat_err_per_denied, "err_per_denied.html");
ReadFile(pat_fun_cat, "fun_cat.html");
ReadFile(pat_fun_ls, "fun_ls.html");
ReadFile(pat_fun_rm, "fun_rm.html");
ReadFile(pat_fun_emacs, "fun_emacs.html");
ReadFile(pat_fun_mkdir, "fun_mkdir.html");
ReadFile(pat_fun_default, "fun_default.html");
ReadFile(pat_fun_priv, "fun_priv.html");
ReadFile(pat_fun_who, "fun_who.html");
ReadFile(pat_fun_run, "fun_run.html");
ReadFile(pat_fun_last, "fun_last.html");
ReadFile(pat_item_info, "item_info.html");
ReadFile(pat_item_tab_info, "item_tab_info.html");
ReadFile(pat_fun_thread, "fun_thread.html");
ReadFile(pat_fun_createthread, "fun_createthread.html");
ReadFile(pat_dir_last_info, "dir_last_info.html");
ReadFile(pat_fun_reload, "fun_reload.html");
ReadFile(pat_fun_upload, "fun_upload.html");
ReadFile(pat_fun_ticket, "fun_ticket.html");
ReadFile(pat_fun_createticket, "fun_createticket.html");
ReadFile(pat_fun_uptime, "fun_uptime.html");
ReadFile(pat_fun_login, "fun_login.html");
ReadFile(pat_fun_mv, "fun_mv.html");
ReadFile(pat_fun_uname, "fun_uname.html");
ReadFile(pat_fun_ckeditor, "fun_ckeditor.html");
ReadFile(pat_fun_adduser, "fun_adduser.html");
ReadFile(pat_fun_subject, "fun_subject.html");
ReadFile(pat_fun_cp, "fun_cp.html");
ReadFile(pat_fun_tinymce, "fun_tinymce.html");
ReadFunctionsTemplates();
index_patterns.ReloadPatterns(locale, locale_filter, false);
}
@ -556,39 +550,45 @@ using namespace TemplatesFunctions;
// the rest are deleted
void Templates::ReadNewIndexTemplates()
{
Mounts::MountTab::const_iterator i;
using namespace TemplatesFunctions;
using namespace TemplatesFunctions;
index_patterns.MarkAllToDelete();
const Mounts::MountTab * pmount_tab = TemplatesFunctions::system->mounts.GetMountTab();
for(i=pmount_tab->begin() ; i!=pmount_tab->end() ; ++i)
{
const std::string * file = i->second.HtmlTemplate();
if( file )
index_patterns.AddPatternIfNotExists(*file, locale, locale_filter, false); // file pattern will be unmarked
}
ReadIndexFileNames(true);
index_patterns.DeleteMarked();
}
// reading only index file names (without parsing the files)
void Templates::ReadIndexFileNames()
// if add_pattern is true then pattern will be read (parsed)
// if add_pattern is false then only file_name of the pattern will be remembered
// you can next call ReadTemplates() to read those patterns
void Templates::ReadIndexFileNames(bool add_pattern)
{
using namespace TemplatesFunctions;
Mounts::MountTab::const_iterator i;
const Mounts::MountTab * pmount_tab = TemplatesFunctions::system->mounts.GetMountTab();
// loop through all mount points
for(i=pmount_tab->begin() ; i!=pmount_tab->end() ; ++i)
{
const std::string * file = i->second.HtmlTemplate();
const Mount & mount = i->second;
if( file )
index_patterns.AddFileName(*file);
if( mount.param[Mount::par_html_template].defined )
{
size_t len = mount.param[Mount::par_html_template].arg.size();
size_t a;
// loop through all html_templates() values
for(a=0 ; a<len ; ++a)
{
const std::string & file_name = mount.param[Mount::par_html_template].arg[a];
if( add_pattern )
index_patterns.AddPatternIfNotExists(file_name, locale, locale_filter, false); // file pattern will be unmarked
else
index_patterns.AddFileName(file_name);
}
}
}
}
@ -599,6 +599,7 @@ void Templates::ClearPatterns()
using namespace TemplatesFunctions;
TemplatesFunctions::ClearPatterns(patterns, pat_last);
TemplatesFunctions::ClearPatterns(patterns_fun, functions->FunctionsSize());
}
@ -611,11 +612,27 @@ using namespace TemplatesFunctions;
return;
Ezc::Pattern * index = 0;
const std::string * index_file_local = TemplatesFunctions::system->mounts.pmount->HtmlTemplate();
const std::string * index_file_local = 0;
if( index_file_local )
if( request->is_item )
{
if( !request->item.html_template.empty() )
index_file_local = &request->item.html_template;
}
else
{
if( !request->dir_tab.back()->html_template.empty() )
index_file_local = &request->dir_tab.back()->html_template;
}
if( !index_file_local )
index_file_local = TemplatesFunctions::system->mounts.pmount->FirstHtmlTemplate();
if( index_file_local && *index_file_local != config->templates_index )
index = index_patterns.GetPattern(*index_file_local, locale.GetLang());
if( !index )
index = &patterns[locale.GetLang()][pat_index];
@ -680,7 +697,6 @@ void Templates::SetSessionManager(SessionManager * psession_manager)
Templates::Templates()
{
ClearPatterns();
}

View File

@ -60,9 +60,9 @@ namespace TemplatesFunctions
pat_fun_adduser,
pat_err_404,
pat_err_per_denied,
pat_item_info,
pat_item_tab_info,
pat_dir_last_info,
//pat_item_info,
//pat_item_tab_info,
//pat_dir_last_info,
pat_fun_subject,
pat_fun_cp,
pat_fun_tinymce,
@ -79,6 +79,7 @@ namespace TemplatesFunctions
extern IndexPatterns index_patterns;
extern Patterns patterns;
extern Patterns patterns_fun;
extern PatternCacher pattern_cacher;
extern Locale locale;
extern Ezc::Functions ezc_functions;
@ -144,7 +145,7 @@ namespace TemplatesFunctions
void item_can_read(Info & i);
void item_can_write(Info & i);
void item_can_remove(Info & i);
void item_info(Info & i);
//void item_info(Info & i);
void item_user(Info & i);
void item_modification_user(Info & i);
void item_users_different(Info & i);
@ -155,6 +156,9 @@ namespace TemplatesFunctions
void item_dates_equal(Info & i);
void item_run(Info & i);
void item_guest_name(Info & i);
void item_html_template(Info & i);
void item_has_html_template(Info & i);
void item_tab(Info & i);
void item_tab_id(Info & i);
@ -170,7 +174,7 @@ namespace TemplatesFunctions
void item_tab_link_auth(Info & i);
void item_tab_can_read(Info & i);
void item_tab_can_write(Info & i);
void item_tab_info(Info & i);
//void item_tab_info(Info & i);
void item_tab_user(Info & i);
void item_tab_modification_user(Info & i);
void item_tab_users_different(Info & i);
@ -211,14 +215,16 @@ namespace TemplatesFunctions
void dir_last_default_item_dir(Info &);
void dir_last_default_item_url(Info & i);
void dir_last_subject(Info & i);
void dir_last_info(Info & i);
//void dir_last_info(Info & i);
void dir_last_user(Info & i);
void dir_last_url(Info & i);
void dir_last_url_is(Info & i);
void dir_last_date_creation(Info & i);
void dir_last_date_modification(Info & i);
void dir_last_dates_equal(Info & i);
void dir_last_html_template(Info & i);
void dir_last_has_html_template(Info & i);
/*
user
@ -360,6 +366,8 @@ namespace TemplatesFunctions
void mount_type_is_thread(Info & i);
void mount_type_is_ticket(Info & i);
void mount_type_is_cms(Info & i);
void mount_has_html_template(Info & i);
void mount_first_html_template(Info & i);
/*
@ -404,6 +412,15 @@ namespace TemplatesFunctions
void winix_err_msg_from_locales(Info & i);
void winix_show_content_in_full_window(Info & i);
/*
template (html templates)
*/
void template_index(Info & i);
void template_tab(Info & i);
void template_tab_isdefault(Info & i);
void template_tab_file_name(Info & i);
} // namespace TemplatesFunctions
@ -425,7 +442,7 @@ public:
void ClearPatterns();
void ReadTemplates();
void ReadNewIndexTemplates();
void ReadIndexFileNames();
void ReadIndexFileNames(bool add_pattern = false);
void CreateFunctions();
void Generate();
void GenerateRunRaw();
@ -433,9 +450,12 @@ public:
private:
void ReadFile(TemplatesFunctions::Pat pat, const char * file);
void ReadFileFun(size_t index, const char * file);
void ReadFunctionsTemplates();
void SetLocale();
std::string temp;
std::string fun_file;
};