added: item content type: raw
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@549 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
59943c87cd
commit
3c95b84633
|
@ -19,14 +19,14 @@ void Content::FunCat()
|
|||
if( !request.is_item )
|
||||
{
|
||||
log << log1 << "Content: Cat function requires an item" << logend;
|
||||
request.status = Error::item_required;
|
||||
request.status = Error::no_item;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( !request.HasReadAccess(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ void Content::MakeStandardFunction()
|
|||
|
||||
if( request.pfunction )
|
||||
{
|
||||
request.status = Error::db_no_item;
|
||||
request.status = Error::no_item;
|
||||
log << log1 << "Content: in authorizer mode only 'cat' funtion is available and must "
|
||||
"be default (not in the url)" << logend;
|
||||
return;
|
||||
|
@ -185,7 +185,7 @@ void Content::MakeStandardFunction()
|
|||
if( request.pfunction->code == FUN_UPLOAD )
|
||||
FunUpload();
|
||||
else
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
|
||||
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ void Content::MakePost()
|
|||
{
|
||||
if( request.role == Request::authorizer )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -252,6 +252,32 @@ void Content::MakePost()
|
|||
}
|
||||
|
||||
|
||||
void Content::MakePage()
|
||||
{
|
||||
bool sent = false;
|
||||
|
||||
if( request.is_item && request.item.content_type == Item::ct_raw && request.status == Error::ok && request.pfunction )
|
||||
{
|
||||
if( request.pfunction->code == FUN_CAT )
|
||||
{
|
||||
request.page << request.item.content;
|
||||
sent = true;
|
||||
}
|
||||
else
|
||||
if( request.pfunction->code == FUN_RUN )
|
||||
{
|
||||
templates.GenerateRunRaw();
|
||||
sent = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !sent )
|
||||
{
|
||||
templates.Generate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::Make()
|
||||
{
|
||||
|
@ -273,7 +299,7 @@ void Content::Make()
|
|||
MakeStandardFunction();
|
||||
}
|
||||
else
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
}
|
||||
|
||||
if( request.session->spam_score > 0 )
|
||||
|
@ -289,8 +315,8 @@ void Content::Make()
|
|||
}
|
||||
|
||||
plugin.Call(CMSLU_CONTENT_MAKE);
|
||||
templates.Generate();
|
||||
|
||||
MakePage();
|
||||
|
||||
//request.PrintGetTable();
|
||||
//request.PrintEnv();
|
||||
//request.PrintIn();
|
||||
|
|
|
@ -24,6 +24,8 @@ class Content
|
|||
{
|
||||
Templates templates;
|
||||
|
||||
std::string temp;
|
||||
|
||||
void CheckSpecialFile();
|
||||
|
||||
void PrepareUrl(Item & item);
|
||||
|
@ -69,6 +71,8 @@ class Content
|
|||
|
||||
bool PostFunSetUrlSubject();
|
||||
void PostFunLogin();
|
||||
|
||||
void SetContentType();
|
||||
void PostFunEmacsAdd();
|
||||
void PostFunEmacsEdit(bool with_url);
|
||||
void PostFunEmacs();
|
||||
|
@ -88,6 +92,7 @@ class Content
|
|||
|
||||
void CheckGetPostTimes(time_t difference = 10);
|
||||
// bool CreateFile(const std::string & path, const std::string & content);
|
||||
void MakePage();
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ bool Content::FunCreateThreadCheckAccess()
|
|||
{
|
||||
if( !request.CanCreateThread() )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,7 @@ void Content::PostFunCreateThread()
|
|||
request.PostVar("url", request.item.url);
|
||||
request.PostVar("subject", request.item.subject);
|
||||
request.PostVar("content", request.item.content);
|
||||
SetContentType();
|
||||
SetUser(request.item);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ long defaultid = -1;
|
|||
defaultid = db.GetFileId(pdir->id, file);
|
||||
|
||||
if( defaultid == -1 )
|
||||
throw Error(Error::db_no_item);
|
||||
throw Error(Error::no_item);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ void Content::PostFunDefault()
|
|||
|
||||
if( !request.HasWriteAccess(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ void Content::FunDefault()
|
|||
{
|
||||
if( !request.HasWriteAccess(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,12 +51,12 @@ void Content::PostFunEmacsAdd()
|
|||
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
|
||||
request.item.parent_id = request.dir_table.back()->id;
|
||||
request.item.type = Item::file;
|
||||
request.item.content_type = 1;// !! tymczasowo formatted text
|
||||
request.item.content_type = Item::ct_formatted_text;// !! tymczasowo formatted text
|
||||
|
||||
// dates (creation and modification) is set by request.item.Clear() at the beginning
|
||||
|
||||
if( !request.CanUseEmacs(*request.dir_table.back() ) )
|
||||
throw Error(Error::permision_denied);
|
||||
throw Error(Error::permission_denied);
|
||||
|
||||
request.session->done_status = db.AddItem(request.item);
|
||||
|
||||
|
@ -74,7 +74,7 @@ void Content::PostFunEmacsEdit(bool with_url)
|
|||
request.session->done = Done::edited_item;
|
||||
|
||||
if( !request.CanUseEmacs(request.item) )
|
||||
throw Error(Error::permision_denied);
|
||||
throw Error(Error::permission_denied);
|
||||
|
||||
time_t t = std::time(0);
|
||||
request.item.date_modification = *std::localtime( &t );
|
||||
|
@ -91,7 +91,7 @@ void Content::PostFunEmacsEdit(bool with_url)
|
|||
}
|
||||
|
||||
|
||||
// returning true if the 'url' has to be changed
|
||||
// returning true if the 'url' has to be change
|
||||
bool Content::PostFunSetUrlSubject()
|
||||
{
|
||||
bool with_url = false;
|
||||
|
@ -132,6 +132,42 @@ return with_url;
|
|||
}
|
||||
|
||||
|
||||
void Content::SetContentType()
|
||||
{
|
||||
request.item.content_type = Item::ct_formatted_text; // formatted text default
|
||||
request.PostVar("contenttype", temp);
|
||||
|
||||
if( temp == "text" )
|
||||
request.item.content_type = Item::ct_text;
|
||||
else
|
||||
if( temp == "formatted text" )
|
||||
request.item.content_type = Item::ct_formatted_text;
|
||||
|
||||
if( !request.session->puser )
|
||||
return;
|
||||
|
||||
long user_id = request.session->puser->id;
|
||||
|
||||
if( temp == "html" )
|
||||
{
|
||||
if( request.CanUseHtml(user_id) )
|
||||
request.item.content_type = Item::ct_html;
|
||||
}
|
||||
else
|
||||
if( temp == "bbcode" )
|
||||
{
|
||||
if( request.CanUseBBCode(user_id) )
|
||||
request.item.content_type = Item::ct_bbcode;
|
||||
}
|
||||
else
|
||||
if( temp == "raw" )
|
||||
{
|
||||
if( request.CanUseRaw(user_id) )
|
||||
request.item.content_type = Item::ct_raw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunEmacs()
|
||||
{
|
||||
|
@ -141,6 +177,7 @@ bool adding = !request.is_item;
|
|||
{
|
||||
bool with_url = PostFunSetUrlSubject();
|
||||
request.PostVar("content", request.item.content);
|
||||
SetContentType();
|
||||
|
||||
if( !CheckRebus() )
|
||||
{
|
||||
|
@ -220,7 +257,7 @@ void Content::FunEmacs()
|
|||
{
|
||||
// adding a new item
|
||||
if( !request.CanUseEmacs(*request.dir_table.back()) )
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -228,7 +265,7 @@ void Content::FunEmacs()
|
|||
// editing an existing item
|
||||
if( !request.CanUseEmacs(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ void Content::PostFunMkdir(bool add_to_dir_table, int mask)
|
|||
{
|
||||
if( !request.CanUseMkdir(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ void Content::FunMkdir()
|
|||
// !! what about an item? (is_item)
|
||||
if( !request.CanUseMkdir(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ void Content::FunReload()
|
|||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
{
|
||||
log << log1 << "Content: Only an admin has access to reload function" << logend;
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,12 +55,12 @@ void Content::FunRmDir()
|
|||
{
|
||||
if( !request.CanRemove(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
if( request.param_table.empty() )
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
else
|
||||
if( request.IsParam("confirm") )
|
||||
return;
|
||||
|
@ -82,7 +82,7 @@ void Content::FunRm()
|
|||
|
||||
if( !request.CanRemove(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ void Content::FunRm()
|
|||
}
|
||||
else
|
||||
{
|
||||
request.session->done_status = Error::db_no_item;
|
||||
request.session->done_status = Error::no_item;
|
||||
}
|
||||
|
||||
request.session->done = Done::deleted_item;
|
||||
|
|
|
@ -19,13 +19,13 @@ void Content::FunRun()
|
|||
if( !request.is_item )
|
||||
{
|
||||
log << log1 << "Content: Run function requires an item" << logend;
|
||||
request.status = Error::item_required;
|
||||
request.status = Error::no_item;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !request.HasReadExecAccess(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,14 +17,14 @@ void Content::FunUpload()
|
|||
{
|
||||
if( request.is_item || !request.CanUseUpload(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( data.mounts.CurrentMountType() != Mount::cms )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -34,19 +34,19 @@ void Content::PostFunUpload()
|
|||
{
|
||||
if( request.is_item || !request.CanUseUpload(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
if( data.mounts.CurrentMountType() != Mount::cms )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
if( request.post_file_table.empty() )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ void Content::PostFunUpload()
|
|||
// !! skasowac takze plik z bazy danych
|
||||
log << log1 << "Content: can't move the tmp file from: " << tmp_filename;
|
||||
log << log1 << ", to: " << path << logend;
|
||||
request.status = Error::permision_denied;
|
||||
request.status = Error::permission_denied;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,8 +130,8 @@ void Config::AssignValues()
|
|||
data.priv_no_user = Text("priv_no_user", "-- no user --");
|
||||
data.priv_no_group = Text("priv_no_group", "-- no group --");
|
||||
|
||||
data.session_max_iddle = Int("session_max_iddle", 10800); // 3h
|
||||
data.session_remember_max_iddle = Int("session_remember_max_iddle", 16070400); // 3 months
|
||||
data.session_max_idle = Int("session_max_idle", 10800); // 3h
|
||||
data.session_remember_max_idle = Int("session_remember_max_idle", 16070400); // 3 months
|
||||
data.session_file = Text("session_file");
|
||||
|
||||
data.compression = Bool("compression", true);
|
||||
|
|
|
@ -81,11 +81,11 @@ public:
|
|||
std::string priv_no_group;
|
||||
|
||||
// time in seconds when the user will be automatically logged out (iddle time)
|
||||
int session_max_iddle;
|
||||
int session_max_idle;
|
||||
|
||||
// time in seconds when the user will be automatically logged out (when he selected 'remember me' option)
|
||||
// this time is usually greater than session_max_iddle
|
||||
int session_remember_max_iddle;
|
||||
// this time is usually greater than session_max_idle
|
||||
int session_remember_max_idle;
|
||||
|
||||
// this file is used when the program is starting and ending
|
||||
std::string session_file;
|
||||
|
|
18
core/db.cpp
18
core/db.cpp
|
@ -200,7 +200,7 @@ const char * Db::AssertValue(PGresult * r, int row, int col)
|
|||
{
|
||||
log << log1 << "Db: there is no such an item in the result, row:" << row << ", col:" << col << logend;
|
||||
|
||||
throw Error(Error::db_no_item);
|
||||
throw Error(Error::no_item);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -475,8 +475,8 @@ Error Db::AddItemIntoContent(Item & item)
|
|||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.content (content, content_type) values (";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << item.content_type << "');";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << static_cast<int>(item.content_type) << "');";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
|
@ -586,8 +586,8 @@ Error Db::EditItemInContent(Item & item)
|
|||
std::ostringstream query;
|
||||
query << "update core.content set (content, content_type) = (";
|
||||
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << item.content_type << "' ";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << static_cast<int>(item.content_type) << "' ";
|
||||
query << ") where id='" << item.content_id << "';";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
|
@ -620,7 +620,7 @@ Error Db::EditItemGetId(Item & item)
|
|||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
|
||||
if( PQntuples(r) != 1 || PQnfields(r) != 2 )
|
||||
throw Error(Error::db_no_item);
|
||||
throw Error(Error::no_item);
|
||||
|
||||
// we cannot use AssertColumn() with a name because both columns are called 'id'
|
||||
item.id = atol( AssertValue(r, 0, 0) );
|
||||
|
@ -654,7 +654,7 @@ Error Db::EditItemGetContentId(Item & item)
|
|||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
|
||||
if( PQntuples(r) != 1 || PQnfields(r) != 1 )
|
||||
throw Error(Error::db_no_item);
|
||||
throw Error(Error::no_item);
|
||||
|
||||
item.content_id = atol( AssertValue(r, 0, 0) );
|
||||
}
|
||||
|
@ -735,7 +735,7 @@ Error Db::EditDefaultItem(long id, long new_default_item)
|
|||
|
||||
if( rows == 0 )
|
||||
{
|
||||
result = Error::db_no_item;
|
||||
result = Error::no_item;
|
||||
log << log1 << "Db: EditDefaultItem: no such item, id: " << id << logend;
|
||||
}
|
||||
}
|
||||
|
@ -918,7 +918,7 @@ Error Db::GetItem(long parent_id, const std::string & url, Item & item)
|
|||
int rows = PQntuples(r);
|
||||
|
||||
if( rows == 0 )
|
||||
throw Error(Error::db_no_item);
|
||||
throw Error(Error::no_item);
|
||||
|
||||
ItemColumns col;
|
||||
col.SetColumns(r);
|
||||
|
|
|
@ -49,7 +49,7 @@ void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item)
|
|||
if( default_item != -1 ) item.default_item = atol( Db::AssertValue(r, row, default_item) );
|
||||
if( subject != -1 ) item.subject = Db::AssertValue(r, row, subject);
|
||||
if( content != -1 ) item.content = Db::AssertValue(r, row, content);
|
||||
if( content_type != -1 ) item.content_type = atoi( Db::AssertValue(r, row, content_type) );
|
||||
if( content_type != -1 ) item.content_type = static_cast<Item::ContentType>( atoi(Db::AssertValue(r, row, content_type)) );
|
||||
if( guest_name != -1 ) item.guest_name = Db::AssertValue(r, row, guest_name);
|
||||
if( static_auth != -1 ) item.static_auth = static_cast<Item::StaticAuth>( atoi(Db::AssertValue(r, row, static_auth)) );
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ public:
|
|||
db_incorrect_query,
|
||||
db_incorrent_result_status,
|
||||
db_no_column,
|
||||
db_no_item, // !! zamienic na no_item
|
||||
db_incorrect_login,
|
||||
db_more_than_one_login,
|
||||
db_err_currval,
|
||||
|
@ -38,11 +37,11 @@ public:
|
|||
cant_change_user,
|
||||
cant_change_group,
|
||||
cant_change_privileges,
|
||||
permision_denied, // !! permission_denied (dwa ss)
|
||||
permission_denied,
|
||||
no_root_dir,
|
||||
no_function, // !! zamienic na no_function
|
||||
no_function,
|
||||
|
||||
item_required, // !! zamienic na no_item (i usunac db_no_item)
|
||||
no_item,
|
||||
unknown_param,
|
||||
|
||||
mount_unknown,
|
||||
|
|
|
@ -83,7 +83,7 @@ void FunctionParser::ParseItem()
|
|||
if( request.role == Request::authorizer && request.item.static_auth == Item::static_none )
|
||||
{
|
||||
log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend;
|
||||
request.status = Error::db_no_item;
|
||||
request.status = Error::no_item;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
16
core/item.h
16
core/item.h
|
@ -34,12 +34,16 @@ std::string subject;
|
|||
std::string content;
|
||||
std::string url;
|
||||
|
||||
enum ContentType
|
||||
{
|
||||
ct_text = 0,
|
||||
ct_formatted_text,
|
||||
ct_html,
|
||||
ct_bbcode,
|
||||
ct_raw
|
||||
};
|
||||
|
||||
// 0 - text: simple
|
||||
// 1 - text: formatted
|
||||
// 2 - text: html
|
||||
// 3 - text: bbcode
|
||||
int content_type;
|
||||
ContentType content_type;
|
||||
|
||||
|
||||
|
||||
|
@ -99,7 +103,7 @@ void Clear()
|
|||
content.clear();
|
||||
url.clear();
|
||||
|
||||
content_type = 0;
|
||||
content_type = ct_formatted_text;
|
||||
|
||||
type = none;
|
||||
parent_id = -1;
|
||||
|
|
|
@ -215,30 +215,31 @@ int was_enter = 0; // how many enteres there were before
|
|||
|
||||
out << "<p>";
|
||||
|
||||
for(i = in.begin() ; i != in.end() ; ++i)
|
||||
// skipping first new line characters
|
||||
for(i = in.begin() ; i != in.end() && (*i==13 || *i==10) ; ++i);
|
||||
|
||||
for( ; i != in.end() ; ++i )
|
||||
{
|
||||
if( !HtmlTryChar(out, *i) )
|
||||
if( *i == 13 ) // skipping stupid characters (\r\n\ in dos mode)
|
||||
continue;
|
||||
|
||||
if( *i == 10 )
|
||||
{
|
||||
if( *i == 13 )
|
||||
// skipping stupid characters (\r\n\ in dos mode)
|
||||
continue;
|
||||
|
||||
if( *i == 10 )
|
||||
{
|
||||
++was_enter;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( was_enter == 1 )
|
||||
out << "<br>\n";
|
||||
else
|
||||
if( was_enter > 1 )
|
||||
out << "</p>\n<p>";
|
||||
|
||||
out << *i;
|
||||
was_enter = 0;
|
||||
}
|
||||
++was_enter;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( was_enter == 1 )
|
||||
out << "<br>\n";
|
||||
else
|
||||
if( was_enter > 1 )
|
||||
out << "</p>\n<p>";
|
||||
|
||||
was_enter = 0;
|
||||
}
|
||||
|
||||
if( !HtmlTryChar(out, *i) )
|
||||
out << *i;
|
||||
}
|
||||
|
||||
out << "</p>\n";
|
||||
|
|
|
@ -47,7 +47,7 @@ void Mounts::ReadMounts()
|
|||
Item fstab;
|
||||
Error err = db.GetItem(etc->id, file, fstab);
|
||||
|
||||
if( err == Error::db_no_item )
|
||||
if( err == Error::no_item )
|
||||
{
|
||||
log << log1 << "M: there is no /etc/fstab file" << logend;
|
||||
return;
|
||||
|
|
|
@ -388,7 +388,7 @@ void Request::SendSessionCookie()
|
|||
return;
|
||||
}
|
||||
|
||||
time_t t = time(0) + data.session_remember_max_iddle;
|
||||
time_t t = time(0) + data.session_remember_max_idle;
|
||||
tm * expires = localtime(&t);
|
||||
|
||||
if( !expires )
|
||||
|
@ -456,12 +456,14 @@ void Request::AddDebugInfo()
|
|||
}
|
||||
|
||||
|
||||
void Request::SendPage(bool compressing)
|
||||
void Request::SendPage(bool compressing, const std::string & source_ref)
|
||||
{
|
||||
const std::string & source_ref = page.str();
|
||||
const std::string * source = &source_ref;
|
||||
|
||||
if( data.html_filter )
|
||||
bool raw = request.is_item && request.item.content_type == Item::ct_raw && request.status == Error::ok &&
|
||||
request.pfunction && (request.pfunction->code == FUN_CAT || request.pfunction->code == FUN_RUN);
|
||||
|
||||
if( data.html_filter && !raw )
|
||||
{
|
||||
html_filter.TrimWhite(true);
|
||||
html_filter.BreakLongLines(true);
|
||||
|
@ -480,13 +482,15 @@ void Request::SendPage(bool compressing)
|
|||
|
||||
void Request::SendAll()
|
||||
{
|
||||
bool compressing = data.compression && !browser_msie && !browser_konqueror && accept_encoding_parser.AcceptDeflate();
|
||||
Header header = h_200;
|
||||
const std::string & source_ref = page.str();
|
||||
bool compressing = data.compression && !browser_msie && !browser_konqueror &&
|
||||
accept_encoding_parser.AcceptDeflate() && source_ref.size() >= 512;
|
||||
Header header = h_200;
|
||||
|
||||
if( status == Error::db_no_item || status == Error::no_function || status == Error::unknown_param )
|
||||
if( status == Error::no_item || status == Error::no_function || status == Error::unknown_param )
|
||||
header = h_404;
|
||||
|
||||
if( status == Error::permision_denied || status == Error::cant_change_user || status == Error::cant_change_group )
|
||||
if( status == Error::permission_denied || status == Error::cant_change_user || status == Error::cant_change_group )
|
||||
header = h_403;
|
||||
|
||||
SendSessionCookie();
|
||||
|
@ -504,7 +508,7 @@ Header header = h_200;
|
|||
AddDebugInfo();
|
||||
|
||||
// sending content
|
||||
SendPage(compressing);
|
||||
SendPage(compressing, source_ref);
|
||||
}
|
||||
|
||||
|
||||
|
@ -792,29 +796,23 @@ return true;
|
|||
|
||||
bool Request::CanUseHtml(long user_id)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
// super user can use html
|
||||
return true;
|
||||
|
||||
long group = data.groups.GetGroupId("allow_html");
|
||||
|
||||
if( group == -1 )
|
||||
// there is no such a group
|
||||
return false;
|
||||
|
||||
if( puser->IsMemberOf(group) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return CanUse(user_id, "allow_html");
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseBBCode(long user_id)
|
||||
{
|
||||
return CanUse(user_id, "allow_bbcode");
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseRaw(long user_id)
|
||||
{
|
||||
return CanUse(user_id, "allow_raw");
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUse(long user_id, const char * group_name)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
|
||||
|
@ -822,10 +820,9 @@ bool Request::CanUseBBCode(long user_id)
|
|||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
// super user can use bbcode
|
||||
return true;
|
||||
|
||||
long group = data.groups.GetGroupId("allow_bbcode");
|
||||
long group = data.groups.GetGroupId(group_name);
|
||||
|
||||
if( group == -1 )
|
||||
// there is no such a group
|
||||
|
@ -838,6 +835,9 @@ return false;
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Request::MakeDirsOnFS(std::string & path)
|
||||
{
|
||||
size_t i;
|
||||
|
|
|
@ -153,7 +153,8 @@ struct Request
|
|||
|
||||
bool CanUseHtml(long user_id);
|
||||
bool CanUseBBCode(long user_id);
|
||||
|
||||
bool CanUseRaw(long user_id);
|
||||
|
||||
bool MakeDirsOnFS(std::string & path);
|
||||
|
||||
private:
|
||||
|
@ -165,13 +166,15 @@ private:
|
|||
h_403
|
||||
};
|
||||
|
||||
bool CanUse(long user_id, const char * group_name);
|
||||
|
||||
void SendSessionCookie();
|
||||
void CheckIE();
|
||||
void CheckKonqueror();
|
||||
|
||||
void SendHeaders(bool compressing, Header header);
|
||||
void AddDebugInfo();
|
||||
void SendPage(bool compressing);
|
||||
void SendPage(bool compressing, const std::string & source_ref);
|
||||
|
||||
// used to set some env_* variables into it, when the server didn't set that variable
|
||||
// it contains '\0'
|
||||
|
|
|
@ -179,7 +179,7 @@ SessionContainer::Iterator SessionManager::SessionEnd()
|
|||
|
||||
void SessionManager::DeleteOldSessions()
|
||||
{
|
||||
session_table.DelFirstByTimeInterval(data.session_max_iddle);
|
||||
session_table.DelFirstByTimeInterval(data.session_max_idle);
|
||||
|
||||
if( ++session_checker > 1000 )
|
||||
{
|
||||
|
@ -187,7 +187,7 @@ void SessionManager::DeleteOldSessions()
|
|||
log << log3 << "SM: checking sessions which have 'remember me' flag set" << logend;
|
||||
|
||||
session_checker = 0;
|
||||
session_table.DelFirstByTimeInterval(data.session_remember_max_iddle, false);
|
||||
session_table.DelFirstByTimeInterval(data.session_remember_max_idle, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ void done_status(Info & i)
|
|||
|
||||
void done_status_no_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done_status == Error::db_no_item;
|
||||
i.result = request.session->done_status == Error::no_item;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -63,36 +63,79 @@ void item_content_noescape(Info & i)
|
|||
}
|
||||
|
||||
|
||||
void item_print_content(Info & i)
|
||||
void item_content_type_is(Info & i)
|
||||
{
|
||||
if( request.item.content_type == 0 ) // simple txt
|
||||
switch(request.item.content_type)
|
||||
{
|
||||
HtmlEscape(i.out, request.item.content);
|
||||
}
|
||||
else
|
||||
if( request.item.content_type == 1 ) // formatted txt
|
||||
{
|
||||
HtmlEscapeFormTxt(i.out, request.item.content);
|
||||
}
|
||||
else
|
||||
if( request.item.content_type == 2 ) // html
|
||||
{
|
||||
if( request.CanUseHtml(request.item.user_id) )
|
||||
i.out << request.item.content;
|
||||
else
|
||||
HtmlEscape(i.out, request.item.content);
|
||||
}
|
||||
else
|
||||
if( request.item.content_type == 3 ) // bbcode
|
||||
{
|
||||
if( request.CanUseBBCode(request.item.user_id) )
|
||||
HtmlEscape(i.out, request.item.content); // tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
||||
else
|
||||
i.out << request.item.content;
|
||||
case Item::ct_text:
|
||||
i.out_string = "text";
|
||||
break;
|
||||
|
||||
case Item::ct_formatted_text:
|
||||
i.out_string = "formatted text";
|
||||
break;
|
||||
|
||||
case Item::ct_html:
|
||||
i.out_string = "html";
|
||||
break;
|
||||
|
||||
case Item::ct_bbcode:
|
||||
i.out_string = "bbcode";
|
||||
break;
|
||||
|
||||
case Item::ct_raw:
|
||||
i.out_string = "raw";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_print_content(std::ostringstream & out, const std::string & content, Item::ContentType content_type)
|
||||
{
|
||||
if( content_type == Item::ct_text )
|
||||
{
|
||||
HtmlEscape(out, content);
|
||||
}
|
||||
else
|
||||
if( content_type == Item::ct_formatted_text )
|
||||
{
|
||||
HtmlEscapeFormTxt(out, content);
|
||||
}
|
||||
else
|
||||
if( content_type == Item::ct_html )
|
||||
{
|
||||
if( request.CanUseHtml(request.item.user_id) )
|
||||
out << content;
|
||||
else
|
||||
HtmlEscape(out, content);
|
||||
}
|
||||
else
|
||||
if( content_type == Item::ct_bbcode )
|
||||
{
|
||||
if( request.CanUseBBCode(request.item.user_id) )
|
||||
out << content; // !! tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
||||
else
|
||||
HtmlEscape(out, content);
|
||||
}
|
||||
else
|
||||
if( content_type == Item::ct_raw )
|
||||
{
|
||||
if( request.CanUseRaw(request.item.user_id) )
|
||||
out << content;
|
||||
else
|
||||
HtmlEscape(out, content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_print_content(Info & i)
|
||||
{
|
||||
item_print_content(i.out, request.item.content, request.item.content_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_privileges(Info & i)
|
||||
{
|
||||
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
||||
|
@ -212,6 +255,7 @@ void item_dates_equal(Info & i)
|
|||
}
|
||||
|
||||
|
||||
|
||||
void item_run(Info & i)
|
||||
{
|
||||
if( !request.is_item )
|
||||
|
@ -227,8 +271,12 @@ void item_run(Info & i)
|
|||
}
|
||||
|
||||
Ezc::Pattern * p = pattern_cacher.GetPattern(request.item);
|
||||
Ezc::Generator gen(i.out, *p, functions);
|
||||
std::ostringstream item_run_content;
|
||||
|
||||
Ezc::Generator gen(item_run_content, *p, functions);
|
||||
gen.Generate();
|
||||
|
||||
item_print_content(i.out, item_run_content.str(), request.item.content_type);
|
||||
}
|
||||
|
||||
|
||||
|
@ -354,33 +402,10 @@ void item_tab_print_content(Info & i)
|
|||
if( item_index >= request.item_table.size() )
|
||||
return;
|
||||
|
||||
int type = request.item_table[item_index].content_type;
|
||||
std::string & content = request.item_table[item_index].content;
|
||||
Item::ContentType type = request.item_table[item_index].content_type;
|
||||
|
||||
if( type == 0 ) // simple txt
|
||||
{
|
||||
HtmlEscape(i.out, request.item_table[item_index].content);
|
||||
}
|
||||
else
|
||||
if( type == 1 ) // formatted txt
|
||||
{
|
||||
HtmlEscapeFormTxt(i.out, request.item_table[item_index].content);
|
||||
}
|
||||
else
|
||||
if( type == 2 ) // html
|
||||
{
|
||||
if( request.CanUseHtml(request.item_table[item_index].user_id) )
|
||||
i.out << request.item_table[item_index].content;
|
||||
else
|
||||
HtmlEscape(i.out, request.item_table[item_index].content);
|
||||
}
|
||||
else
|
||||
if( type == 3 ) // bbcode
|
||||
{
|
||||
if( request.CanUseBBCode(request.item_table[item_index].user_id) )
|
||||
HtmlEscape(i.out, request.item_table[item_index].content); // tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
||||
else
|
||||
i.out << request.item_table[item_index].content;
|
||||
}
|
||||
item_print_content(i.out, content, type);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -146,18 +146,18 @@ Ezc::Pattern * p = 0;
|
|||
p = content_for_function();
|
||||
break;
|
||||
|
||||
case Error::item_required:
|
||||
case Error::no_item:
|
||||
p = &pat_err_item_required;
|
||||
break;
|
||||
|
||||
case Error::permision_denied:
|
||||
case Error::permission_denied:
|
||||
case Error::cant_change_user:
|
||||
case Error::cant_change_group:
|
||||
case Error::cant_change_privileges:
|
||||
p = &pat_err_per_denied;
|
||||
break;
|
||||
|
||||
case Error::db_no_item:
|
||||
//case Error::no_item:
|
||||
case Error::no_function:
|
||||
case Error::unknown_param:
|
||||
p = &pat_err_404;
|
||||
|
@ -226,6 +226,7 @@ void Templates::CreateFunctions()
|
|||
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_content_type_is", item_content_type_is);
|
||||
functions.Insert("item_print_content", item_print_content);
|
||||
functions.Insert("item_privileges", item_privileges);
|
||||
functions.Insert("item_dir", item_dir);
|
||||
|
@ -307,9 +308,12 @@ void Templates::CreateFunctions()
|
|||
/*
|
||||
user
|
||||
*/
|
||||
functions.Insert("user_name", user_name);
|
||||
functions.Insert("user_logged", user_logged);
|
||||
functions.Insert("user_super_user", user_super_user);
|
||||
functions.Insert("user_name", user_name);
|
||||
functions.Insert("user_logged", user_logged);
|
||||
functions.Insert("user_super_user", user_super_user);
|
||||
functions.Insert("user_can_use_html", user_can_use_html);
|
||||
functions.Insert("user_can_use_bbcode", user_can_use_bbcode);
|
||||
functions.Insert("user_can_use_raw", user_can_use_raw);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -487,13 +491,22 @@ void Templates::ReadTemplates()
|
|||
|
||||
void Templates::Generate()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Ezc::Generator generator(request.page, pat_index, functions);
|
||||
|
||||
generator.Generate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Templates::GenerateRunRaw()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Ezc::Info info(request.page);
|
||||
info.iter = 0;
|
||||
info.result = false;
|
||||
|
||||
item_run(info);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,8 @@ namespace TemplatesFunctions
|
|||
void item_subject_noescape(Info & i);
|
||||
void item_content(Info & i);
|
||||
void item_content_noescape(Info & i);
|
||||
void item_content_type_is(Info & i);
|
||||
void item_print_content(std::ostringstream & out, const std::string & content, Item::ContentType content_type);
|
||||
void item_print_content(Info & i);
|
||||
void item_privileges(Info & i);
|
||||
void item_dir(Info & i);
|
||||
|
@ -80,7 +82,6 @@ namespace TemplatesFunctions
|
|||
void item_run(Info & i);
|
||||
void item_guest_name(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);
|
||||
|
@ -146,7 +147,9 @@ namespace TemplatesFunctions
|
|||
void user_name(Info & i);
|
||||
void user_logged(Info & i);
|
||||
void user_super_user(Info & i);
|
||||
|
||||
void user_can_use_html(Info & i);
|
||||
void user_can_use_bbcode(Info & i);
|
||||
void user_can_use_raw(Info & i);
|
||||
|
||||
/*
|
||||
privileges
|
||||
|
@ -246,6 +249,7 @@ public:
|
|||
void ReadTemplates();
|
||||
void CreateFunctions();
|
||||
void Generate();
|
||||
void GenerateRunRaw();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -43,8 +43,31 @@ void user_super_user(Info & i)
|
|||
}
|
||||
|
||||
|
||||
void user_can_use_html(Info & i)
|
||||
{
|
||||
if( !request.session->puser )
|
||||
i.result = false;
|
||||
else
|
||||
i.result = request.CanUseHtml(request.session->puser->id);
|
||||
}
|
||||
|
||||
|
||||
void user_can_use_bbcode(Info & i)
|
||||
{
|
||||
if( !request.session->puser )
|
||||
i.result = false;
|
||||
else
|
||||
i.result = request.CanUseBBCode(request.session->puser->id);
|
||||
}
|
||||
|
||||
|
||||
void user_can_use_raw(Info & i)
|
||||
{
|
||||
if( !request.session->puser )
|
||||
i.result = false;
|
||||
else
|
||||
i.result = request.CanUseRaw(request.session->puser->id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue