2010-01-28 16:39:01 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-04-09 17:50:58 +02:00
|
|
|
* Copyright (c) 2010-2021, Tomasz Sowa
|
2010-01-28 16:39:01 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2010-01-28 16:39:01 +01:00
|
|
|
*/
|
|
|
|
|
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"
|
2021-04-30 01:34:48 +02:00
|
|
|
#include "models/user.h"
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
2014-10-19 23:20:09 +02:00
|
|
|
extern EzcFun ezc_functions;
|
|
|
|
extern Ezc::Blocks ezc_blocks;
|
2021-05-23 10:14:08 +02:00
|
|
|
extern Ezc::Vars ezc_vars;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
void HtmlEscapeFormTxt(HtmlTextStream & out, const std::wstring & in)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
|
|
|
std::wstring::const_iterator i;
|
|
|
|
int was_enter = 0; // how many enteres there were before
|
|
|
|
|
|
|
|
if( in.empty() )
|
|
|
|
return;
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
out << R("<p>"); // !! pozbyc sie wstawianie tego html tutaj (wrzucic w jakis sposob do szablonow)
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
// 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 )
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
out << R("<br>\n");
|
2010-11-21 01:19:17 +01:00
|
|
|
else
|
|
|
|
if( was_enter > 1 )
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
out << R("</p>\n<p>");
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
was_enter = 0;
|
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
out << *i;
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
out << R("</p>\n");
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2014-10-19 23:20:09 +02:00
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
void InitGenerator(EzcGen & gen, Ezc::Models & ezc_models)
|
2014-10-19 23:20:09 +02:00
|
|
|
{
|
|
|
|
gen.TrimWhite(gen_trim_white);
|
|
|
|
gen.SkipNewLine(gen_skip_new_line);
|
|
|
|
gen.RecognizeSpecialChars(gen_use_special_chars);
|
|
|
|
gen.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* although we have addresses to blocks and functions cached in patters
|
|
|
|
* we have to provide it here because they will be used for variables
|
|
|
|
* if a variable is an alias e.g. [def variable function]
|
|
|
|
*/
|
|
|
|
gen.SetBlocks(ezc_blocks);
|
|
|
|
gen.SetFunctions(ezc_functions);
|
2021-05-23 10:14:08 +02:00
|
|
|
gen.SetVariables(ezc_vars);
|
2021-05-31 18:59:20 +02:00
|
|
|
|
|
|
|
gen.SetModels(ezc_models);
|
2021-06-19 20:33:35 +02:00
|
|
|
gen.SetLogger(log);
|
2014-10-19 23:20:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-23 01:34:33 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
void print_date_nice(Info & i, const pt::Date & date)
|
2010-02-15 01:31:14 +01:00
|
|
|
{
|
|
|
|
time_t one_day = 60 * 60 * 24;
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date ltm = system->ToLocal(date);
|
2010-02-15 01:31:14 +01:00
|
|
|
|
2012-05-27 01:04:49 +02:00
|
|
|
if( date + one_day > cur->request->start_time )
|
|
|
|
i.out << DateToStr(ltm.year, ltm.month, ltm.day, ltm.hour, ltm.min, ltm.sec);
|
2010-02-15 01:31:14 +01:00
|
|
|
else
|
2012-05-27 01:04:49 +02:00
|
|
|
i.out << DateToStr(ltm.year, ltm.month, ltm.day);
|
2010-02-15 01:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-26 09:18:32 +02:00
|
|
|
|
2021-06-19 23:48:12 +02:00
|
|
|
// DEPRECATED, we have ItemContent::display_user_name and User::display_name
|
2012-09-26 09:18:32 +02:00
|
|
|
void print_user_name(Info & i, User * puser, const std::wstring & guest_name)
|
2010-10-19 02:31:20 +02:00
|
|
|
{
|
|
|
|
if( puser )
|
|
|
|
{
|
2021-06-19 23:48:12 +02:00
|
|
|
puser->display_name(i);
|
2010-10-19 02:31:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i.out << "~";
|
2012-09-26 09:18:32 +02:00
|
|
|
|
|
|
|
if( !guest_name.empty() && !IsWhite(guest_name) )
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
i.out << guest_name;
|
2010-10-19 02:31:20 +02:00
|
|
|
else
|
2012-09-26 09:18:32 +02:00
|
|
|
i.out << locale.Get(L"display_guest_name");
|
2010-10-19 02:31:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-20 21:22:08 +02:00
|
|
|
bool should_escape(Info & env)
|
|
|
|
{
|
|
|
|
bool res = true;
|
|
|
|
|
|
|
|
for(size_t i=0 ; i < env.params.size() ; ++i)
|
|
|
|
{
|
|
|
|
// CHECKME what about env.params[i].is_function ?
|
|
|
|
|
|
|
|
if( env.params[i].str == L"noescape" || env.params[i].str == L"raw" )
|
|
|
|
{
|
|
|
|
res = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2021-06-19 23:48:12 +02:00
|
|
|
|
2010-07-04 22:27:14 +02:00
|
|
|
} // namespace TemplatesFunctions
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
} // namespace Winix
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
|