2010-01-28 16:39:01 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2010-01-28 16:39:01 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-07-04 22:27:14 +02:00
|
|
|
#include "templates.h"
|
2010-01-28 16:39:01 +01:00
|
|
|
#include "misc.h"
|
2010-10-19 02:31:20 +02:00
|
|
|
#include "core/misc.h"
|
|
|
|
#include "core/request.h"
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
|
2010-07-04 22:27:14 +02:00
|
|
|
namespace TemplatesFunctions
|
2010-01-28 16:39:01 +01:00
|
|
|
{
|
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
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(TextStream<std::wstring> & 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 << L"<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 << L"<br>\n";
|
|
|
|
else
|
|
|
|
if( was_enter > 1 )
|
|
|
|
out << L"</p>\n<p>";
|
|
|
|
|
|
|
|
was_enter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !HtmlTryChar(out, *i) )
|
|
|
|
out << *i;
|
|
|
|
}
|
|
|
|
|
|
|
|
out << L"</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)
|
2010-02-15 01:31:14 +01:00
|
|
|
{
|
2010-10-24 01:12:47 +02:00
|
|
|
time_t t = Time(rtm);
|
|
|
|
time_t now = std::time(0);
|
2010-02-15 01:31:14 +01:00
|
|
|
time_t one_day = 60 * 60 * 24;
|
2010-06-22 23:09:37 +02:00
|
|
|
|
2010-10-24 01:12:47 +02:00
|
|
|
tm ltm = system->LocalTime(rtm);
|
2010-02-15 01:31:14 +01:00
|
|
|
|
|
|
|
if( t + one_day > now )
|
2010-10-24 01:12:47 +02:00
|
|
|
i.out << DateToStr(ltm.tm_year + 1900, ltm.tm_mon + 1, ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec);
|
2010-02-15 01:31:14 +01:00
|
|
|
else
|
2010-10-24 01:12:47 +02:00
|
|
|
i.out << DateToStr(ltm.tm_year + 1900, ltm.tm_mon + 1, ltm.tm_mday);
|
2010-02-15 01:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void print_user_name(Info & i, const User * puser, const std::wstring & guest_name)
|
2010-10-19 02:31:20 +02:00
|
|
|
{
|
|
|
|
if( puser )
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, puser->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i.out << "~";
|
|
|
|
|
|
|
|
if( !guest_name.empty() )
|
|
|
|
HtmlEscape(i.out, guest_name);
|
|
|
|
else
|
|
|
|
i.out << "guest"; // !! dodac do konfiga
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
|
2010-07-05 17:21:06 +02:00
|
|
|
int ParseCKeditorFun()
|
|
|
|
{
|
|
|
|
ckeditor_getparser.fun_num = 2; // default if there is a problem with parsing info
|
2010-02-15 01:31:14 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( !request->get_tab.empty() )
|
2010-07-05 17:21:06 +02:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
size_t last = request->get_tab.size()-1;
|
2010-02-15 01:31:14 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( !request->get_tab[last].empty() )
|
2010-07-05 17:21:06 +02:00
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
static std::string get;
|
|
|
|
AssignString(request->get_tab[last], get);
|
|
|
|
ckeditor_getparser.Parse(get.c_str() + 1); // the first char is '?'
|
2010-07-05 17:21:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ckeditor_getparser.fun_num;
|
|
|
|
}
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
|
|
|
|
|
2010-07-05 17:21:06 +02:00
|
|
|
// those functions from here are used in the second thread too
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void Read(Patterns & patterns, size_t pat, Locale & locale, LocaleFilter & locale_filter, const wchar_t * file, bool delete_white)
|
2010-01-28 16:39:01 +01:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t len = patterns.size();
|
|
|
|
|
|
|
|
for(i=0 ; i<len ; ++i)
|
|
|
|
{
|
|
|
|
if( pat < patterns[i].size() )
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
patterns[i][pat].UTF8(true); // !! powinno byc brane z konfiga
|
2010-07-20 01:07:34 +02:00
|
|
|
patterns[i][pat].DeleteWhiteTextItems(delete_white);
|
2010-08-10 18:12:50 +02:00
|
|
|
patterns[i][pat].Directory(config->templates_dir, config->templates_dir_default);
|
2010-01-28 16:39:01 +01:00
|
|
|
patterns[i][pat].ParseFile(file);
|
|
|
|
|
2010-06-22 01:53:19 +02:00
|
|
|
locale_filter.Filter(patterns[i][pat], locale, static_cast<Locale::Lang>(i));
|
2010-01-28 16:39:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ClearPatterns(Patterns & patterns, size_t len)
|
|
|
|
{
|
|
|
|
size_t loc, pat;
|
|
|
|
|
|
|
|
patterns.resize(Locale::lang_unknown);
|
|
|
|
|
|
|
|
for(loc=0 ; loc < static_cast<size_t>(Locale::lang_unknown) ; ++loc)
|
|
|
|
{
|
|
|
|
patterns[loc].resize(len);
|
|
|
|
|
|
|
|
for(pat=0 ; pat<len ; ++pat)
|
|
|
|
patterns[loc][pat].Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-04 22:27:14 +02:00
|
|
|
} // namespace TemplatesFunctions
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
|