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.117 2009/10/13 11:55:27 mast Exp $ + // $Id$      #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:523:    //! If a string is thrown, it will be used as a error message from    //! set, and the variable will not be changed.    {    return ({ 0, new_value });    }       mapping(string:string) get_form_vars( RequestID id )    //! Return all form variables preficed with path().    {    string p = path(); -  array names = glob( p+"*", indices(id->variables) ); +  array names = glob( p+"*", indices(id->real_variables) );    mapping res = ([ ]);    foreach( sort(names), string n ) -  res[ n[strlen(p).. ] ] = id->variables[ n ]; +  res[ n[strlen(p).. ] ] = id->real_variables[ n ][0];    return res;    }       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;    }       int(0..1) set_from_form( RequestID id, void|int(0..1) force ) -  //! Set this variable from the form variable in id->Variables, +  //! 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. @[force]    //! forces the variable to be set even if the variable already    //! has the new value, forcing possible warnings to be added.    //! Returns 1 if the variable was changed, otherwise 0.    //!    //! Other side effects: Might create warnings to be shown to the    //! user (see get_warnings)    //!    //! Calls verify_set_from_form and verify_set
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:769:    {    return Roxen.html_encode_string( _format(query()) );    }       string render_form( RequestID id, void|mapping additional_args )    {    int size = 15;    if( _max != no_limit && _min != no_limit )    size = max( strlen(_format(_max)), strlen(_format(_min)) )+2;    string value; +  catch {    if (_may_be_empty && (float)query() == (float)0)    value = "";    else    value = query()==""? "" : _format( (float)query() ); -  +  };       additional_args = additional_args || ([]); -  +  if (!additional_args->type)    additional_args->type="text";       return input(path(), value, size, additional_args);    }       void may_be_empty(int(0..1) state)    //! Decides if an empty variable also is valid.    {    _may_be_empty = state;    }
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:876:    }       string render_form( RequestID id, void|mapping additional_args )    {    int size = 10;    if( _min != no_limit && _max != no_limit )    size = max( strlen((string)_max), strlen((string)_min) )+2;    string value = (query() == 0 && _is_empty)? "" : (string)query();       additional_args = additional_args || ([]); +  if (!additional_args->type)    additional_args->type="text";       return input(path(), value, size, additional_args);    }       void may_be_empty(int(0..1) state)    //! Decides if an empty variable also is valid.    {    _may_be_empty = state;    }
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:921:    }       array(string) verify_set_from_form( mixed new )    {    return ({ 0, [string]new-"\r" });    }       string render_form( RequestID id, void|mapping additional_args )    {    additional_args = additional_args || ([]); +  if (!additional_args->type)    additional_args->type="text";    return input(path(), (string)query(), width, additional_args);    }   }      // =====================================================================   // Text   // =====================================================================   class Text   //! Text (multi-line string) variable
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:999:    }      }            // =====================================================================   // Password   // =====================================================================   class Password - //! Password variable (uses crypt) + //! Password variable (uses crypt_password)   {    inherit String;    int width = 20;    constant type = "Password";       int(0..1) set_from_form( RequestID id )    {    mapping val;    if( sizeof( val = get_form_vars(id)) &&    val[""] && strlen(val[""]) ) { -  set( crypt( val[""] ) ); +  set( crypt_password( val[""] ) );    return 1;    }    return 0;    }       string render_view( RequestID id )    {    return "******";    }   
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1648:    // first do the assign...    if( (int)vl[".count"] != _current_count )    return 0;    _current_count++;    set_warning(0);       foreach( indices( vl ), string vv )    if( sscanf( vv, ".set.%d", rn ) && (vv == ".set."+rn) )    {    if ((rn >= 0) && (rn < sizeof(l))) { -  m_delete( id->variables, path()+vv ); +  m_delete( id->real_variables, path()+vv );    l[rn] = transform_from_form( vl[vv], vl );    m_delete( vl, vv );    } else {    report_debug("set_from_form(%O): vv:%O sizeof(l):%d\n",    id, vv, sizeof(l));    }    }    // 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( id->real_variables, path()+vv );    m_delete( vl, vv );    l = l[..rn-2] + l[rn..rn] + l[rn-1..rn-1] + l[rn+1..];    }    else if( sscanf( vv, ".down.%d.x%*s", rn )==2 )    {    do_goto = 1; -  m_delete( id->variables, path()+vv ); +  m_delete( id->real_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" ); +  m_delete( id->real_variables, path()+".new.x" );    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 ); +  m_delete( id->real_variables, path()+vv );    l = l[..rn-1] + l[rn+1..];    }       array b;    mixed q = catch( b = verify_set_from_form( l ) );    if( q || sizeof( b ) != 2 )    {    if( q )    add_warning( q );    else
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:2117:   string input(string name, string value, int size,    void|mapping(string:string) args, void|int noxml)   {    if(!args)    args=([]);    else    args+=([]);       args->name=name;    if(value) -  args->value=value; +  args->value = Roxen.html_encode_string(value);    if(!args->size && size)    args->size=(string)size;       string render="<input";       foreach(indices(args), string attr) {    render+=" "+attr+"=";    if(!has_value(args[attr], "\"")) render+="\""+args[attr]+"\"";    else if(!has_value(args[attr], "'")) render+="'"+args[attr]+"'";    else render+="'"+replace(args[attr], "'", "&#39;")+"'";    }    -  + // render = "<tt>" + Roxen.html_encode_string(name) + "</tt><br />\n" + render; +     if(noxml) return render+">";    return render+" />";   }