179 lines
2.8 KiB
C++
Executable File
179 lines
2.8 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
|
|
#include "templates.h"
|
|
#include "misc.h"
|
|
#include "core/misc.h"
|
|
#include "core/request.h"
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
{
|
|
|
|
/*
|
|
bool HtmlTryChar(TextStream<std::wstring> & out, wchar_t c)
|
|
{
|
|
if( c == '<' )
|
|
{
|
|
out << L"<";
|
|
return true;
|
|
}
|
|
else
|
|
if( c == '>' )
|
|
{
|
|
out << L">";
|
|
return true;
|
|
}
|
|
else
|
|
if( c == '&' )
|
|
{
|
|
out << L"&";
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
void HtmlEscape(TextStream<std::wstring> & out, const std::wstring & in)
|
|
{
|
|
std::wstring::const_iterator i;
|
|
|
|
for(i = in.begin() ; i != in.end() ; ++i)
|
|
{
|
|
if( !HtmlTryChar(out, *i) )
|
|
out << *i;
|
|
}
|
|
}
|
|
|
|
|
|
std::wstring HtmlEscape(const std::wstring & in)
|
|
{
|
|
TextStream<std::wstring> out;
|
|
|
|
HtmlEscape(out, in);
|
|
|
|
return out.Str();
|
|
}
|
|
*/
|
|
|
|
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");
|
|
}
|
|
|
|
/*
|
|
std::wstring HtmlEscapeFormTxt(const std::wstring & in)
|
|
{
|
|
TextStream<std::wstring> out;
|
|
|
|
HtmlEscapeFormTxt(out, in);
|
|
|
|
return out.Str();
|
|
}
|
|
*/
|
|
|
|
|
|
void print_date_nice(Info & i, const tm & rtm)
|
|
{
|
|
time_t t = Time(rtm);
|
|
time_t now = std::time(0);
|
|
time_t one_day = 60 * 60 * 24;
|
|
|
|
tm ltm = system->LocalTime(rtm);
|
|
|
|
if( t + one_day > now )
|
|
i.out << DateToStr(ltm.tm_year + 1900, ltm.tm_mon + 1, ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec);
|
|
else
|
|
i.out << DateToStr(ltm.tm_year + 1900, ltm.tm_mon + 1, ltm.tm_mday);
|
|
}
|
|
|
|
|
|
void print_user_name(Info & i, const User * puser, const std::wstring & guest_name)
|
|
{
|
|
if( puser )
|
|
{
|
|
i.out << puser->name;
|
|
}
|
|
else
|
|
{
|
|
i.out << "~";
|
|
|
|
if( !guest_name.empty() )
|
|
i.out << guest_name;
|
|
else
|
|
i.out << "guest"; // !! dodac do konfiga
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int ParseCKeditorFun()
|
|
{
|
|
ckeditor_getparser.fun_num = 2; // default if there is a problem with parsing info
|
|
|
|
if( !cur->request->get_tab.empty() )
|
|
{
|
|
size_t last = cur->request->get_tab.size()-1;
|
|
|
|
if( !cur->request->get_tab[last].empty() )
|
|
{
|
|
static std::string get;
|
|
AssignString(cur->request->get_tab[last], get);
|
|
ckeditor_getparser.Parse(get.c_str() + 1); // the first char is '?'
|
|
}
|
|
}
|
|
|
|
return ckeditor_getparser.fun_num;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|