Roxen.git / server / etc / modules / Variable.pmod / module.pmod

version» Context lines:

Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1: - // $Id: module.pmod,v 1.45 2001/01/29 05:44:37 per Exp $ + // $Id: module.pmod,v 1.46 2001/02/02 07:30:35 per Exp $      #include <module.h>   #include <roxen.h>      // Locale macros   //<locale-token project="roxen_config"> LOCALE </locale-token>      #define LOCALE(X,Y) \    ([string](mixed)Locale.translate("roxen_config",roxenp()->locale->get(),X,Y))   
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:296:    //! Return all form variables preficed with path().    {    string p = path();    array names = glob( p+"*", indices(id->variables) );    mapping res = ([ ]);    foreach( sort(names), string n )    res[ n[strlen(p).. ] ] = id->variables[ n ];    return res;    }    -  mixed transform_from_form( string what ) +  mixed transform_from_form( string what,mapping|void v )    //! Given a form value, return what should be set.    //! Used by the default set_from_form implementation.    {    return what;    }       void set_from_form( RequestID id )    //! Set this variable from the form variable in id->Variables,    //! if any are available. The default implementation simply sets    //! the variable to the string in the form variables.
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:908:    constant type="List";    constant width = 40;       string transform_to_form( mixed what )    //! Override this function to do the value->form mapping for    //! individual elements in the array.    {    return (string)what;    }    -  mixed transform_from_form( string what ) +  mixed transform_from_form( string what,mapping v )    {    return what;    }       static int _current_count = time()*100+(gethrtime()/10000);    void set_from_form(RequestID id)    {    int rn, do_goto;    array l = query();    mapping vl = get_form_vars(id);    // first do the assign...    if( (int)vl[".count"] != _current_count )    return;    _current_count++;       foreach( indices( vl ), string vv ) -  if( sscanf( vv, ".set.%d", rn ) ) +  if( sscanf( vv, ".set.%d", rn ) && (vv == ".set."+rn) )    {    m_delete( id->variables, path()+vv ); -  l[rn] = transform_from_form( vl[vv] ); +  l[rn] = transform_from_form( vl[vv], vl );    m_delete( vl, vv );    }    // then the move...    foreach( indices(vl), string vv )    if( sscanf( vv, ".up.%d.x%*s", rn ) == 2 )    {    do_goto = 1;    m_delete( id->variables, path()+vv );    m_delete( vl, vv );    l = l[..rn-2] + l[rn..rn] + l[rn-1..rn-1] + l[rn+1..];
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:951:    {    do_goto = 1;    m_delete( id->variables, path()+vv );    l = l[..rn-1] + l[rn+1..rn+1] + l[rn..rn] + l[rn+2..];    }    // then the possible add.    if( vl[".new.x"] )    {    do_goto = 1;    m_delete( id->variables, path()+".new.x" ); -  l += ({ transform_from_form( "" ) }); +  l += ({ transform_from_form( "",vl ) });    }       // .. and delete ..    foreach( indices(vl), string vv )    if( sscanf( vv, ".delete.%d.x%*s", rn )==2 )    {    do_goto = 1;    m_delete( id->variables, path()+vv );    l = l[..rn-1] + l[rn+1..];    }
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1005:    "Location":nid->not_query+(nid->misc->path_info||"")+    "?"+query+"#"+path(),    ]);    if( nid->misc->defines )    nid->misc->defines[ " _error" ] = 302;    else if( id->misc->defines )    id->misc->defines[ " _error" ] = 302;    }    }    +  +  string render_row(string prefix, mixed val, int width) +  { +  return input( prefix, val, width ); +  } +     string render_form( RequestID id, void|mapping additional_args )    {    string prefix = path()+".";    int i;       string res = "<a name='"+path()+"'>\n</a><table>\n"    "<input type='hidden' name='"+prefix+"count' value='"+_current_count+"' />\n";    -  foreach( map(query(), transform_to_form), string val ) +  foreach( map(query(), transform_to_form), mixed val )    { -  res += "<tr>\n<td><font size='-1'>"+ input( prefix+"set."+i, val, width) + "</font></td>\n"; +  res += "<tr>\n<td><font size='-1'>"+ render_row(prefix+"set."+i, val, width) +  + "</font></td>\n";   #define BUTTON(X,Y) ("<submit-gbutton2 name='"+X+"'>"+Y+"</submit-gbutton2>")   #define REORDER(X,Y) ("<submit-gbutton2 name='"+X+"' icon-src='"+Y+"'></submit-gbutton2>")    if( i )    res += "\n<td>"+    REORDER(prefix+"up."+i, "/internal-roxen-up")+    "</td>";    else    res += "\n<td></td>";    if( i != sizeof( query())- 1 )    res += "\n<td>"+
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1092:   }      class IntList   //! A list of integers   {    inherit List;    constant type="IntList";    constant width=20;       string transform_to_form(int what) { return (string)what; } -  int transform_from_form(string what) { return (int)what; } +  int transform_from_form(string what,mapping v) { return (int)what; }   }      class FloatList   //! A list of floating point numbers   {    inherit List;    constant type="DirectoryList";    constant width=20;       static int _prec = 3;
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1116:    //! If prec is 3, and the float is 1, 1.000 will be shown.    //! Default is 2.    {    _prec = prec;    }       string transform_to_form(int what)    {    return sprintf("%1."+_prec+"f", what);    } -  float transform_from_form(string what) { return (float)what; } +  float transform_from_form(string what,mapping v) { return (float)what; }   }      class URLList   //! A list of URLs   {    inherit List;    constant type="URLList";       array verify_set_from_form( array(string) new_value )    {
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1149:    return ({ warn, res });    }   }      class PortList   //! A list of Port URLs   {    inherit List;    constant type="PortList";    +  string render_row( string prefix, mixed val, int width ) +  { +  string res = "<input type=hidden name='"+prefix+"' value='"+prefix+"' />"; +  +  array split = val/"://"; +  +  res += "<select name='"+prefix+"prot'>"; +  foreach( sort(indices( roxenp()->protocols )), string p ) +  { +  if( p == split[0] ) +  res += "<option selected='t'>"+p+"</option>"; +  else +  res += "<option>"+p+"</option>"; +  } +  res += "</select>"; +  +  split = split[-1]/"/"; +  if( sizeof( split ) > 2 ) +  split[1] = split[1..]*"/"; +  else if( sizeof( split ) < 2 ) +  split += ({ "" }); +  +  res += "://<input type=string name='"+prefix+"host' value='"+ +  Roxen.html_encode_string(split[0])+"' />"; +  +  res += "/<input type=string name='"+prefix+"path' value='"+ +  Roxen.html_encode_string(split[1])+"' />"; +  +  return res; +  } +  +  string transform_from_form( string v, mapping va ) +  { +  if( v == "" ) return "http://*/"; +  +  werror("%O %O %O\n", v, v[strlen(path())..],va ); +  v = v[strlen(path())..]; +  return va[v+"prot"]+"://"+va[v+"host"]+"/"+va[v+"path"]; +  } +     array verify_set_from_form( array(string) new_value )    {    string warn = "";    array res = ({});    foreach( new_value, string vv )    {    string tmp1, tmp2;    [tmp1,tmp2] = verify_port( vv, 0 );    if( tmp1 )    warn += tmp1;