winix/templates/winix.cpp

223 lines
3.3 KiB
C++
Raw Normal View History

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <ctime>
#include "templates.h"
#include "core/request.h"
#include "core/plugin.h"
#include "core/misc.h"
#include "functions/functions.h"
namespace TemplatesFunctions
{
void winix_cur_time(Info & i)
{
static char buffer[100];
tm rtm = Time(std::time(0));
sprintf(buffer, "%02d:%02d:%02d", rtm.tm_hour, rtm.tm_min, rtm.tm_sec);
i.out << buffer;
}
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 winix_how_many_sessions(Info & i)
{
i.out << session_manager->Size();
}
void winix_users_logged(Info & i)
{
i.out << system->users.HowManyLogged();
}
void winix_function(Info & i)
{
i.out << cur->request->function->fun.url;
}
void winix_function_is(Info & i)
{
if( !cur->request->function )
return;
i.res = (cur->request->function->fun.url == i.par);
}
void winix_function_param_is(Info & i)
{
i.res = cur->request->IsParam(i.par);
}
void winix_function_param_value(Info & i)
{
i.out << cur->request->ParamValue(i.par);
}
void winix_has_plugin(Info & i)
{
size_t exist = 0;
if( i.params.empty() )
return;
for(size_t a=0 ; a<i.params.size() ; ++a)
{
if( plugin.HasPlugin(i.params[a]) )
++exist;
}
i.res = (exist == i.params.size());
}
void winix_loadavg_now(Info & i)
{
char buf[20];
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvgNow());
i.out << buf;
}
void winix_loadavg_1(Info & i)
{
char buf[20];
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg1());
i.out << buf;
}
void winix_loadavg_5(Info & i)
{
char buf[20];
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg5());
i.out << buf;
}
void winix_loadavg_15(Info & i)
{
char buf[20];
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg15());
i.out << buf;
}
void winix_req_per_sec_now(Info & i)
{
char buf[20];
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSecNow());
i.out << buf;
}
void winix_req_per_sec_1(Info & i)
{
char buf[20];
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec1());
i.out << buf;
}
void winix_req_per_sec_5(Info & i)
{
char buf[20];
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec5());
i.out << buf;
}
void winix_req_per_sec_15(Info & i)
{
char buf[20];
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec15());
i.out << buf;
}
void winix_err_is(Info & i)
{
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
int value = Toi(i.par);
i.res = (cur->request->status == value);
}
void winix_err_code(Info & i)
{
i.out << cur->request->status;
}
static std::wstring winix_error_key;
void winix_is_err_in_locales(Info & i)
{
wchar_t buff[40];
size_t buff_len = sizeof(buff) / sizeof(wchar_t);
swprintf(buff, buff_len, L"winix_err_%d", cur->request->status);
winix_error_key = buff;
i.res = locale.IsKey(winix_error_key);
}
void winix_err_msg_from_locales(Info & i)
{
wchar_t buff[40];
size_t buff_len = sizeof(buff) / sizeof(wchar_t);
swprintf(buff, buff_len, L"winix_err_%d", cur->request->status);
winix_error_key = buff;
i.out << locale.Get(winix_error_key);
}
void winix_show_content_in_full_window(Info & i)
{
if( cur->request->function )
i.res = (cur->request->function == &functions->fun_ckeditor || cur->request->function == &functions->fun_tinymce);
}
void winix_false(Info & i)
{
i.res = false;
}
void winix_true(Info & i)
{
i.res = true;
}
} // namespace