Branch: Tag:

1999-10-17

1999-10-17 22:54:52 by Martin Nilsson <mani@lysator.liu.se>

Minor cleanup, renamed tag_aprestate to tag_apre so it works as usual, moved in user and modified code from rxmlparse.pike

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

7:   #define _rettext id->misc->defines[" _rettext"]   #define _ok id->misc->defines[" _ok"]    - constant cvs_version="$Id: rxmltags.pike,v 1.25 1999/10/17 14:14:13 nilsson Exp $"; + constant cvs_version="$Id: rxmltags.pike,v 1.26 1999/10/17 22:54:52 nilsson Exp $";   constant thread_safe=1;   constant language = roxen->language;   
25:    "Should the usage of &lt;insert href&gt; be allowed?");   }    + void start(int q, object c) + { +  add_api_function("query_modified", api_query_modified, ({ "string", })); + } +    array register_module()   {    return ({ MODULE_PARSER,
86:   {    mapping hdrs = http_auth_required (args->realm, args->message);    if (hdrs->error) _error = hdrs->error; -  //FIXME: add_http_header -  if (hdrs->extra_heads) _extra_heads += hdrs->extra_heads; +  if (hdrs->extra_heads) +  _extra_heads += hdrs->extra_heads; +  // We do not need this as long as hdrs only contains strings and numbers +  // foreach(indices(hdrs->extra_heads), string tmp) +  // add_http_header(_extra_heads, tmp, hdrs->extra_heads[tmp]);    if (hdrs->text) _rettext = hdrs->text;    return "";   }
110:    int t=time();    if(!m->now)    { -  t+=id->conf->api_functions()->time_quantifier[0](id, m); +  t+=time_dequantifier(m);    CACHE(max(t-time(),0));    } else {    NOCACHE();
187:    if (r->error)    _error = r->error;    if (r->extra_heads) -  foreach(indices(r->extra_heads), string tmp) -  add_http_header(_extra_heads, tmp, r->extra_heads[tmp]); -  // _extra_heads += r->extra_heads; +  _extra_heads += r->extra_heads; +  // We do not need this as long as r only contains strings and numbers +  // foreach(indices(r->extra_heads), string tmp) +  // add_http_header(_extra_heads, tmp, r->extra_heads[tmp]);    if (m->text)    _rettext = m->text;   
206:    return ({ "Shows from which page the client linked to this one." });       return({ sizeof(id->referer) ? -  html_encode_string(id->referer*"") : +  m->quote=="none"?id->referer:(html_encode_string(id->referer)):    m->alt || "" });   }   
313:    {    m->width=(string)xysize[0];    m->height=(string)xysize[1]; -  }else{ +  } +  else    tmp+=" Dimensions quering failed.";    } -  }else{ +  else    tmp+=" Virtual path failed"; -  } +     if(!m->alt) {    array src=m->src/"/";    string src=src[sizeof(src)-1];
402:   string tag_date(string q, mapping m, RequestID id)   {    int t=(int)m["unix-time"] || time(1); -  if(m->day) t += (int)m->day * 86400; -  if(m->hour) t += (int)m->hour * 3600; -  if(m->minute) t += (int)m->minute * 60; -  if(m->second) t += (int)m->second; +  t+=time_dequantifier(m);       if(!(m->brief || m->time || m->date))    m->full=1;    -  if(!m->date) -  if(!m->unix_time || m->second) +  if(m->part=="second" || m->part=="beat")    NOCACHE();    else    CACHE(60); // One minute is good enough.
503:      string tag_set_cookie(string tag, mapping m, RequestID id)   { -  string cookies; -  int t; //time -  -  if(m->name) -  cookies = m->name+"="+http_encode_cookie(m->value||""); -  else +  if(!m->name)    return rxml_error(tag, "Requires a name attribute.", id);    -  +  string cookies = m->name+"="+http_encode_cookie(m->value||""); +  int t; //time +     if(m->persistent)    t=(3600*(24*365*2));    else -  t=id->conf->api_functions()->time_quantifier[0](id, m); +  t=time_dequantifier(m);    -  if(t) cookies += "; expires="+http_date(t+time()); +  cookies += "; expires="+http_date(t+time(1));       //FIXME: Check the parameter's usability    cookies += "; path=" +(m->path||"/");
537:    return "";   }    - array(string) tag_user(string tag, mapping m, RequestID id, object file) + string tag_modified(string tag, mapping m, object id, object file)   { -  return ({ id->conf->api_functions()->tag_user_wrapper[0](id, tag, m, file) }); +  array (int) s; +  object f; +  +  if(m->by && !m->file && !m->realfile) +  { +  // FIXME: The auth module should probably not be used in this case. +  if(!id->conf->auth_module) +  return rxml_error(tag, "Modified by requires a user database.", id); +  // FIXME: The next row is defunct. last_modified_by does not exists. +  m->name = id->conf->last_modified_by(file, id); +  CACHE(10); +  return tag_user(tag, m, id, file);    }    - array(string) tag_modified(string tag, mapping m, RequestID id, object file) +  if(m->file)    { -  return ({ id->conf->api_functions()->tag_user_wrapper[0](id, tag, 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 ); +  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); + } +  + string|array(string) tag_user(string tag, mapping m, object id, object file) + { +  string *u; +  string b, dom; +  +  if(!id->conf->auth_module) +  return rxml_error(tag, "Requires a user database.", id); +  +  if (!(b=m->name)) { +  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 &lt;%s@%s&gt;", +  u[4], b, dom) +  }); +  return ({ sprintf("<a href=\"/~%s/\">%s</a> " +  "<a href=\"mailto:%s@%s\">&lt;%s@%s&gt;</a>", +  b, u[4], b, dom, b, dom) +  }); + } +    array(string) tag_set_max_cache( string tag, mapping m, RequestID id )   {    id->misc->cacheable = (int)m->time;
569:    return ({ contents });   }    -  +    array(string) container_catch( string tag, mapping m, string c, RequestID id )   {    string r;
675:    return res;   }    - string container_aprestate(string tag, mapping m, string q, RequestID id) + string container_apre(string tag, mapping m, string q, RequestID id)   {    string href, s, *foo;   
1205:    "expr":lambda( string q){ return (int)sexpr_eval(q); },    ]);   } +  + // ---------------- API registration stuff --------------- +  + string api_query_modified(object id, string f, int|void by) + { +  mapping m = ([ "by":by, "file":f ]); +  return tag_modified("modified", m, id, id); + }