201 lines
2.9 KiB
C++
Executable File
201 lines
2.9 KiB
C++
Executable File
/*
|
|
* 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;
|
|
}
|
|
|
|
|
|
|
|
void winix_users_logged(Info & i)
|
|
{
|
|
i.out << system->users.HowManyLogged();
|
|
}
|
|
|
|
|
|
void winix_function(Info & i)
|
|
{
|
|
i.out << request->function->fun.url;
|
|
}
|
|
|
|
|
|
void winix_function_is(Info & i)
|
|
{
|
|
if( !request->function )
|
|
return;
|
|
|
|
i.res = (request->function->fun.url == i.par);
|
|
}
|
|
|
|
|
|
void winix_function_param_is(Info & i)
|
|
{
|
|
i.res = request->IsParam(i.par.c_str());
|
|
}
|
|
|
|
|
|
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 = atoi( i.par.c_str() );
|
|
i.res = (request->status == value);
|
|
}
|
|
|
|
|
|
void winix_err_code(Info & i)
|
|
{
|
|
i.out << request->status;
|
|
}
|
|
|
|
|
|
|
|
static std::string winix_error_key;
|
|
|
|
|
|
void winix_is_err_in_locales(Info & i)
|
|
{
|
|
char buff[40];
|
|
|
|
sprintf(buff, "winix_err_%d", request->status);
|
|
winix_error_key = buff;
|
|
|
|
i.res = locale.IsKey(winix_error_key);
|
|
}
|
|
|
|
|
|
void winix_err_msg_from_locales(Info & i)
|
|
{
|
|
char buff[40];
|
|
|
|
sprintf(buff, "winix_err_%d", request->status);
|
|
winix_error_key = buff;
|
|
|
|
i.out << locale.Get(winix_error_key);
|
|
}
|
|
|
|
|
|
void winix_show_content_in_full_window(Info & i)
|
|
{
|
|
if( request->function )
|
|
i.res = (request->function->fun.url == "ckeditor" || request->function->fun.url == "tinymce");
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|