126 lines
2.1 KiB
C++
Executable File
126 lines
2.1 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010-2012, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
|
|
#include "templates.h"
|
|
#include "misc.h"
|
|
#include "core/misc.h"
|
|
#include "core/request.h"
|
|
#include "core/user.h"
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
{
|
|
|
|
|
|
|
|
void HtmlEscapeFormTxt(HtmlTextStream & out, const std::wstring & in)
|
|
{
|
|
std::wstring::const_iterator i;
|
|
int was_enter = 0; // how many enteres there were before
|
|
|
|
if( in.empty() )
|
|
return;
|
|
|
|
out << R("<p>"); // !! pozbyc sie wstawianie tego html tutaj (wrzucic w jakis sposob do szablonow)
|
|
|
|
// skipping first new line characters
|
|
for(i = in.begin() ; i != in.end() && (*i==13 || *i==10) ; ++i);
|
|
|
|
for( ; i != in.end() ; ++i )
|
|
{
|
|
if( *i == 13 ) // skipping stupid characters (\r\n\ in dos mode)
|
|
continue;
|
|
|
|
if( *i == 10 )
|
|
{
|
|
++was_enter;
|
|
}
|
|
else
|
|
{
|
|
if( was_enter == 1 )
|
|
out << R("<br>\n");
|
|
else
|
|
if( was_enter > 1 )
|
|
out << R("</p>\n<p>");
|
|
|
|
was_enter = 0;
|
|
}
|
|
|
|
out << *i;
|
|
}
|
|
|
|
out << R("</p>\n");
|
|
}
|
|
|
|
|
|
|
|
void print_hour_min(Info & i, time_t time)
|
|
{
|
|
char buffer[100];
|
|
|
|
int hours = time / 60 / 60;
|
|
int mins = (time / 60 - hours * 60);
|
|
|
|
sprintf(buffer, "%02d:%02d", hours, mins);
|
|
i.out << buffer;
|
|
}
|
|
|
|
|
|
|
|
void print_date_nice(Info & i, const PT::Date & date)
|
|
{
|
|
time_t one_day = 60 * 60 * 24;
|
|
PT::Date ltm = system->ToLocal(date);
|
|
|
|
if( date + one_day > cur->request->start_time )
|
|
i.out << DateToStr(ltm.year, ltm.month, ltm.day, ltm.hour, ltm.min, ltm.sec);
|
|
else
|
|
i.out << DateToStr(ltm.year, ltm.month, ltm.day);
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 )
|
|
{
|
|
print_user_name(i, *puser);
|
|
}
|
|
else
|
|
{
|
|
i.out << "~";
|
|
|
|
if( !guest_name.empty() && !IsWhite(guest_name) )
|
|
i.out << guest_name;
|
|
else
|
|
i.out << locale.Get(L"display_guest_name");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|