415 lines
6.4 KiB
C++
Executable File
415 lines
6.4 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2012, 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_account_need_email_verification(Info & i)
|
|
{
|
|
i.res = config->account_need_email_verification;
|
|
}
|
|
|
|
|
|
void winix_cur_time(Info & i)
|
|
{
|
|
static char buffer[100];
|
|
|
|
PT::Date & date = cur->request->start_date;
|
|
|
|
sprintf(buffer, "%02d:%02d:%02d", date.hour, date.min, date.sec);
|
|
i.out << buffer;
|
|
}
|
|
|
|
|
|
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_is_not(Info & i)
|
|
{
|
|
i.res = !cur->request->IsParam(i.par);
|
|
}
|
|
|
|
|
|
void winix_function_param_value(Info & i)
|
|
{
|
|
i.out << cur->request->ParamValue(i.par);
|
|
}
|
|
|
|
|
|
// first parameter is param_name
|
|
// second parameter is param_value
|
|
void winix_function_param_value_is(Info & i)
|
|
{
|
|
if( i.params.size() == 2 )
|
|
i.res = (cur->request->ParamValue(i.params[0]) == i.params[1]);
|
|
}
|
|
|
|
|
|
void winix_function_param_value_is_not(Info & i)
|
|
{
|
|
if( i.params.size() == 2 )
|
|
i.res = (cur->request->ParamValue(i.params[0]) != i.params[1]);
|
|
}
|
|
|
|
|
|
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)
|
|
{
|
|
int value = Toi(i.par);
|
|
i.res = (cur->request->status == value);
|
|
}
|
|
|
|
|
|
void winix_err_code(Info & i)
|
|
{
|
|
i.out << cur->request->status;
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
i.res = locale.IsKey(buff);
|
|
}
|
|
|
|
|
|
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);
|
|
i.out << locale.Get(buff);
|
|
}
|
|
|
|
|
|
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 ||
|
|
cur->request->function == &functions->fun_nicedit ||
|
|
cur->request->function == &functions->fun_vim ||
|
|
cur->request->function == &functions->fun_emacs ||
|
|
cur->request->function == &functions->fun_upload );
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the ezc function name is "false"
|
|
// ezc_functions.Insert("false", winix_false);
|
|
void winix_false(Info & i)
|
|
{
|
|
i.res = false;
|
|
}
|
|
|
|
|
|
// the ezc function name is "true"
|
|
// ezc_functions.Insert("true", winix_true);
|
|
void winix_true(Info & i)
|
|
{
|
|
i.res = true;
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
// first parameter is param_name
|
|
// second parameter is param_value
|
|
void winix_postvar_value_is(Info & i)
|
|
{
|
|
if( i.params.size() == 2 )
|
|
i.res = (cur->request->PostVar(i.params[0]) == i.params[1]);
|
|
}
|
|
|
|
|
|
void winix_postvar_value_is_not(Info & i)
|
|
{
|
|
if( i.params.size() == 2 )
|
|
i.res = (cur->request->PostVar(i.params[0]) != i.params[1]);
|
|
}
|
|
|
|
|
|
void winix_subdomain(Info & i)
|
|
{
|
|
i.out << cur->request->subdomain;
|
|
}
|
|
|
|
|
|
void winix_subdomain_is_empty(Info & i)
|
|
{
|
|
i.res = cur->request->subdomain.empty();
|
|
}
|
|
|
|
|
|
void winix_subdomain_is_not_empty(Info & i)
|
|
{
|
|
i.res = !cur->request->subdomain.empty();
|
|
}
|
|
|
|
void winix_subdomain_is(Info & i)
|
|
{
|
|
i.res = cur->request->subdomain == i.par;
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
}
|
|
|
|
|
|
|
|
|
|
static size_t tz_index;
|
|
|
|
void winix_tz_tab(Info & i)
|
|
{
|
|
tz_index = i.iter;
|
|
|
|
i.res = tz_index < system->time_zones.Size();
|
|
}
|
|
|
|
|
|
void winix_tz_tab_id(Info & i)
|
|
{
|
|
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
|
|
|
if( tz )
|
|
i.out << tz->id;
|
|
}
|
|
|
|
|
|
void winix_tz_tab_name(Info & i)
|
|
{
|
|
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
|
|
|
if( tz )
|
|
i.out << locale.Get(tz->name);
|
|
}
|
|
|
|
|
|
void winix_tz_tab_offset_sec(Info & i)
|
|
{
|
|
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
|
|
|
if( tz )
|
|
i.out << tz->offset;
|
|
}
|
|
|
|
|
|
void winix_tz_tab_offset_hour_min(Info & i)
|
|
{
|
|
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
|
|
|
if( tz )
|
|
{
|
|
time_t offset = tz->offset;
|
|
|
|
if( offset < 0 )
|
|
{
|
|
i.out << '-';
|
|
offset = -offset;
|
|
}
|
|
else
|
|
{
|
|
i.out << '+';
|
|
}
|
|
|
|
print_hour_min(i, offset);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static size_t locale_id;
|
|
|
|
void winix_locale_tab(Info & i)
|
|
{
|
|
locale_id = i.iter;
|
|
i.res = locale_id < locale.Size();
|
|
}
|
|
|
|
|
|
void winix_locale_tab_id(Info & i)
|
|
{
|
|
if( locale_id < locale.Size() )
|
|
i.out << Toi(locale.GetByIndex(L"winix_locale_id", locale_id, false));
|
|
}
|
|
|
|
|
|
void winix_locale_tab_name(Info & i)
|
|
{
|
|
if( locale_id < locale.Size() )
|
|
i.out << locale.GetByIndex(L"locale_name", locale_id, false);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|