moved winix directories to winixdsubdirectory
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1028 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
179
winixd/templates/misc.cpp
Normal file
179
winixd/templates/misc.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "misc.h"
|
||||
#include "core/misc.h"
|
||||
#include "core/request.h"
|
||||
#include "core/user.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
extern EzcFun ezc_functions;
|
||||
extern Ezc::Blocks ezc_blocks;
|
||||
|
||||
|
||||
|
||||
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 InitGenerator(EzcGen & gen)
|
||||
{
|
||||
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);
|
||||
gen.SetCommentary(config->ezc_error_prefix, config->ezc_error_postfix);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_date_nice(Info & i, const PT::Date & date)
|
||||
{
|
||||
time_t one_day = 60 * 60 * 24;
|
||||
PT::Date ltm = system->ToLocal(date);
|
||||
|
||||
if( date + one_day > cur->request->start_time )
|
||||
i.out << DateToStr(ltm.year, ltm.month, ltm.day, ltm.hour, ltm.min, ltm.sec);
|
||||
else
|
||||
i.out << DateToStr(ltm.year, ltm.month, ltm.day);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// cannot be a const reference at the moment (PT::Space is used)
|
||||
void print_user_name(Info & i, User & user)
|
||||
{
|
||||
std::wstring * dname = user.aenv.GetValue(L"display_name");
|
||||
|
||||
if( dname && !IsWhite(*dname, true) )
|
||||
i.out << *dname;
|
||||
else
|
||||
i.out << user.name;
|
||||
}
|
||||
|
||||
|
||||
void print_user_name(Info & i, User * puser, const std::wstring & guest_name)
|
||||
{
|
||||
if( puser )
|
||||
{
|
||||
print_user_name(i, *puser);
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << "~";
|
||||
|
||||
if( !guest_name.empty() && !IsWhite(guest_name) )
|
||||
i.out << guest_name;
|
||||
else
|
||||
i.out << locale.Get(L"display_guest_name");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
Reference in New Issue
Block a user