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:
@@ -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
|
||||
|
@@ -144,7 +144,7 @@ bool App::Init()
|
||||
if( !notify.Init() )
|
||||
return false;
|
||||
|
||||
|
||||
// init templates after functions are created
|
||||
templates.ReadIndexFileNames();
|
||||
templates.ReadTemplates();
|
||||
templates.CreateFunctions();
|
||||
|
@@ -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");
|
||||
|
@@ -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;
|
||||
|
45
core/db.cpp
45
core/db.cpp
@@ -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";
|
||||
|
@@ -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);
|
||||
|
@@ -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) );
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -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];
|
||||
|
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user