diff --git a/core/misc.cpp b/core/misc.cpp index cd5363f..a17b224 100755 --- a/core/misc.cpp +++ b/core/misc.cpp @@ -561,6 +561,40 @@ return false; +/* + return true if the whole string has only white characters + an empty string is treated as white +*/ +bool IsWhite(const wchar_t * str, bool treat_new_line_as_white) +{ + for( ; *str != 0 ; ++str ) + { + if( *str == '\n' ) + { + if( !treat_new_line_as_white ) + return false; + } + else + if( !IsWhite(*str) ) + return false; + } + +return true; +} + + + +/* + return true if the whole string has only white characters +*/ +bool IsWhite(const std::wstring & str, bool treat_new_line_as_white) +{ + return IsWhite(str.c_str(), treat_new_line_as_white); +} + + + + bool IsLastSlash(const std::wstring & path) { diff --git a/core/misc.h b/core/misc.h index 02f8bd5..99eac0f 100755 --- a/core/misc.h +++ b/core/misc.h @@ -227,6 +227,8 @@ const char * DateToStrCookie(time_t t); const wchar_t * IpToStr(unsigned int ip_); bool IsWhite(wchar_t s); +bool IsWhite(const wchar_t * str, bool treat_new_line_as_white = false); +bool IsWhite(const std::wstring & str, bool treat_new_line_as_white = false); bool IsLastSlash(const std::wstring & path); template diff --git a/locale/en b/locale/en index 9d4a287..b9e479d 100755 --- a/locale/en +++ b/locale/en @@ -7,6 +7,9 @@ charset = UTF-8 logged_as = logged as logged_as_long = You are logged as +display_guest_name = guest + + account_not_activated = This account is not activated yet. account_suspended = This account is temporarily suspended account_banned = This account has been banned diff --git a/locale/pl b/locale/pl index ba629e1..caf39a4 100755 --- a/locale/pl +++ b/locale/pl @@ -8,6 +8,8 @@ charset = UTF-8 logged_as = zalogowany jako logged_as_long = Aktualnie jesteś zalogowany jako +display_guest_name = gość + account_not_activated = To konto nie jest jeszcze aktywowane account_suspended = To konto jest tymczasowo zablokowane account_banned = To konto zostało wyłączone diff --git a/templates/misc.cpp b/templates/misc.cpp index 08d8c70..3895456 100755 --- a/templates/misc.cpp +++ b/templates/misc.cpp @@ -86,20 +86,34 @@ void print_date_nice(Info & i, const PT::Date & date) } -void print_user_name(Info & i, const User * puser, const std::wstring & guest_name) + + +// cannot be a const reference at the moment (PT::Space is used) +void print_user_name(Info & i, User & user) +{ + std::wstring * dname = user.aenv.GetValue(L"display_name"); + + if( dname && !IsWhite(*dname, true) ) + i.out << *dname; + else + i.out << user.name; +} + + +void print_user_name(Info & i, User * puser, const std::wstring & guest_name) { if( puser ) { - i.out << puser->name; + print_user_name(i, *puser); } else { i.out << "~"; - - if( !guest_name.empty() ) + + if( !guest_name.empty() && !IsWhite(guest_name) ) i.out << guest_name; else - i.out << "guest"; // !! dodac do konfiga + i.out << locale.Get(L"display_guest_name"); } } diff --git a/templates/misc.h b/templates/misc.h index fbe87a3..8f1896e 100755 --- a/templates/misc.h +++ b/templates/misc.h @@ -39,7 +39,24 @@ void HtmlEscapeFormTxt(HtmlTextStream & out, const std::wstring & in); void print_hour_min(Info & i, time_t time); void print_date_nice(Info & i, const PT::Date & date); -void print_user_name(Info & i, const User * puser, const std::wstring & guest_name); + + +/* + print a user name -- it is trying to use 'display_name' from user's admin env + if it not find it or if the 'display_name' is all white (consists of all white characters) + then the login name is printed +*/ +void print_user_name(Info & i, User & user); + + + +/* + puser can be null -- in such a case guest_name is used + if guest_name is empty then 'display_guest_name' from locales is printed +*/ +void print_user_name(Info & i, User * puser, const std::wstring & guest_name); + + } // namespace TemplatesFunctions