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

version» Context lines:

Roxen.git/server/config_interface/sites/add_module.pike:1: + // $Id: add_module.pike,v 1.80 2005/12/17 22:51:57 jonasw Exp $ +    #include <config_interface.h>   #include <module.h>   #include <module_constants.h>   #include <roxen.h>      int no_reload()   {    if( sizeof( already_added ) )    return 1; // Reloading this script now would destroy state.   }
Roxen.git/server/config_interface/sites/add_module.pike:60:    || ((modinfo->type & MODULE_TYPES) && (o=conf->types_module)))    return roxen.find_module( conf->otomod[o] );   }      // To redirect to when done with module addition   string site_url( RequestID id, string site )   {    return "/sites/site.html/"+site+"/";   }    - string page_base( RequestID id, string content, int|void noform ) + string get_method(RequestID id)   { -  +  // There really is no difference between Normal and Fast    string method =    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, +  int|void show_search_form) + { +  string method = get_method(id); +  +  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'>" +  "<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>"; +     return sprintf( "<use file='/template' />\n"    "<tmpl title=' %s'%s>"    "<topmenu base='/' selected='sites'/>\n"    "<content><cv-split>"    "<subtablist width='100%%'>"    "<st-tabs></st-tabs>"    "<st-page>"    "<if not='1' variable='form.initial'>" -  "<table border='0' cellspacing='4' cellpadding='0'>" -  "<tr><td>%s:</td><td>" +  "<table width='100%%' border='0' cellspacing='4' " +  " cellpadding='0'>" +  "<tr><td nowrap='nowrap'>%s:</td><td>"    "<form action='' style='margin: 0'>"    "<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='fast'>%s</option>"    "<option value='faster'>%s</option>"    "<option value='compact'>%s</option>"    "<option value='really_compact'>%s</option>"    "</select>"    "</default>"    "</form>" -  "</td><td></td>&nbsp;&nbsp;<td>" +  "</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;"    "&reload_module_list=yes&method=%s' "    "> %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(258,"Add module"), +  LOCALE(258,"Add Module"),    noform?" noform='noform'":"", -  LOCALE(0, "List type"), +  LOCALE(0, "List Type"),    method,    LOCALE(0, "Normal"), -  LOCALE(0, "Fast"), +  // LOCALE(0, "Fast"),    LOCALE(0, "Faster"),    LOCALE(0, "Compact"),    LOCALE(0, "Really Compact"), -  +  (show_search_form && search_form) || "",    method, -  LOCALE(272,"Reload module list"), +  LOCALE(272,"Reload Module List"),    LOCALE(202,"Cancel"), -  content ); +  content);   }            string module_name_from_file( string file )   {    string data, name;       catch(data = Stdio.read_bytes( file ));   
Roxen.git/server/config_interface/sites/add_module.pike:287:    sort(w,mods);    for(int i=0; i<sizeof(w); i++)    {    mixed r = w[i];    if(!classes[r[0]])    classes[r[0]] = ([ "doc":r[1], "modules":({}) ]);    if( mods[i]->get_description() )    classes[r[0]]->modules += ({ mods[i] });    }    +  multiset(ModuleInfo) search_modules; +  if (string mod_query = id->variables->mod_query) { +  array(string) mod_query_words = (lower_case(mod_query) / " ") - ({ "" }); +  search_modules = (< >); +  foreach(mods, ModuleInfo m) { +  string compare = +  lower_case(((string) m->get_name() || "") + "\0" + +  m->sname + "\0" + +  m->filename + "\0" + +  Roxen.html_decode_string((string) m->get_description()||"")); +  search_miss: +  { +  foreach(mod_query_words, string w) +  if (!has_value(compare, w)) +  break search_miss; +  search_modules[m] = 1; +  } +  } +  } +     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 )) && -  r[0] ) +  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)    {    if( q->get_description() == "Undocumented" &&    q->type == 0 )    continue; -  +  if (search_modules && !search_modules[q]) +  continue;    object b = module_nomore(q->sname, q, conf);    if( !b && q->locked && (!license_key || !q->unlocked(license_key)) )    {    locked_modules += ({ q });    continue;    }    res += describe_module( q, b );    } -  } else +  } else { +  if (!search_modules)    res += r[1];    } -  +  }    master()->set_inhibit_compile_errors( 0 );    return ({ res, pafeaw( ec->get(), ec->get_warnings(), locked_modules) });   }      string module_image( int type )   {    return "";   }      string strip_leading( LocaleString what )
Roxen.git/server/config_interface/sites/add_module.pike:348:    {    if(!block)    {    return sprintf(    #"    <tr>    <td colspan='2'>    <table width='100%%'>    <tr>    <td><font size='+2'>%s</font></td> -  <td align='right'>(%s) %s</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'> +  <form method='post' action='add_module.pike' +  style='margin: 0 10px 0 0'>    <roxen-automatic-charset-variable/>    <input type='hidden' name='module_to_add' value='%s'>    <input type='hidden' name='config' value='&form.config;'>    <submit-gbutton preparse='1'>%s</submit-gbutton>    </form>    </td>    <td valign='top'>    %s -  <p> -  %s -  </p> +  <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(),
Roxen.git/server/config_interface/sites/add_module.pike:391:    return "";    return "";    }    };   }      array(int|string) class_visible_normal( string c, string d, int size,    RequestID id )   {    int x; -  string method = -  id->variables->method || -  replace(config_setting( "addmodulemethod" ), " ", "_"); +  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>"); +  "bgcolor='&usr.content-titlebg;'><tr><td valign='top'>");    -  if( id->variables->unfolded == c ) { +  if (id->variables->mod_query) { +  x = 1; +  } else if( id->variables->unfolded == c) {    header+=("<a name='"+Roxen.html_encode_string(c)+ -  "'></a><gbutton " +  "'></a><gbutton hspace='5' "    "href='add_module.pike?config=&form.config;"    "&method=" + method + "#"+Roxen.http_encode_url(c)+"' > "+    LOCALE(168, "Hide")+" </gbutton>");    x=1; -  } -  else +  } else {    header+=("<a name='"+Roxen.html_encode_string(c)+ -  "'></a><gbutton " +  "'></a><gbutton hspace='5' "    "href='add_module.pike?config=&form.config;"    "&method=" + method +    "&unfolded="+Roxen.http_encode_url(c)+    "#"+Roxen.http_encode_url(c)+"' > "+    LOCALE(267, "View")+" </gbutton>"); -  +  }       header+=("</td><td width='100%'>"    "<font color='&usr.content-titlefg;' size='+2'>"+c+"</font>"    "<br />"+d+"</td></tr></table></td></tr>\n");       return ({ x, header });   }    - string page_normal( RequestID id, int|void noimage ) +  + string page_normal_low(RequestID id, int|void noimage)   { -  string content = ""; -  content += "<table>"; +     string desc, err;    [desc,err] = get_module_list( describe_module_normal(!noimage),    class_visible_normal, id ); -  content += (desc+"</table>"+err); -  return page_base( id, content, 1 ); +  return +  "<table cellspacing='3' cellpadding='0' border='0' width='100%'>" + +  desc + +  "</table>" + +  err;   }    -  + string page_normal_search(RequestID id, int|void noimage) + { +  return +  "<use file='/template-insert' />\n" +  "<tmpl>" + +  page_normal_low(id, noimage) + +  "</tmpl>"; + } +  + string page_normal( RequestID id, int|void noimage ) + { +  string content = +  "<div id='mod_results' style='display: none'>" +  "</div>" +  "<div id='mod_default'>" + +  page_normal_low(id, noimage) + +  "</div>"; +  return page_base( id, content, 1, 1); + } +    string page_fast( RequestID id )   {    return page_normal( id, 1 );   }      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 align='right'>(%s) %s</td></table></td></tr> -  <tr><td valign='top'><select multiple='multiple' name='module_to_add'> +  <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>%s</p></td> +  </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),    module_image(module->type),    module->sname,    //Roxen.html_encode_string(strip_leading(module->get_name())),    Roxen.html_encode_string(module->get_name()),    module->get_description(),
Roxen.git/server/config_interface/sites/add_module.pike:473:    if( block == module )    return "";    return "";    }   }      array(int|string) class_visible_faster( string c, string d, int size,    RequestID id )   {    int x; -  string method = -  id->variables->method || -  replace(config_setting( "addmodulemethod" ), " ", "_"); +  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>"); +  "<tr><td nowrap='nowrap' valign='top'>");    -  if( id->variables->unfolded == c ) { +  if (id->variables->mod_query) { +  header+=("<gbutton hspace='5' dim='1'> "+LOCALE(267, "View")+ +  " </gbutton><br>" +  "<submit-gbutton hspace='5' vspace='2'> "+LOCALE(0, "Add Modules")+ +  " </submit-gbutton>"); +  x = 1; +  } else if( id->variables->unfolded == c ) {    header+=("<a name='"+Roxen.html_encode_string(c)+ -  "'></a><gbutton dim='1'> "+LOCALE(267, "View")+" </gbutton>" -  "<tr><td><submit-gbutton> "+LOCALE(251, "Add Module")+ -  " </submit-gbutton></td></tr>"); +  "'></a><gbutton hspace='5' dim='1'> "+LOCALE(267, "View")+ +  " </gbutton><br>" +  "<submit-gbutton hspace='5' vspace='2'> "+LOCALE(0, "Add Modules")+ +  " </submit-gbutton>");    x=1;    }    else    header+=("<a name='"+Roxen.html_encode_string(c)+ -  "'></a><gbutton " +  "'></a><gbutton hspace='5' "    "href='add_module.pike?config=&form.config;"    "&method=" + method +    "&unfolded="+Roxen.http_encode_url(c)+    "#"+Roxen.http_encode_url(c)+"' > "+    LOCALE(267, "View")+" </gbutton>");       header+=("</td><td width='100%'>"    "<font color='&usr.content-titlefg;' size='+2'>"+c+"</font>"    "<br />"+d+"</td></tr></table></td></tr>\n");       return ({ x, header });   }    - string page_faster( RequestID id ) + string page_faster_low(RequestID id)   { -  string content = ""; -  content += "<form method='post' action='add_module.pike'>" -  "<input type='hidden' name='config' value='&form.config;'>" -  "<table>"; +     string desc, err;    [desc,err] = get_module_list( describe_module_faster,    class_visible_faster, id ); -  content += (desc+"</table></form>"+err); -  return page_base( id, content ); +  return +  "<form method='post' action='add_module.pike'>" +  "<input type='hidden' name='config' value='&form.config;'>" +  "<table cellspacing='3' cellpadding='0' border='0' width='100%'>" + +  desc + +  "</table>" +  "</form>" + +  err;   }    -  + string page_faster_search(RequestID id) + { +  return +  "<use file='/template-insert' />\n" +  "<tmpl>" + +  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) + +  "</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="";    if(first++) -  res = "</select><br /><submit-gbutton> "+LOCALE(251, "Add Module")+ -  " </submit-gbutton> "; +  res = "</select><br /><submit-gbutton vspace='3'> "+ +  LOCALE(0, "Add Modules")+ " </submit-gbutton> ";    res += "<p><a name='"+Roxen.html_encode_string(c)+    "'></a><font size='+2'>"+c+"</font><br />"+d+"<p>"    "<select size='"+size+"' multiple name='module_to_add' class='add-module-select'>";    return ({ 1, res });   }      string describe_module_compact( object module, object block )   {    if(!block) {    //string modname = strip_leading (module->get_name());
Roxen.git/server/config_interface/sites/add_module.pike:554:      string page_compact( RequestID id )   {    first=0;    string desc, err;    [desc,err] = get_module_list( describe_module_compact,    class_visible_compact, id );    return page_base(id,    "<form action='add_module.pike' method='POST'>"    "<input type='hidden' name='config' value='&form.config;'>"+ -  desc+"</select><br /><submit-gbutton> " -  +LOCALE(251, "Add Module")+" </submit-gbutton><p>" +  desc+"</select><br /><submit-gbutton vspace='3'> " +  +LOCALE(0, "Add Modules")+" </submit-gbutton><p>"    +err+"</form>",    );   }      string page_really_compact( RequestID id )   {    first=0;       object conf = roxen.find_configuration( id->variables->config );    object ec = roxenloader.LowErrorContainer();
Roxen.git/server/config_interface/sites/add_module.pike:596:    in = lower_case((string)in);    //sscanf(in, "%*s: %s", in);    return in;    }), mods);    string res = "";       mixed r;    License.Key license_key = conf->getvar("license")->get_key();    array(RoxenModule) locked_modules = ({});    -  if( (r = class_visible_compact( LOCALE(258,"Add module"), +  if( (r = class_visible_compact( LOCALE(0,"Add Modules"),    LOCALE(273,"Select one or several modules to add."),    sizeof(mods), id )) && r[0] ) {    res += r[1];    foreach(mods, object q) {    if( (!q->get_description() ||    (q->get_description() == "Undocumented")) &&    q->type == 0 )    continue;    object b = module_nomore(q->sname, q, conf);    if( !b && q->locked && (!license_key || !q->unlocked(license_key)) )    {    locked_modules += ({ q });    continue;    }    res += describe_module_compact( q, b );    } -  } else +  } else {    res += r[1]; -  +  }       master()->set_inhibit_compile_errors( 0 );       return page_base(id,    "<form action=\"add_module.pike\" method=\"post\">"    "<input type=\"hidden\" name=\"config\" value=\"&form.config;\" />"+    res+"</select><br /><submit-gbutton> " -  +LOCALE(251, "Add Module")+" </submit-gbutton><br />" +  +LOCALE(0, "Add Modules")+" </submit-gbutton><br />"    +pafeaw(ec->get(),ec->get_warnings(),    locked_modules)+"</form>",    );   }      string decode_site_name( string what )   {    if( (int)what )    return (string)((array(int))(what/","-({""})));    return what;
Roxen.git/server/config_interface/sites/add_module.pike:771:   {    if( !config_perm( "Add Module" ) )    return LOCALE(226, "Permission denied");       if( id->variables->module_to_add &&    id->variables->config )    return do_it( id );       Configuration conf;    foreach(id->variables->config/"\0", string config) { -  if (conf = roxen.find_configuration( id->variables->config )) { +  if (conf = roxen.find_configuration(config)) {    id->variables->config = config;    break;    }    }       if( !config_perm( "Site:"+conf->name ) )    return LOCALE(226,"Permission denied");       if( !conf->inited )    conf->enable_all_modules();    -  string method = -  id->variables->method || -  replace(config_setting( "addmodulemethod" ), " ", "_"); +  string method = get_method(id); +  +  if (id->variables->mod_query) { +  // This can be invoked from both Normal and Faster methods +  return (method == "faster" ? +  page_faster_search(id) : +  page_normal_search(id, 1)); +  } +     return this_object()["page_" + method]( id );   }