/* * 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" namespace TemplatesFunctions { /* bool HtmlTryChar(TextStream & 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 & 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 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("

"); // !! 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("
\n"); else if( was_enter > 1 ) out << R("

\n

"); was_enter = 0; } out << *i; } out << R("

\n"); } /* std::wstring HtmlEscapeFormTxt(const std::wstring & in) { TextStream 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 } } } // namespace TemplatesFunctions