Files
winix/templates/misc.cpp
Tomasz Sowa 5b8a9c0108 added: Patterns class (in templates)
ezc patterns are managed by this class
added: some work in groupitem plugin (not finished yet)
changed: ConfParser can read a string from memory now
         (need some testing yet)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@757 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-08-25 23:53:49 +00:00

103 lines
1.7 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2011, 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_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
}
}
} // namespace TemplatesFunctions