fc8ffc | 2017-05-23 | Pontus Östlund | | #include <config_interface.h>
|
dd2f1d | 1999-11-17 | Per Hedbor | | #include <config.h>
#include <roxen.h>
|
cf2dec | 2000-07-11 | Martin Nilsson | |
|
23414a | 2000-07-21 | Andreas Lange | |
|
fc8ffc | 2017-05-23 | Pontus Östlund | | #define LOCALE(X,Y) _STR_LOCALE("roxen_config",X,Y)
#define CALL(X,Y) _LOCALE_FUN("roxen_config",X,Y)
|
cf2dec | 2000-07-11 | Martin Nilsson | |
|
dd2f1d | 1999-11-17 | Per Hedbor | | int __lt;
string describe_time(int t)
{
int full;
if(localtime(__lt)->yday != localtime(t)->yday)
{
__lt = t;
full=1;
}
if(full)
|
b9a702 | 2000-07-15 | Andreas Lange | | return capitalize(roxen->language(roxen.locale->get(),"date")(t));
|
dd2f1d | 1999-11-17 | Per Hedbor | | else
return sprintf("%02d:%02d",localtime(t)->hour,localtime(t)->min);
}
|
3e3bab | 2001-01-19 | Per Hedbor | | string _units(string unit, int num)
{
|
715d3c | 2000-07-11 | Martin Nilsson | | if(num==1) return "one "+unit;
return num+" "+unit+"s";
}
|
dd2f1d | 1999-11-17 | Per Hedbor | | string describe_interval(int i)
{
|
715d3c | 2000-07-11 | Martin Nilsson | | switch(i) {
case 0..50:
|
1c783c | 2000-07-15 | Andreas Lange | | return CALL("units", _units)("second", i);
|
715d3c | 2000-07-11 | Martin Nilsson | | case 51..3560:
|
1c783c | 2000-07-15 | Andreas Lange | | return CALL("units", _units)("minute", ((i+20)/60));
|
715d3c | 2000-07-11 | Martin Nilsson | | default:
|
1c783c | 2000-07-15 | Andreas Lange | | return CALL("units", _units)("hour", ((i+300)/3600));
|
dd2f1d | 1999-11-17 | Per Hedbor | | }
}
string describe_times(array (int) times)
{
__lt=0;
if(sizeof(times) < 6)
|
3e3bab | 2001-01-19 | Per Hedbor | | return String.implode_nicely(map(times, describe_time),
|
fc8ffc | 2017-05-23 | Pontus Östlund | | LOCALE("cw", "and"));
|
dd2f1d | 1999-11-17 | Per Hedbor | |
int d, every=1;
int ot = times[0];
foreach(times[1..], int t)
if(d)
{
if(abs(t-ot-d)>(d/4))
{
|
fc8ffc | 2017-05-23 | Pontus Östlund | | every=0;
break;
|
dd2f1d | 1999-11-17 | Per Hedbor | | }
ot=t;
} else
d = t-ot;
if(every && (times[-1]+d) >= time(1)-10)
|
23414a | 2000-07-21 | Andreas Lange | | return (LOCALE(207, "every") +" "
|
fc8ffc | 2017-05-23 | Pontus Östlund | | +describe_interval(d)+" "+LOCALE(208, "since")+" "+
describe_time(times[0]));
|
dd2f1d | 1999-11-17 | Per Hedbor | | return String.implode_nicely(map(times[..4], describe_time)+({"..."})+
|
fc8ffc | 2017-05-23 | Pontus Östlund | | map(times[sizeof(times)-3..], describe_time),
LOCALE("cw", "and"));
|
dd2f1d | 1999-11-17 | Per Hedbor | | }
string fix_err(string s)
{
sscanf(reverse(s), "%*[ \t\n]%s", s);
s=reverse(s);
if(s=="")
return s;
if(!(<'.','!','?'>)[s[-1]]) s+=".";
|
715d3c | 2000-07-11 | Martin Nilsson | | return Roxen.html_encode_string(capitalize(s));
|
dd2f1d | 1999-11-17 | Per Hedbor | | }
|
fc8ffc | 2017-05-23 | Pontus Östlund | |
constant logitem_tmpl = #"
<ul class='logitem'>
<li class='err-{{ code }}' title='{{ code_text }}'>
{{ &links }}
{{ #times }}<span class='times'>{{ times }}</span><br>{{ /times }}
{{ &message }}
</li>
</ul>";
|
dd2f1d | 1999-11-17 | Per Hedbor | | int last_time;
|
c60cae | 2000-02-02 | Johan Sundström | | string describe_error(string err, array (int) times,
|
fc8ffc | 2017-05-23 | Pontus Östlund | | string lang, int|void no_links)
|
dd2f1d | 1999-11-17 | Per Hedbor | | {
int code, nt;
|
c60cae | 2000-02-02 | Johan Sundström | | string links = "", reference, server;
|
23414a | 2000-07-21 | Andreas Lange | | array(string) codetext=({ LOCALE(209, "Notice"),
|
fc8ffc | 2017-05-23 | Pontus Östlund | | LOCALE(210, "Warning"),
LOCALE(211, "Error") });
|
c60cae | 2000-02-02 | Johan Sundström | |
|
dd2f1d | 1999-11-17 | Per Hedbor | | if(sizeof(times)==1 && times[0]/60==last_time) nt=1;
last_time=times[0]/60;
|
c60cae | 2000-02-02 | Johan Sundström | | sscanf(err, "%d,%[^,],%s", code, reference, err);
|
fc8ffc | 2017-05-23 | Pontus Östlund | |
|
c60cae | 2000-02-02 | Johan Sundström | | switch(no_links)
{
Configuration conf;
RoxenModule module;
case 2:
sscanf(reference, "%[^/]", server);
if(conf = roxen->find_configuration( server ))
|
fc8ffc | 2017-05-23 | Pontus Östlund | | links += sprintf("<a href=\"%s\">%s</a> : ",
@get_conf_url_to_virtual_server( conf, lang ));
|
c60cae | 2000-02-02 | Johan Sundström | | case 1:
|
715d3c | 2000-07-11 | Martin Nilsson | | if(module = Roxen.get_module( reference ))
|
fc8ffc | 2017-05-23 | Pontus Östlund | | links += sprintf("<a href=\"%s\">%s</a> : ",
@get_conf_url_to_module( module, lang ));
|
c60cae | 2000-02-02 | Johan Sundström | | }
|
fc8ffc | 2017-05-23 | Pontus Östlund | | mapping mctx = ([
"code" : code,
"code_text" : codetext[code-1],
"links" : links,
"times" : nt ? 0 : describe_times(times),
"message" : replace(fix_err(err), "\n", "<br />\n")
]);
|
bf66c3 | 2018-02-28 | Pontus Östlund | | string out = Roxen.render_mustache(logitem_tmpl, mctx);
|
fc8ffc | 2017-05-23 | Pontus Östlund | |
return out;
|
c60cae | 2000-02-02 | Johan Sundström | | }
|
3e3bab | 2001-01-19 | Per Hedbor | | array(string) get_conf_url_to_module(string|RoxenModule m, string|void lang)
{
|
c60cae | 2000-02-02 | Johan Sundström | |
|
715d3c | 2000-07-11 | Martin Nilsson | | RoxenModule module = stringp(m) ? Roxen.get_module(m) : m;
|
c60cae | 2000-02-02 | Johan Sundström | | Configuration conf = module->my_configuration();
string url_modname = replace(conf->otomod[module], "#", "!"),
|
fc8ffc | 2017-05-23 | Pontus Östlund | | url_confname = conf->name;
|
c60cae | 2000-02-02 | Johan Sundström | |
|
e1fff7 | 2016-01-15 | Henrik Grubbström (Grubba) | | return ({ sprintf("/sites/site.html/%s/-!-/%s/?section=Information&&usr.set-wiz-id;",
|
fc8ffc | 2017-05-23 | Pontus Östlund | | Roxen.http_encode_url(url_confname),
Roxen.http_encode_url(url_modname)),
Roxen.html_encode_string(Roxen.get_modfullname(module)) });
|
c60cae | 2000-02-02 | Johan Sundström | | }
|
3e3bab | 2001-01-19 | Per Hedbor | | array(string) get_conf_url_to_virtual_server(string|Configuration conf,
|
fc8ffc | 2017-05-23 | Pontus Östlund | | string|void lang)
|
3e3bab | 2001-01-19 | Per Hedbor | | {
|
c60cae | 2000-02-02 | Johan Sundström | | string url_confname;
if(stringp(conf))
conf = roxen->find_configuration(url_confname = conf);
else
url_confname = conf->name;
|
fc8ffc | 2017-05-23 | Pontus Östlund | | return ({ sprintf("/sites/site.html/%s/",
Roxen.http_encode_url(url_confname)),
Roxen.html_encode_string(conf->query_name()) });
|
dd2f1d | 1999-11-17 | Per Hedbor | | }
|
9d477e | 2001-05-16 | Per Hedbor | |
|