Roxen.git / server / config_interface / sites / add_module.pike

version» Context lines:

Roxen.git/server/config_interface/sites/add_module.pike:5:   #include <module_constants.h>   #include <roxen.h>      int no_reload()   {    if( sizeof( already_added ) )    return 1; // Reloading this script now would destroy state.   }      //<locale-token project="roxen_config">LOCALE</locale-token> - #define LOCALE(X,Y) _STR_LOCALE("roxen_config",X,Y) + #define LOCALE(X,Y) _STR_LOCALE("roxen_config",X,Y)      // Class is the name of the directory.   array(string) class_description( string d, RequestID id )   {    string name, doc;    while(!(< "", "/" >)[d] && !Stdio.is_file( d+"/INFO" ))    d = dirname(d);    if((< "", "/" >)[d])    return ({"Local modules", "" });   
Roxen.git/server/config_interface/sites/add_module.pike:76:    id->variables->method ||    replace(config_setting( "addmodulemethod" ), " ", "_");    if (has_value(method, "\0"))    method = (method / "\0")[0];    if (method == "fast")    method = "normal";    id->variables->method = method;    return method;   }    - string page_base( RequestID id, string content, int|void noform, +  + bool show_deprecated(RequestID id) + { +  return !!((int)id->variables->deprecated); + } +  +  + string page_base(RequestID id, string content, int|void noform,    int|void show_search_form)   {    string method = get_method(id); -  +  string tmpl = Stdio.read_file(combine_path(__DIR__, "add_module.mu"));    -  string search_form = -  "<script language='javascript' src='find_module.js'></script>" -  "<script language='javascript'>" -  " query_config = '&form.config;';\n" -  " query_method = '" + method + "';\n" -  "</script>" -  "<table cellspacing='2' cellpadding='0' border='0'>" -  "<tr><td>Find:&nbsp;</td>" -  "<td>" -  "<form style='margin: 0' onsubmit='return false'>" -  "<roxen-wizard-id-variable />" -  "<input type='search' size='30' name='mod_query' id='mod_query' " -  " onkeydown='return query_update_results(event);'" -  " onkeypress='return query_update_results(event);'>" -  "</form>" -  "</td>" -  "<td><img src='/internal-roxen-spinner-white'" -  " id='mod_spinner' style='visibility: hidden'></td>" -  "</tr>" -  "</table>"; +  mapping ctx = ([ +  "title" : LOCALE(251,"Add Module"), +  "noform" : noform, +  "list_type_title" : LOCALE(421, "List Type"), +  "method" : method, +  "search_form" : show_search_form, +  "content" : content, +  "list_types" : ([ +  "normal" : LOCALE(280, "Normal"), +  "faster" : LOCALE(284, "Faster"), +  "compact" : LOCALE(286, "Compact"), +  "rcompact" : LOCALE(531, "Really Compact") +  ]), +  "button" : ([ +  "reload" : LOCALE(272,"Reload Module List"), +  "cancel" : LOCALE(202,"Cancel"), +  ]) +  ]);    -  return sprintf( "<use file='/template' />" -  "<tmpl title=' %s'%s>" -  "<topmenu base='/' selected='sites'/>" -  "<content><cv-split>" -  "<subtablist width='100%%'>" -  "<st-tabs></st-tabs>" -  "<st-page>" -  "<h2>Site: '&form.config;'</h2>" -  "<if not='1' variable='form.initial'>" -  "<table width='100%%' border='0' cellspacing='4' " -  " cellpadding='0'>" -  "<tr><td nowrap='nowrap'>%s:</td><td>" -  "<form action='' style='margin: 0'>" -  "<roxen-wizard-id-variable />" -  "<input type='hidden' name='config' value='&form.config;'>" -  "<default variable='form.method' value='%s'>" -  "<select name='method' onchange='submit()'>" -  "<option value='normal'>%s</option>" -  // "<option value='fast'>%s</option>" -  "<option value='faster'>%s</option>" -  "<option value='compact'>%s</option>" -  "<option value='really_compact'>%s</option>" -  "</select>" -  "</default>" -  "</form>" -  "</td>" -  "<td>&nbsp;&nbsp;</td>" -  "<td width='100%%' nowrap='nowrap'>%s</td>" // search form -  "<td>&nbsp;&nbsp;</td>" -  "<td align='right'>" -  "<gbutton href='add_module.pike?config=&form.config:http;" -  "&amp;reload_module_list=yes&amp;method=%s&amp;&usr.set-wiz-id;' " -  "> %s </gbutton>" -  "</td><td>" -  "<gbutton href='site.html/&form.config;/' " -  "> %s </gbutton>" -  "</td></tr></table>" -  "<p>\n</if>%s\n</p>\n" -  "</st-page></subtablist></td></tr></table>" -  "</cv-split></content></tmpl>", -  LOCALE(251,"Add Module"), -  noform?" noform='noform'":"", -  LOCALE(421, "List Type"), -  method, -  LOCALE(280, "Normal"), -  // LOCALE(0, "Fast"), -  LOCALE(284, "Faster"), -  LOCALE(286, "Compact"), -  LOCALE(531, "Really Compact"), -  (show_search_form && search_form) || "", -  method, -  LOCALE(272,"Reload Module List"), -  LOCALE(202,"Cancel"), -  content); +  return Mustache()->render(tmpl, ctx);   }    -  -  +    string module_name_from_file( string file )   {    string data, name;       catch(data = Stdio.read_bytes( file ));       if( data    && sscanf( data, "%*smodule_name%*s=%[^;];", name )    && sscanf( name, "%*[^\"]\"%s\"", name ) )    return Roxen.html_encode_string(name);
Roxen.git/server/config_interface/sites/add_module.pike:226:    continue;    }    }    res += ({ e });    }    if( sizeof( res ) )    {    string he( string what )    {    if( what == "Error" ) -  return "<font color='&usr.warncolor;'>"+what+"</font>"; +  return "<span class='notify warn inline'>"+what+"</span>";    return what;    };       string hc( string what )    {    return what;    };       string trim_name( string what )    {    array q = (what / "/");    return q[sizeof(q)-2..]*"/";    };    - #define RELOAD(X) sprintf("<gbutton " \ -  "img-align='middle' " \ + #define RELOAD(X) sprintf("<link-gbutton " \ +  "type='reload' " \    "href='add_module.pike?config=&form.config:http;" \ -  "&amp;method=&form.method;" \ -  "&amp;random=%d&amp;only=%s" \ -  "&amp;reload_module_list=yes" \ -  "&amp;&usr.set-wiz-id;" \ -  "#errors_and_warnings'> %s </gbutton>", \ +  "&amp;method=&form.method;" \ +  "&amp;random=%d&amp;only=%s" \ +  "&amp;reload_module_list=yes" \ +  "&amp;&usr.set-wiz-id;" \ +  "#errors_and_warnings'>%s</link-gbutton>", \    random(4711111), \    (X), \    LOCALE(253, "Reload"))       if( !header_added++ )    da_string +=    "<p><a name='errors_and_warnings'></a><br />"    "<font size='+2'><b><font color='&usr.warncolor;'>"    "Compile errors and warnings</font></b><br />"    "<table width=100% cellpadding='3' cellspacing='0' border='0'>";
Roxen.git/server/config_interface/sites/add_module.pike:292:       return da_string + format_locked_modules(locked_modules);   }      string format_locked_modules(array(ModuleInfo) locked_modules)   {    if(!sizeof(locked_modules))    return "";       return -  "<font size='+1'>Locked modules</font><br />\n" -  "These modules are locked and can not be enabled because they are " -  "not part of the license key for this configuration.<br />\n" -  "<blockquote><font color='darkred'>"+ -  (((array(string))locked_modules->get_name())*"<br />\n")+"</font></blockquote>"; +  "<p class='large'>Locked modules</p>\n" +  "<p>These modules are locked and can not be enabled because they are " +  "not part of the license key for this configuration.</p>\n" +  "<div class='notify error'>"+ +  (((array(string))locked_modules->get_name())*"<br />\n")+"</div>";   }      array(string) get_module_list( function describe_module,    function class_visible, -  RequestID id ) +  RequestID id, +  void|bool fast)   {    object conf = roxen.find_configuration( id->variables->config );    object ec = roxenloader.LowErrorContainer();    int do_reload;    master()->set_inhibit_compile_errors( ec );       if( id->variables->reload_module_list )    roxen->clear_all_modules_cache();       array(ModuleInfo) mods;    roxenloader.push_compile_error_handler( ec );    mods = roxen->all_modules();    roxenloader.pop_compile_error_handler();    -  foreach( mods, ModuleInfo m ) -  if( module_nomore( m->sname, m, conf ) ) +  foreach( mods, ModuleInfo m ) { +  if (m->deprecated && !show_deprecated(id)) { +  TRACE("::: DEPRECATED ModuleInfo: %O\n", m);    mods -= ({ m }); -  +  } +  if( module_nomore( m->sname, m, conf ) ) { +  mods -= ({ m }); +  } +  }       string res = "";    string doubles="", already="";    array w = map(mods, module_class, id);       mapping classes = ([]);    sort(w,mods);    for(int i=0; i<sizeof(w); i++)    {    mixed r = w[i];
Roxen.git/server/config_interface/sites/add_module.pike:363:    }       License.Key license_key = conf->getvar("license")->get_key();    array(RoxenModule) locked_modules = ({});       foreach( sort(indices(classes)), string c )    {    mixed r;    if( c == "" )    continue; -  if( (r = class_visible( c, classes[c]->doc, sizeof(classes[c]->modules), id )) && +  if( (r = class_visible( c, classes[c]->doc, sizeof(classes[c]->modules), id, fast)) &&    r[0] &&    (!search_modules ||    sizeof(classes[c]->modules & indices(search_modules))))    {    res += r[1];    array m = classes[c]->modules;    array q = m->get_name();    sort( q, m );    foreach(m, object q)    {
Roxen.git/server/config_interface/sites/add_module.pike:409:    return "";   }      string strip_leading( LocaleString what )   {    if( !what ) return 0;    sscanf( (string)what, "%*s:%*[ \t]%s", what );    return what;   }    -  - function describe_module_normal( int image ) + function describe_module_normal(void|bool faster)   { -  return lambda( object module, object block) +  return lambda(object module, object block)    { -  if(!block) -  { -  return sprintf( -  #" -  <tr> -  <td colspan='2'> -  <table width='100%%'> -  <tr> -  <td><font size='+2'>%s</font></td> -  <td align='right'><span class='dimtext'>(%s)</span> %s</td> -  </tr> -  </table> -  </td> -  </tr> -  <tr> -  <td valign='top'> -  <form method='post' action='add_module.pike' -  style='margin: 0 10px 0 0'> +  if (!block) { +  string tmpl = #" +  <div class='module{{#deprecated}} deprecated{{/deprecated}}'> +  <div class='flex-row header'> +  <div class='flex flex-grow'><h3>{{ name }}</h3></div> +  <div class='flex flex-shrink'><span class='dim'>({{ sname }})</span></div> +  </div> +  <div class='row'> +  <div class='float-right'> +  {{ #faster }} +  <label for='mod-{{ sname }}' class='module-checkbox' tabindex='0' +  data-toggle-cb-event=''> +  <input type='checkbox' value='{{ sname }}' name='module_to_add' +  id='mod-{{ sname }}' data-toggle-cb=''> +  <span>Select</span> +  </label> +  {{ /faster }} +  {{ ^faster }} +  <form method='post' action='add_module.pike'>    <roxen-automatic-charset-variable/>    <roxen-wizard-id-variable /> -  <input type='hidden' name='module_to_add' value='%s'> +  <input type='hidden' name='module_to_add' value='{{ sname }}'>    <input type='hidden' name='config' value='&form.config;'> -  <submit-gbutton preparse='1'>%s</submit-gbutton> +  <submit-gbutton type='add'>{{ add_label }}</submit-gbutton>    </form> -  </td> -  <td valign='top'> -  %s -  <p class='dimtext'>%s</p> -  </td> -  </tr> - ", -  //Roxen.html_encode_string(strip_leading(module->get_name())), -  Roxen.html_encode_string(module->get_name()), -  Roxen.html_encode_string (module->sname), -  (image?module_image(module->type):""), -  module->sname, -  LOCALE(251, "Add Module"), -  module->get_description() || LOCALE(1023, "Undocumented"), -  LOCALE(266, "Will be loaded from: ")+module->filename - ); -  } else { -  if( block == module ) -  return ""; -  return ""; +  {{ /faster }} +  </div> +  <div class='doc'> +  {{ &doc }} +  <p class='dim'>{{ load_path }}</p> +  </div> +  </div> +  </div>"; +  +  string doc = module->get_description(); +  +  if (doc) { +  if (objectp(doc)) { +  doc = (string) doc;    } -  +  +  doc = String.trim_all_whites(doc); +  +  if (search(doc, "<p") == -1) { +  doc = "<p>" + doc + "</p>"; +  } +  } +  else { +  doc = "<p>" + ((string)LOCALE(1023, "Undocumented")) + "</p>"; +  } +  +  mapping ctx = ([ +  "name" : module->get_name(), +  "sname" : module->sname, +  "add_label" : LOCALE(251, "Add Module"), +  "doc" : doc, +  "load_path" : LOCALE(266, "Will be loaded from: ")+module->filename, +  "faster" : faster, +  "deprecated" : module->deprecated +  ]); +  +  return Mustache()->render(tmpl, ctx); +  } +  +  return "";    };   }    - array(int|string) class_visible_normal( string c, string d, int size, -  RequestID id ) + array(int|string) class_visible_normal(string c, string d, int size, +  RequestID id, void|bool fast)   {    int x;    string method = get_method(id); -  string header = ("<tr><td colspan='2'><table width='100%' " -  "cellspacing='0' border='0' cellpadding='3' " -  "bgcolor='&usr.content-titlebg;'><tr><td valign='top'>"); +  string header;    -  +  // LOCALE(168, "Hide") +  // LOCALE(267, "View") +  +  array(array(string)) qs = ({ +  ({ "config", "&form.config;" }), +  ({ "method", "&form.method;" }) +  }); +     if (id->variables->mod_query) {    x = 1; -  } else if( id->variables->unfolded == c) { -  header+=("<a name='"+Roxen.html_encode_string(c)+ -  "'></a><gbutton hspace='5' vspace='5' " -  "href='add_module.pike?config=&form.config;" -  "&amp;method=" + method + "&amp;&usr.set-wiz-id;#"+ -  Roxen.http_encode_url(c)+"' > "+ -  LOCALE(168, "Hide")+" </gbutton>"); -  x=1; -  } else { -  header+=("<a name='"+Roxen.html_encode_string(c)+ -  "'></a><gbutton hspace='5' vspace='5' " -  "href='add_module.pike?config=&form.config;" -  "&amp;method=" + method + -  "&amp;unfolded="+Roxen.http_encode_url(c)+ -  "&amp;&usr.set-wiz-id;#"+Roxen.http_encode_url(c)+"' > "+ -  LOCALE(267, "View")+" </gbutton>"); +     } -  +  else if( id->variables->unfolded == c) { +  x = 1; +  } +  else { +  qs += ({ ({ "unfolded", Roxen.http_encode_url(c) }) }); +  }    -  header+=("</td><td width='100%'>" -  "<font color='&usr.content-titlefg;' size='+2'>"+c+"</font>" -  "<br />"+d+"</td></tr></table></td></tr>\n"); +  if (show_deprecated(id)) { +  qs += ({ ({ "deprecated", "1" }) }); +  }    -  +  string qss = sprintf("%{%s=%s&amp;%}", qs); +  +  qss += "&usr.set-wiz-id;#" + Roxen.http_encode_url(c); +  +  string content = sprintf("<a href='add_module.pike?%s'><dl><dt>%s</dt>", +  qss, c); +  +  if (d && sizeof(String.trim_all_whites(d))) { +  content += "<dd>" + d + "</dd>"; +  } +  +  content += "</dl></a>"; +  +  if (x && fast) { +  content = +  "<div class='float-right select-multiple'>" +  "<submit-gbutton2 type='add'>Add modules</submit-gbutton2>" +  "</div>" + +  content; +  } +  +  header = sprintf("<div class='group-header action-group%s' id='%s'>%s</div>\n", +  x ? " open" : " closed", +  Roxen.html_encode_string(c), +  content); +     return ({ x, header });   }       - string page_normal_low(RequestID id, int|void noimage) + string page_normal_low(RequestID id, int|void fast)   {    string desc, err; -  [desc,err] = get_module_list( describe_module_normal(!noimage), -  class_visible_normal, id ); -  return -  "<table cellspacing='3' cellpadding='0' border='0' width='100%'>" + -  desc + -  "</table>" + -  err; +  [desc,err] = get_module_list(describe_module_normal(fast), +  class_visible_normal, id, fast); +  +  string ret = "<div class='add-modules-wrapper'>"; +  +  if (fast) { +  ret += "<input type='hidden' name='config' value='&form.config;'>";    }    - string page_normal_search(RequestID id, int|void noimage) +  return ret + desc + "</div>" + err; + } +  + string page_normal_search(RequestID id, void|bool fast)   {    return    "<use file='/template-insert' />\n"    "<tmpl>" + -  page_normal_low(id, noimage) + +  page_normal_low(id, fast) +    "</tmpl>";   }    - string page_normal( RequestID id, int|void noimage ) + string page_normal( RequestID id, void|bool fast )   {    string content =    "<div id='mod_results' style='display: none'>"    "</div>"    "<div id='mod_default'>" + -  page_normal_low(id, noimage) + +  page_normal_low(id, fast) +    "</div>";    return page_base( id, content, 1, 1);   }      string page_fast( RequestID id )   { -  return page_normal( id, 1 ); +  return page_normal(id);   }      string describe_module_faster( object module, object block)   {    if(!block)    {   return sprintf(    #"    <tr><td colspan='2'><table width='100%%'> -  <td><font size='+2'>%s</font></td> +  <td>#FASTER#<font size='+2'>%s</font></td>    <td align='right'><span class='dimtext'>(%s)</span> %s</td></table>    </td></tr>    <tr><td valign='top'><select multiple='multiple' size='1'    name='module_to_add'>    <option value='%s'>%s</option></select>    </td><td valign='top'>%s<p class='dimtext'>%s</p></td>    </tr>   ",    //Roxen.html_encode_string(strip_leading(module->get_name())),    Roxen.html_encode_string(module->get_name()),
Roxen.git/server/config_interface/sites/add_module.pike:639:    page_faster_low(id) +    "</tmpl>";   }      string page_faster( RequestID id )   {    string content =    "<div id='mod_results' style='display: none'>"    "</div>"    "<div id='mod_default'>" + -  page_faster_low(id) + +  page_normal_low(id, true) +    "</div>";    return page_base( id, content, 0, 1);   }      int first;      array(int|string) class_visible_compact( string c, string d, int size,    RequestID id )   {    string res="";
Roxen.git/server/config_interface/sites/add_module.pike:929:    string method = get_method(id);       if (id->variables->mod_query) {    // Force UTF-8 to please some browsers that can't guess charset in    // XMLHttpRequest communication.    id->set_output_charset && id->set_output_charset("UTF-8");       // This can be invoked from both Normal and Faster methods    return (method == "faster" ?    page_faster_search(id) : -  page_normal_search(id, 1)); +  page_normal_search(id));    }       return this_object()["page_" + method]( id );   }