Branch: Tag:

1999-11-17

1999-11-17 22:34:17 by Martin Nilsson <mani@lysator.liu.se>

Rewrote the default tag.

Rev: server/modules/tags/rxmltags.pike:1.29

7:   #define _rettext id->misc->defines[" _rettext"]   #define _ok id->misc->defines[" _ok"]    - constant cvs_version="$Id: rxmltags.pike,v 1.28 1999/10/20 17:50:51 nilsson Exp $"; + constant cvs_version="$Id: rxmltags.pike,v 1.29 1999/11/17 22:34:17 nilsson Exp $";   constant thread_safe=1;   constant language = roxen->language;   
104:   {    NOCACHE();    string client=""; -  if (sizeof(id->client)) +  if (sizeof(id->client)) {    if(m->full)    client=id->client * " ";    else    client=id->client[0]; -  +  }       return m->quote=="none"?client:({ html_encode_string(client) });   }
380:   {    catch {    array s = id->conf->stat_file( fix_relative( args->file, id ), id ); -  if (s && (s[1]>= 0)) { -  return (string)s[1]; -  } +  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);
398:    if(m->src=="err2") m->src="err_2";    if(m->src=="err3") m->src="err_3";    -  if (m->src[sizeof(m->src)-4..] == ".gif") { +  if (m->src[sizeof(m->src)-4..] == ".gif")    m->src = m->src[..sizeof(m->src)-5]; -  } +     m->src = "/internal-roxen-" + m->src;    }   
442:       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")    }); -  } +     return ({ String.implode_nicely(indices(id->variables)) });    }       if(n = m->other) { -  if(stringp(id->misc[n]) || intp(id->misc[n])) { +  if(stringp(id->misc[n]) || intp(id->misc[n]))    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);    }   
605:    CACHE(10);    if(!s) s = _stat;    if(!s) s = id->conf->stat_file( id->not_query, id ); -  if(s) +  if(s) {    if(m->ssi)    return strftime(id->misc->defines->timefmt || "%c", s[3]); -  else +     return tagtime(s[3], m, id, language); -  +  }       return rxml_error(tag, "Couldn't stat file.", id);   }
622:    if(!id->conf->auth_module)    return rxml_error(tag, "Requires a user database.", id);    -  if (!(b=m->name)) { +  if (!(b=m->name))    return(tag_modified("modified", m | ([ "by":"by" ]), id, file)); -  } +        b=m->name;   
690:    id->misc->catcher_is_ready++;    array e = catch(r=parse_rxml(c, id));    id->misc->catcher_is_ready--; -  if(e) -  return e[0]; +  if(e) return e[0];    return ({r});   }   
720:   string|array(string) container_crypt( string s, mapping m,    string c, RequestID id )   { -  if(m->compare) -  return crypt(c,m->compare)?"<true>":"<false>"; -  else +  if(m->compare) return crypt(c,m->compare)?"<true>":"<false>";    return ({ crypt(c) });   }   
1005:    m_delete(m, "small");    ret=smallcapsstr("font","font", m+bm, m+sm);    } -  else { +  else    ret=smallcapsstr("big","small", m+bm, m+sm); -  } +        for(int i=0; i<strlen(s); i++)    if(s[i]=='<') {
1031:   string container_random(string tag, mapping m, string s)   {    mixed q; -  if(!(q=m->separator || m->sep)) -  return (q=s/"\n")[random(sizeof(q))]; -  else +  if(!(q=m->separator || m->sep)) return (q=s/"\n")[random(sizeof(q))];    return (q=s/q)[random(sizeof(q))];   }   
1075:    throw( ({ c, backtrace() }) );   }    - // Internal method for the default tag - private mixed internal_tag_input( string tag_name, mapping args, string name, -  multiset (string) value ) + // Internal methods for the default tag + private int|array internal_tag_input(string t, mapping m, string name, multiset(string) value)   { -  if (name && args->name != name) -  return 0; -  if (args->type == "checkbox" || args->type == "radio") -  if (args->value) -  if (value[ args->value ]) -  if (args->checked) -  return 0; -  else -  args->checked = "checked"; -  else -  if (args->checked) -  m_delete( args, "checked" ); -  else -  return 0; -  else -  if (value[ "on" ]) -  if (args->checked) -  return 0; -  else -  args->checked = "checked"; -  else -  if (args->checked) -  m_delete( args, "checked" ); -  else -  return 0; -  else -  return 0; -  return ({ make_tag( tag_name, args ) }); +  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" ); +  }    - // Internal method for the default tag - private mixed internal_tag_option( string tag_name, mapping args, -  string contents, multiset(string) value ) +  return ({ make_tag(t, m) }); + } + private int|array internal_tag_select(string t, mapping m, string c, string name, multiset(string) value)   { -  if (args->value) -  if (value[ args->value ]) -  if (args->selected) +  array(string) tmp; +  int i; +  +  if (m->name==name || !name) +  c=parse_html(c, (["option":lambda(string t, mapping m, multiset(string) value) { +  if (value[m->value]) { +  if (m->selected)    return 0;    else -  args->selected = "selected"; -  else -  return 0; -  else -  if (value[ trim( contents ) ]) -  if (args->selected) -  return 0; -  else -  args->selected = "selected"; -  else -  return 0; -  return ({ make_container( tag_name, args, contents ) }); +  m->selected = "selected";    } -  +  return ({ make_tag(t, m) }); +  }]), ([]), value);    - // Internal method for the default tag - private mixed internal_tag_select( string tag_name, mapping args, -  string contents, string name, -  multiset (string) value ) - { -  array (string) tmp; -  int c; -  -  if (name && args->name != name) -  return 0; -  tmp = contents / "<option"; -  for (c=1; c < sizeof( tmp ); c++) -  if (sizeof( tmp[c] / "</option>" ) == 1) -  tmp[c] += "</option>"; -  contents = tmp * "<option"; -  mapping m = ([ "option" : internal_tag_option ]); -  contents = parse_html( contents, ([ ]), m, value ); -  return ({ make_container( tag_name, args, contents ) }); +  return ({ make_container(t, m, c) });   }    - // The default tag is used to give default values to forms elements, - // without any fuss. - array(string) container_default( string tag_name, mapping args, -  string contents, RequestID id) + array(string) container_default( string t, mapping m, string c, RequestID id)   { -  string separator = args->separator || "\000"; +  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});    -  contents = parse_rxml( contents, id ); -  if (args->value) -  return ({parse_html( contents, ([ "input" : internal_tag_input ]), -  ([ "select" : internal_tag_select ]), -  args->name, mkmultiset( args->value -  / separator ) )}); -  else if (args->variable && id->variables[ args->variable ]) -  return ({parse_html( contents, ([ "input" : internal_tag_input ]), -  ([ "select" : internal_tag_select ]), -  args->name, -  mkmultiset( id->variables[ args->variable ] -  / separator ) )}); -  else -  return ({ contents }); +  return ({ parse_html(c, (["input":internal_tag_input]), +  (["select":internal_tag_select]), +  m->name, value) });   }      string container_sort(string t, mapping m, string c, RequestID id)