2010-02-11 21:56:52 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2010-02-11 21:56:52 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include "templates.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/request.h"
|
2010-10-11 22:42:49 +02:00
|
|
|
#include "core/plugin.h"
|
2010-10-24 01:12:47 +02:00
|
|
|
#include "core/misc.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "functions/functions.h"
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void winix_cur_time(Info & i)
|
|
|
|
{
|
|
|
|
static char buffer[100];
|
|
|
|
|
2010-10-24 01:12:47 +02:00
|
|
|
tm rtm = Time(std::time(0));
|
2010-02-11 21:56:52 +01:00
|
|
|
|
2010-10-24 01:12:47 +02:00
|
|
|
sprintf(buffer, "%02d:%02d:%02d", rtm.tm_hour, rtm.tm_min, rtm.tm_sec);
|
2010-02-11 21:56:52 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
|
|
|
void winix_users_logged(Info & i)
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
i.out << system->users.HowManyLogged();
|
2010-02-11 21:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-16 19:34:41 +01:00
|
|
|
void winix_function(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
i.out << cur->request->function->fun.url;
|
2010-02-16 19:34:41 +01:00
|
|
|
}
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
|
|
|
void winix_function_is(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->request->function )
|
2010-02-11 21:56:52 +01:00
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
i.res = (cur->request->function->fun.url == i.par);
|
2010-02-11 21:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_function_param_is(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
i.res = cur->request->IsParam(i.par);
|
2010-02-11 21:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 05:14:26 +01:00
|
|
|
void winix_function_param_is_not(Info & i)
|
|
|
|
{
|
|
|
|
i.res = !cur->request->IsParam(i.par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-11 22:37:28 +01:00
|
|
|
void winix_function_param_value(Info & i)
|
|
|
|
{
|
|
|
|
i.out << cur->request->ParamValue(i.par);
|
|
|
|
}
|
|
|
|
|
2011-02-22 05:14:26 +01:00
|
|
|
|
2010-10-11 22:42:49 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
2010-02-13 21:12:15 +01:00
|
|
|
void winix_loadavg_now(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvgNow());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_loadavg_1(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg1());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_loadavg_5(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg5());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_loadavg_15(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg15());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_req_per_sec_now(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSecNow());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_req_per_sec_1(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec1());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
|
2010-02-13 21:12:15 +01:00
|
|
|
void winix_req_per_sec_5(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec5());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_req_per_sec_15(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec15());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
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);
|
2011-01-23 15:15:30 +01:00
|
|
|
i.res = (cur->request->status == value);
|
2010-02-28 01:08:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_err_code(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
i.out << cur->request->status;
|
2010-02-28 01:08:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void winix_is_err_in_locales(Info & i)
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
wchar_t buff[40];
|
|
|
|
size_t buff_len = sizeof(buff) / sizeof(wchar_t);
|
2010-02-28 01:08:10 +01:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
swprintf(buff, buff_len, L"winix_err_%d", cur->request->status);
|
2011-02-24 18:06:12 +01:00
|
|
|
i.res = locale.IsKey(buff);
|
2010-02-28 01:08:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_err_msg_from_locales(Info & i)
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
wchar_t buff[40];
|
|
|
|
size_t buff_len = sizeof(buff) / sizeof(wchar_t);
|
2010-02-28 01:08:10 +01:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
swprintf(buff, buff_len, L"winix_err_%d", cur->request->status);
|
2011-02-24 18:06:12 +01:00
|
|
|
i.out << locale.Get(buff);
|
2010-02-28 01:08:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-22 01:53:19 +02:00
|
|
|
void winix_show_content_in_full_window(Info & i)
|
2010-06-21 00:47:24 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->function )
|
2011-06-15 01:45:42 +02:00
|
|
|
i.res = (cur->request->function == &functions->fun_ckeditor ||
|
|
|
|
cur->request->function == &functions->fun_tinymce ||
|
|
|
|
cur->request->function == &functions->fun_nicedit ||
|
|
|
|
cur->request->function == &functions->fun_vim ||
|
2011-08-02 02:10:45 +02:00
|
|
|
cur->request->function == &functions->fun_emacs ||
|
|
|
|
cur->request->function == &functions->fun_upload );
|
2010-06-21 00:47:24 +02:00
|
|
|
}
|
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
|
2011-04-26 19:19:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the ezc function name is "false"
|
|
|
|
// ezc_functions.Insert("false", winix_false);
|
2010-11-22 02:12:46 +01:00
|
|
|
void winix_false(Info & i)
|
|
|
|
{
|
|
|
|
i.res = false;
|
|
|
|
}
|
|
|
|
|
2011-04-26 19:19:08 +02:00
|
|
|
|
|
|
|
// the ezc function name is "true"
|
|
|
|
// ezc_functions.Insert("true", winix_true);
|
2010-11-22 02:12:46 +01:00
|
|
|
void winix_true(Info & i)
|
|
|
|
{
|
|
|
|
i.res = true;
|
|
|
|
}
|
|
|
|
|
2010-02-13 21:12:15 +01:00
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
void winix_has_postvar(Info & i)
|
|
|
|
{
|
|
|
|
i.res = cur->request->IsPostVar(i.par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_postvar(Info & i)
|
|
|
|
{
|
|
|
|
i.out << cur->request->PostVar(i.par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-26 19:19:08 +02:00
|
|
|
|
|
|
|
// these functions are to be used with [is...] statements
|
|
|
|
void str(Info & i)
|
|
|
|
{
|
|
|
|
for(size_t a=0 ; a<i.params.size() ; ++a)
|
|
|
|
i.out << i.params[a];
|
|
|
|
}
|
|
|
|
|
|
|
|
void strnc(Info & i)
|
|
|
|
{
|
|
|
|
for(size_t a=0 ; a<i.params.size() ; ++a)
|
|
|
|
i.out << i.params[a];
|
|
|
|
|
|
|
|
i.case_sensitive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
} // namespace
|