ebdb65 | 2000-01-14 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | |
#define _stat id->misc->defines[" _stat"]
#define _error id->misc->defines[" _error"]
#define _extra_heads id->misc->defines[" _extra_heads"]
#define _rettext id->misc->defines[" _rettext"]
#define _ok id->misc->defines[" _ok"]
|
ecab8b | 2000-01-23 | Martin Nilsson | | constant cvs_version="$Id: rxmltags.pike,v 1.44 2000/01/23 03:01:41 nilsson Exp $";
|
481740 | 1999-08-13 | Martin Nilsson | | constant thread_safe=1;
|
bfd5fb | 1999-10-08 | Martin Nilsson | | constant language = roxen->language;
|
481740 | 1999-08-13 | Martin Nilsson | |
#include <module.h>
inherit "module";
inherit "roxenlib";
|
0be641 | 2000-01-18 | Martin Nilsson | | constant module_type = MODULE_PARSER | MODULE_PROVIDER;
constant module_name = "RXML 1.4 tags";
constant module_doc = "This module adds a lot of RXML tags.";
|
16509b | 1999-12-14 | Martin Nilsson | | void create()
|
481740 | 1999-08-13 | Martin Nilsson | | {
defvar("insert_href",1,"Allow <insert href>.",
TYPE_FLAG|VAR_MORE,
"Should the usage of <insert href> be allowed?");
}
|
16509b | 1999-12-14 | Martin Nilsson | | void start()
|
659d4b | 1999-10-18 | Martin Nilsson | | {
|
ecab8b | 2000-01-23 | Martin Nilsson | | add_api_function("query_modified", api_query_modified, ({ "string" }));
|
0be641 | 2000-01-18 | Martin Nilsson | | query_tag_set()->prepare_context=set_entities;
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
b7e95b | 1999-12-14 | Martin Nilsson | | string query_provides() {
return "modified";
}
TAGDOCUMENTATION;
|
cfe42b | 1999-12-07 | Martin Nilsson | | #ifdef manual
constant tagdoc=(["roxen-automatic-charset-variable":"<desc tag></desc>",
|
885935 | 1999-11-25 | Martin Nilsson | | "append":"<desc tag></desc>",
"auth-required":"<desc tag></desc>",
"expire-time":"<desc tag></desc>",
"header":"<desc tag></desc>",
"redirect":"<desc tag></desc>",
"unset":"<desc tag></desc>",
"set":"<desc tag></desc>",
"quote":"<desc tag></desc>",
"inc":"<desc tag></desc>",
"dec":"<desc tag></desc>",
"imgs":"<desc tag></desc>",
"roxen":"<desc tag></desc>",
"debug":"<desc tag></desc>",
"fsize":"<desc tag></desc>",
"configimage":"<desc tag></desc>",
"date":"<desc tag></desc>",
"insert":"<desc tag></desc>",
"configurl":"<desc tag></desc>",
"return":"<desc tag></desc>",
"set-cookie":"<desc tag></desc>",
"remove-cookie":"<desc tag></desc>",
"modified":"<desc tag></desc>",
"user":"<desc tag></desc>",
"set-max-cache":"<desc tag></desc>",
"scope":"<desc cont></desc>",
"catch":"<desc cont></desc>",
"cache":"<desc cont></desc>",
"crypt":"<desc cont></desc>",
"for":"<desc cont></desc>",
"foreach":"<desc cont></desc>",
"apre":"<desc cont></desc>",
"aconf":"<desc cont></desc>",
"maketag":"<desc cont></desc>",
"doc":"<desc cont></desc>",
"autoformat":"<desc cont></desc>",
"smallcaps":"<desc cont></desc>",
"random":"<desc cont></desc>",
"formoutput":"<desc cont></desc>",
"gauge":"<desc cont></desc>",
"trimlines":"<desc cont></desc>",
"throw":"<desc cont></desc>",
"default":"<desc cont></desc>",
"sort":"<desc cont></desc>",
"recursive-output":"<desc cont></desc>",
"repeat":"<desc cont></desc>",
"replace":"<desc cont></desc>",
"cset":"<desc cont></desc>"
|
cfe42b | 1999-12-07 | Martin Nilsson | | ]);
#endif
|
885935 | 1999-11-25 | Martin Nilsson | |
constant permitted = "123456789xabcdefnt\"XABCDEFlo<>=0-*+/%%|()"/"";
|
481740 | 1999-08-13 | Martin Nilsson | |
string sexpr_eval(string what)
{
array q = what/"";
what = "mixed foo(){ return "+(q-(q-permitted))*""+";}";
return (string)compile_string( what )()->foo();
}
|
b53b75 | 1999-10-09 | Martin Nilsson | |
|
0be641 | 2000-01-18 | Martin Nilsson | |
class Entity_page_realfile {
string rxml_var_eval(RXML.Context c) { return c->id->realfile||""; }
}
|
ecab8b | 2000-01-23 | Martin Nilsson | | class Entity_page_virtroot {
|
0be641 | 2000-01-18 | Martin Nilsson | | string rxml_var_eval(RXML.Context c) { return c->id->virtfile||""; }
}
|
ecab8b | 2000-01-23 | Martin Nilsson | | class Entity_page_virtfile {
string rxml_var_eval(RXML.Context c) { return c->id->not_query; }
}
|
c6b6c9 | 2000-01-21 | Martin Nilsson | | class Entity_page_url {
|
0be641 | 2000-01-18 | Martin Nilsson | | string rxml_var_eval(RXML.Context c) { return c->id->raw_url; }
}
|
c6b6c9 | 2000-01-21 | Martin Nilsson | | class Entity_page_last_true {
|
0be641 | 2000-01-18 | Martin Nilsson | | int rxml_var_eval(RXML.Context c) { return c->id->misc->defines[" _ok"]; }
}
class Entity_page_language {
|
c6b6c9 | 2000-01-21 | Martin Nilsson | | string rxml_var_eval(RXML.Context c) { return c->id->misc->defines->language || ""; }
|
0be641 | 2000-01-18 | Martin Nilsson | | }
|
ecab8b | 2000-01-23 | Martin Nilsson | | class Entity_page_scope {
string rxml_var_eval(RXML.Context c) { return c->current_scope()||""; }
}
|
0be641 | 2000-01-18 | Martin Nilsson | | mapping page_scope=(["realfile":Entity_page_realfile(),
|
ecab8b | 2000-01-23 | Martin Nilsson | | "virtroot":Entity_page_virtroot(),
"virtfile":Entity_page_virtfile(),
|
c6b6c9 | 2000-01-21 | Martin Nilsson | | "url":Entity_page_url(),
"last_true":Entity_page_last_true(),
|
ecab8b | 2000-01-23 | Martin Nilsson | | "language":Entity_page_language(),
"scope":Entity_page_scope() ]);
|
0be641 | 2000-01-18 | Martin Nilsson | |
|
ecab8b | 2000-01-23 | Martin Nilsson | | class Entity_client_referrer {
string rxml_var_eval(RXML.Context c) {
c->id->misc->cacheable=0;
return c->id->referer?c->id->referer[0]:"";
}
|
0be641 | 2000-01-18 | Martin Nilsson | | }
|
c6b6c9 | 2000-01-21 | Martin Nilsson | | class Entity_client_name {
|
ecab8b | 2000-01-23 | Martin Nilsson | | string rxml_var_eval(RXML.Context c) {
c->id->misc->cacheable=0;
return c->id->client?c->id->client[0]:"";
}
|
0be641 | 2000-01-18 | Martin Nilsson | | }
|
c6481f | 2000-01-21 | Martin Nilsson | | class Entity_client_ip {
|
ecab8b | 2000-01-23 | Martin Nilsson | | string rxml_var_eval(RXML.Context c) {
c->id->misc->cacheable=0;
return c->id->remoteaddr;
}
}
class Entity_client_accept_language {
string rxml_var_eval(RXML.Context c) {
c->id->misc->cacheable=0;
if(!c->id->misc["accept-language"]) return "";
return c->id->misc["accept-language"][0];
}
}
class Entity_client_accept_languages {
string rxml_var_eval(RXML.Context c) {
c->id->misc->cacheable=0;
if(!c->id->misc["accept-language"]) return "";
return c->id->misc["accept-language"]*",";
}
|
0be641 | 2000-01-18 | Martin Nilsson | | }
|
c6481f | 2000-01-21 | Martin Nilsson | | mapping client_scope=([ "ip":Entity_client_ip(),
|
c6b6c9 | 2000-01-21 | Martin Nilsson | | "name":Entity_client_name(),
|
ecab8b | 2000-01-23 | Martin Nilsson | | "referrer":Entity_client_referrer(),
"accept_language":Entity_client_accept_language(),
"accept_languages":Entity_client_accept_languages()]);
|
0be641 | 2000-01-18 | Martin Nilsson | |
void set_entities(RXML.Context c) {
|
c6b6c9 | 2000-01-21 | Martin Nilsson | | c->extend_scope("page", page_scope);
c->extend_scope("client", client_scope);
|
0be641 | 2000-01-18 | Martin Nilsson | | }
|
481740 | 1999-08-13 | Martin Nilsson | |
|
bcde6c | 1999-11-19 | Per Hedbor | | string tag_roxen_automatic_charset_variable( string t, mapping m,
RequestID id )
{
return make_tag( "input",
([
"type":"hidden",
"name":"magic_roxen_automatic_charset_variable",
"value":"åäö",
]) );
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_append( string tag, mapping m, RequestID id )
|
481740 | 1999-08-13 | Martin Nilsson | | {
if (m->variable)
{
|
ecab8b | 2000-01-23 | Martin Nilsson | | RXML.Context context=RXML.get_context();
mixed value=context->user_get_var(m->variable, m->scope);
if (m->value) {
if (value)
value+=m->value;
|
481740 | 1999-08-13 | Martin Nilsson | | else
|
ecab8b | 2000-01-23 | Martin Nilsson | | value=m->value;
context->user_set_var(m->variable, value, m->scope);
return "";
}
if (m->from) {
mixed from=context->user_get_var(m->from, m->scope);
if(!from) return rxml_error(tag, "From variable doesn't exist.", id);
if (value)
value+=from;
|
481740 | 1999-08-13 | Martin Nilsson | | else
|
ecab8b | 2000-01-23 | Martin Nilsson | | value=from;
context->user_set_var(m->variable, value, m->scope);
return "";
}
if (m->other) {
if (!id->misc->variables || !id->misc->variables[ m->other ])
|
d93f83 | 1999-09-17 | Martin Nilsson | | return rxml_error(tag, "Other variable doesn't exist.", id);
|
ecab8b | 2000-01-23 | Martin Nilsson | | if (value)
value+=id->misc->variables[ m->other ];
else
value=id->misc->variables[ m->other ];
context->user_set_var(m->variable, value, m->scope);
return "";
}
return rxml_error(tag, "No value specified.", id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
return rxml_error(tag, "Nothing to append from.", id);
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_auth_required (string tagname, mapping args, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
mapping hdrs = http_auth_required (args->realm, args->message);
if (hdrs->error) _error = hdrs->error;
|
659d4b | 1999-10-18 | Martin Nilsson | | if (hdrs->extra_heads)
_extra_heads += hdrs->extra_heads;
|
ecab8b | 2000-01-23 | Martin Nilsson | |
|
659d4b | 1999-10-18 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | | if (hdrs->text) _rettext = hdrs->text;
return "";
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_expire_time(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
int t=time();
if(!m->now)
{
|
659d4b | 1999-10-18 | Martin Nilsson | | t+=time_dequantifier(m);
|
481740 | 1999-08-13 | Martin Nilsson | | CACHE(max(t-time(),0));
} else {
NOCACHE();
|
bfd5fb | 1999-10-08 | Martin Nilsson | | add_http_header(_extra_heads, "Pragma", "no-cache");
add_http_header(_extra_heads, "Cache-Control", "no-cache");
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
bfd5fb | 1999-10-08 | Martin Nilsson | | add_http_header(_extra_heads, "Expires", http_date(t));
|
481740 | 1999-08-13 | Martin Nilsson | | return "";
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_header(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
if(m->name == "WWW-Authenticate")
{
string r;
if(m->value)
{
if(!sscanf(m->value, "Realm=%s", r))
r=m->value;
|
659d4b | 1999-10-18 | Martin Nilsson | | } else
|
481740 | 1999-08-13 | Martin Nilsson | | r="Users";
m->value="basic realm=\""+r+"\"";
} else if(m->name=="URI")
m->value = "<" + m->value + ">";
|
659d4b | 1999-10-18 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | | if(!(m->value && m->name))
return rxml_error(tag, "Requires both a name and a value.", id);
|
bfd5fb | 1999-10-08 | Martin Nilsson | | add_http_header(_extra_heads, m->name, m->value);
|
481740 | 1999-08-13 | Martin Nilsson | | return "";
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_redirect(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
049148 | 1999-09-11 | Martin Stjernholm | | if (!(m->to && sizeof (m->to)))
|
481740 | 1999-08-13 | Martin Nilsson | | return rxml_error(tag, "Requires attribute \"to\".", id);
multiset(string) orig_prestate = id->prestate;
multiset(string) prestate = (< @indices(orig_prestate) >);
if(m->add) {
foreach((m->add-" ")/",", string s)
prestate[s]=1;
m_delete(m,"add");
}
if(m->drop) {
foreach((m->drop-" ")/",", string s)
prestate[s]=0;
m_delete(m,"drop");
}
id->prestate = prestate;
mapping r = http_redirect(m->to, id);
id->prestate = orig_prestate;
if (r->error)
_error = r->error;
if (r->extra_heads)
|
659d4b | 1999-10-18 | Martin Nilsson | | _extra_heads += r->extra_heads;
|
481740 | 1999-08-13 | Martin Nilsson | | if (m->text)
_rettext = m->text;
return "";
}
|
1c7945 | 1999-10-17 | Martin Nilsson | | string tag_unset(string tag, mapping m, RequestID id) {
|
ecab8b | 2000-01-23 | Martin Nilsson | | if(!m->variable && !m->scope)
return rxml_error(tag, "Variable not specified.", id);
if(!m->variable && m->scope!="roxen") {
RXML.get_context()->add_scope(m->scope, ([]) );
return "";
}
RXML.get_context()->user_delete_var(m->variable, m->scope);
|
1c7945 | 1999-10-17 | Martin Nilsson | | return "";
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_set( string tag, mapping m, RequestID id )
|
481740 | 1999-08-13 | Martin Nilsson | | {
if (m->variable)
{
|
ecab8b | 2000-01-23 | Martin Nilsson | | RXML.Context context=RXML.get_context();
if (m->value) {
context->user_set_var(m->variable, m->value, m->scope);
return "";
}
if (m->expr) {
context->user_set_var(m->variable, sexpr_eval(m->expr), m->scope);
return "";
}
if (m->from) {
mixed from=context->user_get_var(m->from, m->scope);
if(!from) return rxml_error(tag, "From variable doesn't exist.", id);
context->user_set_var(m->variable, from, m->scope);
return "";
}
if (m->other) {
if (id->misc->variables && id->misc->variables[ m->other ]) {
context->user_set_var(m->variable, (string)id->misc->variables[m->other], m->scope);
return "";
}
return rxml_error(tag, "Other variable doesn't exist.", id);
}
if (m->eval) {
context->user_set_var(m->variable, parse_rxml(m->eval, id), m->scope);
return "";
}
|
481740 | 1999-08-13 | Martin Nilsson | |
|
ecab8b | 2000-01-23 | Martin Nilsson | | return rxml_error(tag, "No value specified.", id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
d93f83 | 1999-09-17 | Martin Nilsson | | return rxml_error(tag, "Variable not specified.", id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
string tag_quote(string tagname, mapping m)
{
#if efun(set_start_quote)
if(m->start && strlen(m->start))
set_start_quote(m->start[0]);
if(m->end && strlen(m->end))
set_end_quote(m->end[0]);
#endif
return "";
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_inc(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
ecab8b | 2000-01-23 | Martin Nilsson | | if(!m->variable) return rxml_error(tag, "No variable to increment.", id);
RXML.Context context=RXML.get_context();
array entity=context->parse_user_var(m->variable, m->scope);
if(!context->exist_scope(entity[0])) return rxml_error(tag, "Scope "+entity[0]+" does not exist.", id);
int val=(int)m->value||1;
context->user_set_var(m->variable, (int)context->user_get_var(m->variable, m->scope)+val, m->scope);
return "";
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | string tag_dec(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
ecab8b | 2000-01-23 | Martin Nilsson | | m->value=-(int)m->value||-1;
return tag_inc(tag, m, id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | string|array(string) tag_imgs(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
string tmp="";
if(m->src)
{
string file;
if(file=id->conf->real_file(fix_relative(m->src, id), id))
{
array(int) xysize;
if(xysize=Dims.dims()->get(file))
{
m->width=(string)xysize[0];
m->height=(string)xysize[1];
}
|
659d4b | 1999-10-18 | Martin Nilsson | | else
tmp+=" Dimensions quering failed.";
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
659d4b | 1999-10-18 | Martin Nilsson | | else
tmp+=" Virtual path failed";
|
481740 | 1999-08-13 | Martin Nilsson | | if(!m->alt) {
array src=m->src/"/";
string src=src[sizeof(src)-1];
m->alt=String.capitalize(replace(src[..sizeof(src)-search(reverse(src),".")-2],"_"," "));
}
|
ca6ea2 | 1999-10-03 | Johan Sundström | | return ({ make_tag("img", m)+(tmp?rxml_error(tag, tmp, id):"") });
|
481740 | 1999-08-13 | Martin Nilsson | | }
return rxml_error(tag, "No src given.", id);
}
|
989745 | 1999-10-10 | Per Hedbor | | array(string) tag_roxen(string tagname, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
string size = m->size || "small";
string color = m->color || "blue";
m_delete(m, "color");
m_delete(m, "size");
m->src = "/internal-roxen-power-"+size+"-"+color;
m->width = (["small":"100","medium":"200","large":"300"])[size];
m->height = (["small":"35","medium":"60","large":"90"])[size];
if(!m->alt) m->alt="Powered by Roxen";
if(!m->border) m->border="0";
|
ca6ea2 | 1999-10-03 | Johan Sundström | | return ({ "<a href=\"http://www.roxen.com/\">"+make_tag("img", m)+"</a>" });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
c4d2a5 | 2000-01-03 | Martin Nilsson | | string|array(string) tag_debug( string tag_name, mapping m, RequestID id )
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
c4d2a5 | 2000-01-03 | Martin Nilsson | | if (m->showid)
|
989745 | 1999-10-10 | Per Hedbor | | {
|
c4d2a5 | 2000-01-03 | Martin Nilsson | | array path=lower_case(m->showid)/"->";
|
481740 | 1999-08-13 | Martin Nilsson | | if(path[0]!="id" || sizeof(path)==1) return "Can only show parts of the id object.";
mixed obj=id;
foreach(path[1..], string tmp) {
if(search(indices(obj),tmp)==-1) return "Could only reach "+tmp+".";
obj=obj[tmp];
}
|
989745 | 1999-10-10 | Per Hedbor | | return ({ "<pre>"+html_encode_string(sprintf("%O",obj))+"</pre>" });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
c4d2a5 | 2000-01-03 | Martin Nilsson | | if (m->off)
|
481740 | 1999-08-13 | Martin Nilsson | | id->misc->debug = 0;
|
c4d2a5 | 2000-01-03 | Martin Nilsson | | else if (m->toggle)
|
481740 | 1999-08-13 | Martin Nilsson | | id->misc->debug = !id->misc->debug;
else
id->misc->debug = 1;
return "<!-- Debug is "+(id->misc->debug?"enabled":"disabled")+" -->";
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_fsize(string tag, mapping args, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
ebdb65 | 2000-01-14 | Martin Nilsson | | if(args->file) {
catch {
array s = id->conf->stat_file( fix_relative( args->file, id ), id );
if (s && (s[1]>= 0)) return (string)s[1];
};
if(string s=id->conf->try_get_file(fix_relative(args->file, id), id ) )
return (string)strlen(s);
}
|
481740 | 1999-08-13 | Martin Nilsson | | return rxml_error(tag, "Failed to find file", id);
}
|
16509b | 1999-12-14 | Martin Nilsson | | array(string)|string tag_configimage(string t, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
16509b | 1999-12-14 | Martin Nilsson | | if (!m->src) return rxml_error(t, "No src given", id);
|
481740 | 1999-08-13 | Martin Nilsson | |
|
692e71 | 1999-12-12 | Martin Nilsson | | if (m->src[sizeof(m->src)-4..][0] == '.')
m->src = m->src[..sizeof(m->src)-5];
|
481740 | 1999-08-13 | Martin Nilsson | |
m->alt = m->alt || m->src;
|
692e71 | 1999-12-12 | Martin Nilsson | | m->src = "/internal-roxen-" + m->src;
m->border = m->border || "0";
|
481740 | 1999-08-13 | Martin Nilsson | |
|
ca6ea2 | 1999-10-03 | Johan Sundström | | return ({ make_tag("img", m) });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | string tag_date(string q, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
int t=(int)m["unix-time"] || time(1);
|
659d4b | 1999-10-18 | Martin Nilsson | | t+=time_dequantifier(m);
|
481740 | 1999-08-13 | Martin Nilsson | |
if(!(m->brief || m->time || m->date))
m->full=1;
|
659d4b | 1999-10-18 | Martin Nilsson | | if(m->part=="second" || m->part=="beat")
NOCACHE();
|
481740 | 1999-08-13 | Martin Nilsson | | else
CACHE(60);
|
bfd5fb | 1999-10-08 | Martin Nilsson | | return tagtime(t, m, id, language);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | string|array(string) tag_insert( string tag, mapping m, RequestID id )
|
481740 | 1999-08-13 | Martin Nilsson | | {
string n;
|
5e6383 | 1999-10-04 | Johan Sundström | | if(n = m->variable)
{
if(!id->variables[n])
return rxml_error(tag, "No such variable ("+n+").", id);
|
ecab8b | 2000-01-23 | Martin Nilsson | | return m->quote=="none"?(string)id->variables[n]:({ html_encode_string((string)id->variables[n]) });
|
5e6383 | 1999-10-04 | Johan Sundström | | }
|
481740 | 1999-08-13 | Martin Nilsson | |
|
bd2e11 | 1999-10-20 | Martin Nilsson | | if(n = m->variables) {
if(m->variables!="variables")
return ({ html_encode_string(Array.map(indices(id->variables),
lambda(string s, mapping m)
{ return sprintf("%s=%O\n", s, m[s]); },
id->variables) * "\n")
});
|
5e6383 | 1999-10-04 | Johan Sundström | | return ({ String.implode_nicely(indices(id->variables)) });
|
bd2e11 | 1999-10-20 | Martin Nilsson | | }
|
481740 | 1999-08-13 | Martin Nilsson | |
|
98131d | 1999-10-08 | Martin Nilsson | | if(n = m->other) {
|
f5132b | 1999-11-17 | Martin Nilsson | | if(stringp(id->misc[n]) || intp(id->misc[n]))
|
e48417 | 1999-10-06 | Martin Nilsson | | return m->quote=="none"?(string)id->misc[n]:({ html_encode_string((string)id->misc[n]) });
return rxml_error(tag, "No such other variable ("+n+").", id);
|
98131d | 1999-10-08 | Martin Nilsson | | }
|
d93f83 | 1999-09-17 | Martin Nilsson | |
|
5e6383 | 1999-10-04 | Johan Sundström | | if(n = m->cookies)
|
481740 | 1999-08-13 | Martin Nilsson | | {
NOCACHE();
|
bd2e11 | 1999-10-20 | Martin Nilsson | | if(n!="cookies")
return ({ html_encode_string(Array.map(indices(id->cookies),
lambda(string s, mapping m)
{ return sprintf("%s=%O\n", s, m[s]); },
id->cookies) * "\n")
});
|
5e6383 | 1999-10-04 | Johan Sundström | | return ({ String.implode_nicely(indices(id->cookies)) });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
5e6383 | 1999-10-04 | Johan Sundström | | if(n=m->cookie)
{
|
481740 | 1999-08-13 | Martin Nilsson | | NOCACHE();
|
5e6383 | 1999-10-04 | Johan Sundström | | if(id->cookies[n])
|
e48417 | 1999-10-06 | Martin Nilsson | | return m->quote=="none"?id->cookies[n]:({ html_encode_string(id->cookies[n]) });
|
5e6383 | 1999-10-04 | Johan Sundström | | return rxml_error(tag, "No such cookie ("+n+").", id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
5e6383 | 1999-10-04 | Johan Sundström | | if(m->file)
|
481740 | 1999-08-13 | Martin Nilsson | | {
if(m->nocache) {
int nocache=id->pragma["no-cache"];
id->pragma["no-cache"] = 1;
|
d05991 | 1999-10-08 | Martin Nilsson | | n=API_read_file(id,m->file)||rxml_error("insert", "No such file ("+m->file+").", id);
|
481740 | 1999-08-13 | Martin Nilsson | | id->pragma["no-cache"] = nocache;
|
291e28 | 1999-08-16 | Martin Nilsson | | return n;
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
d05991 | 1999-10-08 | Martin Nilsson | | return API_read_file(id,m->file)||rxml_error("insert", "No such file ("+m->file+").", id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
if(m->href && query("insert_href")) {
|
e161e4 | 1999-09-24 | Martin Nilsson | | if(m->nocache)
NOCACHE();
else
CACHE(60);
|
16509b | 1999-12-14 | Martin Nilsson | | Protocols.HTTP q=Protocols.HTTP.get_url(m->href);
|
e161e4 | 1999-09-24 | Martin Nilsson | | if(q && q->status>0 && q->status<400)
|
5e6383 | 1999-10-04 | Johan Sundström | | return ({ q->data() });
return rxml_error(tag, (q ? q->status_desc: "No server response"), id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
c6481f | 2000-01-21 | Martin Nilsson | | if(m->var) {
object|array tagfunc=RXML.get_context()->tag_set->get_tag("!--#echo");
if(!tagfunc) return rxml_error(tag, "No SSI module added.", id);
return ({ 1, "!--#echo", m});
|
f19d00 | 1999-12-18 | Martin Nilsson | | }
|
481740 | 1999-08-13 | Martin Nilsson | | string ret="Could not fullfill your request.<br>\nArguments:";
foreach(indices(m), string tmp)
ret+="<br />\n"+tmp+" : "+m[tmp];
|
5e6383 | 1999-10-04 | Johan Sundström | |
|
481740 | 1999-08-13 | Martin Nilsson | | return rxml_error(tag, ret, id);
}
|
ecab8b | 2000-01-23 | Martin Nilsson | |
|
989745 | 1999-10-10 | Per Hedbor | | string|array(string) tag_configurl(string tag, mapping m, RequestID id)
|
5e6383 | 1999-10-04 | Johan Sundström | | {
|
bfd5fb | 1999-10-08 | Martin Nilsson | | return ({ roxen->config_url() });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | string tag_return(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
bfd5fb | 1999-10-08 | Martin Nilsson | | int c=(int)m->code;
if(c) _error=c;
string p=m->text;
if(p) _rettext=p;
|
481740 | 1999-08-13 | Martin Nilsson | | return "";
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_set_cookie(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
659d4b | 1999-10-18 | Martin Nilsson | | if(!m->name)
|
481740 | 1999-08-13 | Martin Nilsson | | return rxml_error(tag, "Requires a name attribute.", id);
|
659d4b | 1999-10-18 | Martin Nilsson | | string cookies = m->name+"="+http_encode_cookie(m->value||"");
int t;
|
481740 | 1999-08-13 | Martin Nilsson | | if(m->persistent)
t=(3600*(24*365*2));
else
|
659d4b | 1999-10-18 | Martin Nilsson | | t=time_dequantifier(m);
|
481740 | 1999-08-13 | Martin Nilsson | |
|
659d4b | 1999-10-18 | Martin Nilsson | | cookies += "; expires="+http_date(t+time(1));
|
481740 | 1999-08-13 | Martin Nilsson | |
|
b53b75 | 1999-10-09 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | | cookies += "; path=" +(m->path||"/");
|
bfd5fb | 1999-10-08 | Martin Nilsson | | add_http_header(_extra_heads, "Set-Cookie", cookies);
|
481740 | 1999-08-13 | Martin Nilsson | |
return "";
}
|
989745 | 1999-10-10 | Per Hedbor | | string tag_remove_cookie(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
d93f83 | 1999-09-17 | Martin Nilsson | | if(!m->name || !id->cookies[m->name]) return rxml_error(tag, "That cookie does not exists.", id);
|
bfd5fb | 1999-10-08 | Martin Nilsson | |
add_http_header(_extra_heads, "Set-Cookie",
m->name+"="+http_encode_cookie(m->value||"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/"
);
|
481740 | 1999-08-13 | Martin Nilsson | | return "";
}
|
16509b | 1999-12-14 | Martin Nilsson | | string tag_modified(string tag, mapping m, RequestID id, Stdio.File file)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
659d4b | 1999-10-18 | Martin Nilsson | | array (int) s;
|
16509b | 1999-12-14 | Martin Nilsson | | Stdio.File f;
|
659d4b | 1999-10-18 | Martin Nilsson | |
if(m->by && !m->file && !m->realfile)
{
if(!id->conf->auth_module)
return rxml_error(tag, "Modified by requires a user database.", id);
m->name = id->conf->last_modified_by(file, id);
CACHE(10);
return tag_user(tag, m, id, file);
}
if(m->file)
{
m->realfile = id->conf->real_file(fix_relative(m->file,id), id);
m_delete(m, "file");
}
if(m->by && m->realfile)
{
if(!id->conf->auth_module)
return rxml_error(tag, "Modified by requires a user database.", id);
if(f = open(m->realfile, "r"))
{
m->name = id->conf->last_modified_by(f, id);
destruct(f);
CACHE(10);
return tag_user(tag, m, id, file);
}
return "A. Nonymous.";
}
if(m->realfile)
s = file_stat(m->realfile);
if(!(_stat || s) && !m->realfile && id->realfile)
{
m->realfile = id->realfile;
return tag_modified(tag, m, id, file);
}
CACHE(10);
if(!s) s = _stat;
if(!s) s = id->conf->stat_file( id->not_query, id );
|
f5132b | 1999-11-17 | Martin Nilsson | | if(s) {
|
659d4b | 1999-10-18 | Martin Nilsson | | if(m->ssi)
|
c4d2a5 | 2000-01-03 | Martin Nilsson | | return strftime(id->misc->ssi_timefmt || "%c", s[3]);
|
f5132b | 1999-11-17 | Martin Nilsson | | return tagtime(s[3], m, id, language);
}
|
659d4b | 1999-10-18 | Martin Nilsson | |
|
c4d2a5 | 2000-01-03 | Martin Nilsson | | if(m->ssi) return id->misc->ssi_errmsg||"";
|
659d4b | 1999-10-18 | Martin Nilsson | | return rxml_error(tag, "Couldn't stat file.", id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
16509b | 1999-12-14 | Martin Nilsson | | string|array(string) tag_user(string tag, mapping m, RequestID id, Stdio.File file)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
659d4b | 1999-10-18 | Martin Nilsson | | string *u;
string b, dom;
if(!id->conf->auth_module)
return rxml_error(tag, "Requires a user database.", id);
|
f5132b | 1999-11-17 | Martin Nilsson | | if (!(b=m->name))
|
659d4b | 1999-10-18 | Martin Nilsson | | return(tag_modified("modified", m | ([ "by":"by" ]), id, file));
b=m->name;
dom=id->conf->query("Domain");
if(dom[-1]=='.')
dom=dom[0..strlen(dom)-2];
if(!b) return "";
u=id->conf->userinfo(b, id);
if(!u) return "";
if(m->realname && !m->email)
{
if(m->link && !m->nolink)
return ({ "<a href=\"/~"+b+"/\">"+u[4]+"</a>" });
return ({ u[4] });
}
if(m->email && !m->realname)
{
if(m->link && !m->nolink)
return ({ sprintf("<a href=\"mailto:%s@%s@\">%s@%s</a>",
b, dom, b, dom)
});
return ({ b + "@" + dom });
}
if(m->nolink && !m->link)
return ({ sprintf("%s <%s@%s>",
u[4], b, dom)
});
return ({ sprintf("<a href=\"/~%s/\">%s</a> "
"<a href=\"mailto:%s@%s\"><%s@%s></a>",
b, u[4], b, dom, b, dom)
});
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | array(string) tag_set_max_cache( string tag, mapping m, RequestID id )
{
|
659d4b | 1999-10-18 | Martin Nilsson | | id->misc->cacheable = (int)m->time;
|
989745 | 1999-10-10 | Per Hedbor | | return ({ "" });
}
|
481740 | 1999-08-13 | Martin Nilsson | |
|
ecab8b | 2000-01-23 | Martin Nilsson | | array|string container_scope(string tag, mapping m,
|
989745 | 1999-10-10 | Per Hedbor | | string contents, RequestID id)
{
|
ecab8b | 2000-01-23 | Martin Nilsson | | if(!m->scope) {
mapping old_variables = copy_value(id->variables);
int truth=_ok;
if (!m->extend)
id->variables = ([]);
contents = parse_rxml(contents, id);
id->variables = old_variables;
if (m->truth)
_ok=truth;
return ({ contents });
}
return contents;
|
989745 | 1999-10-10 | Per Hedbor | | }
array(string) container_catch( string tag, mapping m, string c, RequestID id )
{
string r;
if(!id->misc->catcher_is_ready)
id->misc+=(["catcher_is_ready":1]);
else
id->misc->catcher_is_ready++;
array e = catch(r=parse_rxml(c, id));
id->misc->catcher_is_ready--;
|
f5132b | 1999-11-17 | Martin Nilsson | | if(e) return e[0];
|
989745 | 1999-10-10 | Per Hedbor | | return ({r});
}
|
659d4b | 1999-10-18 | Martin Nilsson | | array(string) container_cache(string tag, mapping args,
|
989745 | 1999-10-10 | Per Hedbor | | string contents, RequestID id)
{
#define HASH(x) (x+id->not_query+id->query+id->realauth +id->conf->query("MyWorldLocation"))
#if constant(Crypto.md5)
object md5 = Crypto.md5();
md5->update(HASH(contents));
string key=md5->digest();
#else
string key = (string)hash(HASH(contents));
#endif
if(args->key)
key += args->key;
string parsed = cache_lookup("tag_cache", key);
if(!parsed) {
parsed = parse_rxml(contents, id);
cache_set("tag_cache", key, parsed);
}
return ({parsed});
#undef HASH
}
|
659d4b | 1999-10-18 | Martin Nilsson | | string|array(string) container_crypt( string s, mapping m,
|
989745 | 1999-10-10 | Per Hedbor | | string c, RequestID id )
{
|
f5132b | 1999-11-17 | Martin Nilsson | | if(m->compare) return crypt(c,m->compare)?"<true>":"<false>";
return ({ crypt(c) });
|
989745 | 1999-10-10 | Per Hedbor | | }
string container_for(string t, mapping args, string c, RequestID id)
|
d05991 | 1999-10-08 | Martin Nilsson | | {
string v = args->variable;
int from = (int)args->from;
int to = (int)args->to;
int step = (int)args->step!=0?(int)args->step:(to<from?-1:1);
if((to<from && step>0)||(to>from && step<0)) to=from+step;
string res="";
|
659d4b | 1999-10-18 | Martin Nilsson | | if(to<from)
|
989745 | 1999-10-10 | Per Hedbor | | {
|
b53b75 | 1999-10-09 | Martin Nilsson | | if(v)
for(int i=from; i>=to; i+=step)
res += "<set variable="+v+" value="+i+">"+c;
else
for(int i=from; i>=to; i+=step)
res+=c;
|
d05991 | 1999-10-08 | Martin Nilsson | | return res;
}
|
659d4b | 1999-10-18 | Martin Nilsson | | else if(to>from)
|
989745 | 1999-10-10 | Per Hedbor | | {
|
b53b75 | 1999-10-09 | Martin Nilsson | | if(v)
for(int i=from; i<=to; i+=step)
res += "<set variable="+v+" value="+i+">"+c;
else
for(int i=from; i<=to; i+=step)
res+=c;
|
d05991 | 1999-10-08 | Martin Nilsson | | return res;
}
return "<set variable="+v+" value="+to+">"+c;
}
|
989745 | 1999-10-10 | Per Hedbor | | string container_foreach(string t, mapping args, string c, RequestID id)
|
d05991 | 1999-10-08 | Martin Nilsson | | {
string v = args->variable;
array what;
if(!args->in)
return rxml_error(t, "No in attribute given.", id);
if(args->variables)
what = Array.map(args->in/"," - ({""}),
lambda(string name, mapping v) {
return v[name] || "";
}, id->variables);
else
what = Array.map(args->in / "," - ({""}),
lambda(string var) {
sscanf(var, "%*[ \t\n\r]%s", var);
var = reverse(var);
sscanf(var, "%*[ \t\n\r]%s", var);
return reverse(var);
});
|
659d4b | 1999-10-18 | Martin Nilsson | |
|
d05991 | 1999-10-08 | Martin Nilsson | | string res="";
|
659d4b | 1999-10-18 | Martin Nilsson | | foreach(what, string w)
|
d05991 | 1999-10-08 | Martin Nilsson | | res += "<set variable="+v+" value="+w+">"+c;
return res;
}
|
659d4b | 1999-10-18 | Martin Nilsson | | string container_apre(string tag, mapping m, string q, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
string href, s, *foo;
if(!(href = m->href))
href=strip_prestate(strip_config(id->raw_url));
|
5e6383 | 1999-10-04 | Johan Sundström | | else
|
481740 | 1999-08-13 | Martin Nilsson | | {
if ((sizeof(foo = href / ":") > 1) && (sizeof(foo[0] / "/") == 1))
|
e48417 | 1999-10-06 | Martin Nilsson | | return make_container("a", m, q);
|
d93f83 | 1999-09-17 | Martin Nilsson | | href=strip_prestate(fix_relative(href, id));
|
481740 | 1999-08-13 | Martin Nilsson | | m_delete(m, "href");
}
|
659d4b | 1999-10-18 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | | if(!strlen(href))
href="";
multiset prestate = (< @indices(id->prestate) >);
if(m->add) {
foreach((m->add-" ")/",", s)
prestate[s]=1;
m_delete(m,"add");
}
if(m->drop) {
foreach((m->drop-" ")/",", s)
prestate[s]=0;
m_delete(m,"drop");
}
m->href = add_pre_state(href, prestate);
|
e48417 | 1999-10-06 | Martin Nilsson | | return make_container("a", m, q);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
659d4b | 1999-10-18 | Martin Nilsson | | string|array(string) container_aconf(string tag, mapping m,
|
989745 | 1999-10-10 | Per Hedbor | | string q, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
string href,s;
|
659d4b | 1999-10-18 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | | if(!m->href)
href=strip_prestate(strip_config(id->raw_url));
|
659d4b | 1999-10-18 | Martin Nilsson | | else
|
481740 | 1999-08-13 | Martin Nilsson | | {
href=m->href;
if (search(href, ":") == search(href, "//")-1)
return rxml_error(tag, "It is not possible to add configs to absolute URLs.", id);
href=fix_relative(href, id);
m_delete(m, "href");
}
|
ebdb65 | 2000-01-14 | Martin Nilsson | | array cookies = ({});
|
481740 | 1999-08-13 | Martin Nilsson | | if(m->add) {
foreach((m->add-" ")/",", s)
|
ebdb65 | 2000-01-14 | Martin Nilsson | | cookies+=({s});
|
481740 | 1999-08-13 | Martin Nilsson | | m_delete(m,"add");
}
if(m->drop) {
foreach((m->drop-" ")/",", s)
|
ebdb65 | 2000-01-14 | Martin Nilsson | | cookies+=({"-"+s});
|
481740 | 1999-08-13 | Martin Nilsson | | m_delete(m,"drop");
}
|
ebdb65 | 2000-01-14 | Martin Nilsson | | m->href = add_config(href, cookies, id->prestate);
|
e48417 | 1999-10-06 | Martin Nilsson | | return make_container("a", m, q);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
659d4b | 1999-10-18 | Martin Nilsson | | string container_maketag(string tag, mapping m, string cont, RequestID id)
|
989745 | 1999-10-10 | Per Hedbor | | {
|
5d9397 | 1999-10-04 | Martin Nilsson | | mapping args=(!m->noxml&&m->type=="tag"?(["/":"/"]):([]));
|
0a22e0 | 1999-10-04 | Martin Nilsson | | cont=parse_html(parse_rxml(cont,id), ([]), (["attrib":
|
ecab8b | 2000-01-23 | Martin Nilsson | | lambda(string tag, mapping m, string cont, mapping args) {
args[m->name]=cont;
|
481740 | 1999-08-13 | Martin Nilsson | | return "";
}
|
ecab8b | 2000-01-23 | Martin Nilsson | | ]), args);
|
18be8a | 1999-08-17 | Martin Nilsson | | if(m->type=="container")
|
5d9397 | 1999-10-04 | Martin Nilsson | | return make_container(m->name, args, cont);
return make_tag(m->name, args);
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | string container_doc(string tag, mapping m, string s)
|
481740 | 1999-08-13 | Martin Nilsson | | {
if(!m["quote"])
|
d93f83 | 1999-09-17 | Martin Nilsson | | if(m["pre"]) {
m_delete(m,"pre");
return "\n"+make_container("pre",m,
replace(s, ({"{","}","& "}),({"<",">","& "})))+"\n";
}
|
481740 | 1999-08-13 | Martin Nilsson | | else
return replace(s, ({ "{", "}", "& " }), ({ "<", ">", "& " }));
|
659d4b | 1999-10-18 | Martin Nilsson | | else
|
d93f83 | 1999-09-17 | Martin Nilsson | | if(m["pre"]) {
m_delete(m,"pre");
m_delete(m,"quote");
return "\n"+make_container("pre",m,
replace(s, ({"<",">","& "}),({"<",">","& "})))+"\n";
}
|
481740 | 1999-08-13 | Martin Nilsson | | else
return replace(s, ({ "<", ">", "& " }), ({ "<", ">", "& " }));
}
|
989745 | 1999-10-10 | Per Hedbor | | string container_autoformat(string tag, mapping m, string s, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
s-="\r";
|
b53b75 | 1999-10-09 | Martin Nilsson | | string p=(m["class"]?"<p class=\""+m["class"]+"\">":"<p>");
|
d93f83 | 1999-09-17 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | | if(!m->nobr) {
s = replace(s, "\n", "<br>\n");
if(m->p) {
|
d93f83 | 1999-09-17 | Martin Nilsson | | if(search(s, "<br>\n<br>\n")!=-1) s=p+s;
s = replace(s, "<br>\n<br>\n", "\n</p>"+p+"\n");
|
d61469 | 1999-08-16 | Martin Nilsson | | if(sizeof(s)>3 && s[0..2]!="<p>" && s[0..2]!="<p ")
|
d93f83 | 1999-09-17 | Martin Nilsson | | s=p+s;
if(s[..sizeof(s)-4]==p)
|
481740 | 1999-08-13 | Martin Nilsson | | return s[..sizeof(s)-4];
else
return s+"</p>";
}
return s;
}
if(m->p) {
|
d93f83 | 1999-09-17 | Martin Nilsson | | if(search(s, "\n\n")!=-1) s=p+s;
s = replace(s, "\n\n", "\n</p>"+p+"\n");
|
d61469 | 1999-08-16 | Martin Nilsson | | if(sizeof(s)>3 && s[0..2]!="<p>" && s[0..2]!="<p ")
|
d93f83 | 1999-09-17 | Martin Nilsson | | s=p+s;
if(s[..sizeof(s)-4]==p)
|
481740 | 1999-08-13 | Martin Nilsson | | return s[..sizeof(s)-4];
else
return s+"</p>";
}
|
659d4b | 1999-10-18 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | | return s;
}
|
885935 | 1999-11-25 | Martin Nilsson | | class Smallcapsstr {
|
d93f83 | 1999-09-17 | Martin Nilsson | | constant UNDEF=0, BIG=1, SMALL=2;
static string text="",part="",bigtag,smalltag;
static mapping bigarg,smallarg;
static int last=UNDEF;
void create(string bs, string ss, mapping bm, mapping sm) {
bigtag=bs;
smalltag=ss;
bigarg=bm;
smallarg=sm;
}
|
885935 | 1999-11-25 | Martin Nilsson | | string _sprintf() {
return "Smallcapsstr()";
}
|
d93f83 | 1999-09-17 | Martin Nilsson | | void add(string char) {
part+=char;
}
void add_big(string char) {
if(last!=BIG) flush_part();
part+=char;
last=BIG;
}
void add_small(string char) {
if(last!=SMALL) flush_part();
part+=char;
last=SMALL;
}
void write(string txt) {
if(last!=UNDEF) flush_part();
part+=txt;
}
void flush_part() {
switch(last){
case UNDEF:
default:
text+=part;
break;
case BIG:
text+=make_container(bigtag,bigarg,part);
break;
case SMALL:
text+=make_container(smalltag,smallarg,part);
break;
}
part="";
last=UNDEF;
}
string value() {
if(last!=UNDEF) flush_part();
|
659d4b | 1999-10-18 | Martin Nilsson | | return text;
|
d93f83 | 1999-09-17 | Martin Nilsson | | }
}
|
989745 | 1999-10-10 | Per Hedbor | | string container_smallcaps(string t, mapping m, string s)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
16509b | 1999-12-14 | Martin Nilsson | | Smallcapsstr ret;
|
d93f83 | 1999-09-17 | Martin Nilsson | | string spc=m->space?" ":"";
m_delete(m, "space");
mapping bm=([]), sm=([]);
if(m["class"] || m->bigclass) {
bm=(["class":(m->bigclass||m["class"])]);
m_delete(m, "bigclass");
}
if(m["class"] || m->smallclass) {
sm=(["class":(m->smallclass||m["class"])]);
m_delete(m, "smallclass");
}
if(m->size) {
bm+=(["size":m->size]);
if(m->size[0]=='+' && (int)m->size>1)
sm+=(["size":m->small||"+"+((int)m->size-1)]);
else
sm+=(["size":m->small||(string)((int)m->size-1)]);
m_delete(m, "small");
|
885935 | 1999-11-25 | Martin Nilsson | | ret=Smallcapsstr("font","font", m+bm, m+sm);
|
d93f83 | 1999-09-17 | Martin Nilsson | | }
|
f5132b | 1999-11-17 | Martin Nilsson | | else
|
885935 | 1999-11-25 | Martin Nilsson | | ret=Smallcapsstr("big","small", m+bm, m+sm);
|
d93f83 | 1999-09-17 | Martin Nilsson | |
for(int i=0; i<strlen(s); i++)
if(s[i]=='<') {
int j;
for(j=i; j<strlen(s) && s[j]!='>'; j++);
ret->write(s[i..j]);
i+=j-1;
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
d93f83 | 1999-09-17 | Martin Nilsson | | else if(s[i]<=32)
ret->add_small(s[i..i]);
else if(lower_case(s[i..i])==s[i..i])
ret->add_small(upper_case(s[i..i])+spc);
else if(upper_case(s[i..i])==s[i..i])
ret->add_big(s[i..i]+spc);
else
ret->add(s[i..i]+spc);
return ret->value();
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | string container_random(string tag, mapping m, string s)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
16509b | 1999-12-14 | Martin Nilsson | | string|array q;
|
f5132b | 1999-11-17 | Martin Nilsson | | if(!(q=m->separator || m->sep)) return (q=s/"\n")[random(sizeof(q))];
return (q=s/q)[random(sizeof(q))];
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
659d4b | 1999-10-18 | Martin Nilsson | | array(string) container_formoutput(string tag_name, mapping args,
|
989745 | 1999-10-10 | Per Hedbor | | string contents, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
e48417 | 1999-10-06 | Martin Nilsson | | return ({ do_output_tag( args, ({ id->variables }), contents, id ) });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
16509b | 1999-12-14 | Martin Nilsson | | array(string) container_gauge(string t, mapping args, string contents, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
NOCACHE();
int t = gethrtime();
contents = parse_rxml( contents, id );
t = gethrtime()-t;
string define = args->define?args->define:"gauge";
|
16509b | 1999-12-14 | Martin Nilsson | | if(args->silent) return ({ "" });
if(args->timeonly) return ({ sprintf("%3.6f", t/1000000.0) });
|
481740 | 1999-08-13 | Martin Nilsson | | if(args->resultonly) return ({contents});
|
e48417 | 1999-10-06 | Martin Nilsson | | return ({ "<br><font size=\"-1\"><b>Time: "+
|
481740 | 1999-08-13 | Martin Nilsson | | sprintf("%3.6f", t/1000000.0)+
|
e48417 | 1999-10-06 | Martin Nilsson | | " seconds</b></font><br>"+contents });
|
659d4b | 1999-10-18 | Martin Nilsson | | }
|
481740 | 1999-08-13 | Martin Nilsson | |
|
16509b | 1999-12-14 | Martin Nilsson | | array(string) container_trimlines( string tag_name, mapping args,
|
989745 | 1999-10-10 | Per Hedbor | | string contents, RequestID id )
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
989745 | 1999-10-10 | Per Hedbor | | contents = replace(parse_rxml(contents,id), ({"\r\n","\r" }), ({"\n","\n"}));
|
481740 | 1999-08-13 | Martin Nilsson | | return ({ (contents / "\n" - ({ "" })) * "\n" });
}
|
659d4b | 1999-10-18 | Martin Nilsson | | void container_throw( string t, mapping m, string c, RequestID id)
{
|
3a4b9a | 1999-12-27 | Martin Nilsson | | if(!id->misc->catcher_is_ready && c[-1]!='\n')
|
989745 | 1999-10-10 | Per Hedbor | | c+="\n";
|
659d4b | 1999-10-18 | Martin Nilsson | | throw( ({ c, backtrace() }) );
|
989745 | 1999-10-10 | Per Hedbor | | }
|
f5132b | 1999-11-17 | Martin Nilsson | |
private int|array internal_tag_input(string t, mapping m, string name, multiset(string) value)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
f5132b | 1999-11-17 | Martin Nilsson | | if (name && m->name!=name) return 0;
if (m->type!="checkbox" && m->type!="radio") return 0;
if (value[m->value||"on"]) {
if (m->checked) return 0;
m->checked = "checked";
}
else {
if (!m->checked) return 0;
m_delete(m, "checked" );
}
|
481740 | 1999-08-13 | Martin Nilsson | |
|
f5132b | 1999-11-17 | Martin Nilsson | | return ({ make_tag(t, m) });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
885935 | 1999-11-25 | Martin Nilsson | | array split_on_option( string what, Regexp r )
{
array a = r->split( what );
if( !a )
return ({ what });
return split_on_option( a[0], r ) + a[1..];
}
|
f5132b | 1999-11-17 | Martin Nilsson | | private int|array internal_tag_select(string t, mapping m, string c, string name, multiset(string) value)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
885935 | 1999-11-25 | Martin Nilsson | | if(m->name!=name) return ({ make_container(t,m,c) });
Regexp r = Regexp( "(.*)<([Oo][Pp][Tt][Ii][Oo][Nn])([^>]*)>(.*)" );
array(string) tmp=split_on_option(c,r);
string ret=tmp[0],nvalue;
int selected,stop;
tmp=tmp[1..];
while(sizeof(tmp)>2) {
stop=search(tmp[2],"<");
if(sscanf(lower_case(tmp[1]),"%*svalue=%s%*[ >]",nvalue)!=3) nvalue=tmp[2][..stop==-1?sizeof(tmp[2]):stop];
selected=Regexp(".*[Ss][Ee][Ll][Ee][Cc][Tt][Ee][Dd].*")->match(tmp[1]);
ret+="<"+tmp[0]+tmp[1];
if(value[nvalue] && !selected) ret+=" selected=\"selected\"";
ret+=">"+tmp[2];
if(!Regexp(".*</[Oo][Pp][Tt][Ii][Oo][Nn]")->match(tmp[2])) ret+="</"+tmp[0]+">";
tmp=tmp[3..];
}
return ({ make_container(t,m,ret) });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
f5132b | 1999-11-17 | Martin Nilsson | | array(string) container_default( string t, mapping m, string c, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
f5132b | 1999-11-17 | Martin Nilsson | | multiset value=(<>);
if(m->value) value=mkmultiset((m->value||"")/(m->separator||","));
if(m->variable) value+=mkmultiset(({id->variables[m->variable]}));
c = parse_rxml(c, id );
if(value==(<>)) return ({c});
return ({ parse_html(c, (["input":internal_tag_input]),
(["select":internal_tag_select]),
m->name, value) });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
989745 | 1999-10-10 | Per Hedbor | | string container_sort(string t, mapping m, string c, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
if(!m->separator)
m->separator = "\n";
string pre="", post="";
array lines = c/m->separator;
while(lines[0] == "")
{
pre += m->separator;
lines = lines[1..];
}
while(lines[-1] == "")
{
post += m->separator;
lines = lines[..sizeof(lines)-2];
}
lines=sort(lines);
return pre + (m->reverse?reverse(lines):lines)*m->separator + post;
}
|
16509b | 1999-12-14 | Martin Nilsson | | array(string)|string container_recursive_output (string tagname, mapping args,
|
989745 | 1999-10-10 | Per Hedbor | | string contents, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
int limit;
array(string) inside, outside;
|
659d4b | 1999-10-18 | Martin Nilsson | | if (id->misc->recout_limit)
|
989745 | 1999-10-10 | Per Hedbor | | {
|
481740 | 1999-08-13 | Martin Nilsson | | limit = id->misc->recout_limit - 1;
inside = id->misc->recout_outside, outside = id->misc->recout_inside;
}
|
659d4b | 1999-10-18 | Martin Nilsson | | else
|
989745 | 1999-10-10 | Per Hedbor | | {
|
481740 | 1999-08-13 | Martin Nilsson | | limit = (int) args->limit || 100;
inside = args->inside ? args->inside / (args->separator || ",") : ({});
outside = args->outside ? args->outside / (args->separator || ",") : ({});
if (sizeof (inside) != sizeof (outside))
|
16509b | 1999-12-14 | Martin Nilsson | | return rxml_error(tagname, "'inside' and 'outside' replacement sequences "
"aren't of same length", id);
|
481740 | 1999-08-13 | Martin Nilsson | | }
if (limit <= 0) return contents;
int save_limit = id->misc->recout_limit;
string save_inside = id->misc->recout_inside, save_outside = id->misc->recout_outside;
id->misc->recout_limit = limit;
id->misc->recout_inside = inside;
id->misc->recout_outside = outside;
string res = parse_rxml (
parse_html (
contents,
|
659d4b | 1999-10-18 | Martin Nilsson | | (["recurse": lambda (string t, mapping a, string c) {return ({c});}]),
|
989745 | 1999-10-10 | Per Hedbor | | ([]),
|
659d4b | 1999-10-18 | Martin Nilsson | | "<" + tagname + ">" + replace (contents, inside, outside) +
|
989745 | 1999-10-10 | Per Hedbor | | "</" + tagname + ">"),
|
481740 | 1999-08-13 | Martin Nilsson | | id);
id->misc->recout_limit = save_limit;
id->misc->recout_inside = save_inside;
id->misc->recout_outside = save_outside;
return ({res});
}
|
bd2e11 | 1999-10-20 | Martin Nilsson | |
#define MAGIC_EXIT 4921325
|
989745 | 1999-10-10 | Per Hedbor | | string tag_leave(string tag, mapping m, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
659d4b | 1999-10-18 | Martin Nilsson | | if(id->misc->leave_repeat)
|
989745 | 1999-10-10 | Per Hedbor | | {
|
481740 | 1999-08-13 | Martin Nilsson | | id->misc->leave_repeat--;
|
bd2e11 | 1999-10-20 | Martin Nilsson | | throw(MAGIC_EXIT);
|
481740 | 1999-08-13 | Martin Nilsson | | }
return rxml_error(tag, "Must be contained by <repeat>.", id);
}
|
989745 | 1999-10-10 | Per Hedbor | | string container_repeat(string tag, mapping m, string c, RequestID id)
|
481740 | 1999-08-13 | Martin Nilsson | | {
if(!id->misc->leave_repeat)
id->misc->leave_repeat=0;
int exit=id->misc->leave_repeat++,loop,maxloop=(int)m->maxloops||10000;
string ret="",iter;
while(loop<maxloop && id->misc->leave_repeat!=exit) {
loop++;
mixed error=catch {
iter=parse_rxml(c,id);
};
|
bd2e11 | 1999-10-20 | Martin Nilsson | | if((intp(error) && error!=0 && error!=MAGIC_EXIT) || !intp(error))
|
481740 | 1999-08-13 | Martin Nilsson | | throw(error);
if(id->misc->leave_repeat!=exit)
ret+=iter;
}
if(loop==maxloop)
return ret+rxml_error(tag, "Too many iterations ("+maxloop+").", id);
return ret;
}
|
659d4b | 1999-10-18 | Martin Nilsson | | string container_replace( string tag, mapping m, string cont, RequestID id)
|
989745 | 1999-10-10 | Per Hedbor | | {
|
659d4b | 1999-10-18 | Martin Nilsson | | switch(m->type)
|
989745 | 1999-10-10 | Per Hedbor | | {
|
481740 | 1999-08-13 | Martin Nilsson | | case "word":
default:
if(!m->from) return cont;
|
989745 | 1999-10-10 | Per Hedbor | | return replace(cont,m->from,(m->to?m->to:""));
|
481740 | 1999-08-13 | Martin Nilsson | |
case "words":
if(!m->from) return cont;
string s=m->separator?m->separator:",";
array from=(array)(m->from/s);
array to=(array)(m->to/s);
int balance=sizeof(from)-sizeof(to);
if(balance>0) to+=allocate(balance,"");
return replace(cont,from,to);
}
}
|
989745 | 1999-10-10 | Per Hedbor | | array(string) container_cset( string t, mapping m, string c, RequestID id )
|
481740 | 1999-08-13 | Martin Nilsson | | {
|
31e39c | 1999-10-10 | Per Hedbor | | if( m->quote != "none" )
c = html_decode_string( c );
|
989745 | 1999-10-10 | Per Hedbor | | if( !m->variable )
return ({rxml_error(t, "Variable not specified.", id)});
id->variables[ m->variable ] = c;
return ({ "" });
|
481740 | 1999-08-13 | Martin Nilsson | | }
|
bd2e11 | 1999-10-20 | Martin Nilsson | |
|
481740 | 1999-08-13 | Martin Nilsson | |
mapping query_if_callers()
{
return ([
|
bd2e11 | 1999-10-20 | Martin Nilsson | | "expr":lambda( string q){ return (int)sexpr_eval(q); }
|
481740 | 1999-08-13 | Martin Nilsson | | ]);
}
|
659d4b | 1999-10-18 | Martin Nilsson | |
|
16509b | 1999-12-14 | Martin Nilsson | | string api_query_modified(RequestID id, string f, int|void by)
|
659d4b | 1999-10-18 | Martin Nilsson | | {
mapping m = ([ "by":by, "file":f ]);
return tag_modified("modified", m, id, id);
}
|