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:
2010-01-11 14:47:52 +00:00
parent 59943c87cd
commit 3c95b84633
28 changed files with 319 additions and 178 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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)) );
}

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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";

View File

@@ -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;

View File

@@ -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;

View File

@@ -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'

View File

@@ -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);
}
}