0917d32013-03-04Anders Johansson // $Id$
f025022005-12-17Jonas Wallden 
f26aee2000-01-31Per Hedbor #include <config_interface.h> #include <module.h>
f0a70e2000-07-21Martin Nilsson #include <module_constants.h>
0c694f2000-07-23Martin Nilsson #include <roxen.h>
6647b52017-06-09Pontus Östlund // int no_reload() // { // if( sizeof( already_added ) ) // return 1; // Reloading this script now would destroy state. // }
10745b2001-01-29Per Hedbor 
0c694f2000-07-23Martin Nilsson //<locale-token project="roxen_config">LOCALE</locale-token>
a840292017-06-02Pontus Östlund #define LOCALE(X,Y) _STR_LOCALE("roxen_config",X,Y)
f26aee2000-01-31Per Hedbor 
ab9b6d2000-02-11Per Hedbor // Class is the name of the directory.
c2b2722000-05-22Martin Nilsson array(string) class_description( string d, RequestID id )
ab9b6d2000-02-11Per Hedbor { string name, doc;
db7f382013-07-02Pontus Rodling  while(!(< "", "/" >)[d] && !Stdio.is_file( d+"/INFO" ))
ab9b6d2000-02-11Per Hedbor  d = dirname(d);
14bc712000-02-11Henrik Grubbström (Grubba)  if((< "", "/" >)[d])
ab9b6d2000-02-11Per Hedbor  return ({"Local modules", "" }); string n = Stdio.read_bytes( d+"/INFO" ); sscanf( n, "<"+id->misc->config_locale+">%s" "</"+id->misc->config_locale+">", n ); sscanf( n, "%*s<name>%s</name>", name ); sscanf( n, "%*s<doc>%s</doc>", doc );
d39c492000-03-28Per Hedbor  if( search(n, "<noshow/>" ) != -1 ) return ({ "", "" });
ab9b6d2000-02-11Per Hedbor  if(!name) return ({"Local modules", "" }); if(!doc) doc =""; return ({ name, doc }); }
c2b2722000-05-22Martin Nilsson array(string) module_class( object m, RequestID id )
ab9b6d2000-02-11Per Hedbor { return class_description( m->filename, id ); }
f26aee2000-01-31Per Hedbor object module_nomore(string name, object modinfo, object conf) { mapping module; object o; if(!modinfo) return 0; if(!modinfo->multiple_copies && (module = conf->modules[name]) && sizeof(module->copies) ) return modinfo; if(((modinfo->type & MODULE_DIRECTORIES) && (o=conf->dir_module)) || ((modinfo->type & MODULE_AUTH) && (o=conf->auth_module)) || ((modinfo->type & MODULE_TYPES) && (o=conf->types_module)))
a38da12000-08-20Per Hedbor  return roxen.find_module( conf->otomod[o] );
f26aee2000-01-31Per Hedbor } // To redirect to when done with module addition string site_url( RequestID id, string site ) {
c170ce2001-01-28Per Hedbor  return "/sites/site.html/"+site+"/";
f26aee2000-01-31Per Hedbor }
f025022005-12-17Jonas Wallden string get_method(RequestID id)
f26aee2000-01-31Per Hedbor {
f025022005-12-17Jonas Wallden  // There really is no difference between Normal and Fast
d6b1b52005-12-17Jonas Wallden  string method = id->variables->method || replace(config_setting( "addmodulemethod" ), " ", "_");
f025022005-12-17Jonas Wallden  if (has_value(method, "\0")) method = (method / "\0")[0]; if (method == "fast") method = "normal"; id->variables->method = method; return method; }
a840292017-06-02Pontus Östlund bool show_deprecated(RequestID id) { return !!((int)id->variables->deprecated);
f26aee2000-01-31Per Hedbor }
1577242000-08-19Per Hedbor 
a840292017-06-02Pontus Östlund 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")); 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"), ]) ]);
bf66c32018-02-28Pontus Östlund  return Roxen.render_mustache(tmpl, ctx);
a840292017-06-02Pontus Östlund }
1577242000-08-19Per Hedbor  string module_name_from_file( string file ) { string data, name; catch(data = Stdio.read_bytes( file ));
a840292017-06-02Pontus Östlund 
1577242000-08-19Per Hedbor  if( data && sscanf( data, "%*smodule_name%*s=%[^;];", name ) && sscanf( name, "%*[^\"]\"%s\"", name ) )
6b394a2000-10-13Martin Nilsson  return Roxen.html_encode_string(name); return Roxen.html_encode_string(((file/"/")[-1]/".")[0]);
1577242000-08-19Per Hedbor }
e4445e2002-02-26Marcus Wellhardh string pafeaw( string errors, string warnings, array(ModuleInfo) locked_modules) // Parse And Format Errors And Warnings (and locked modules).
1577242000-08-19Per Hedbor // Your ordinary prettyprinting function. { mapping by_module = ([]); int cnt = 0; foreach( (errors+warnings)/"\n", string e ) { string file; int row; string type, error; sscanf( e, "%s:%d%s", file, row, error ); if( error ) { sscanf( error, "%*[ \t]%s", error ); sscanf( error, "%s: %s", type, error ); if( by_module[ file ] ) by_module[ file ] += ({ ({ row*10000 + cnt++, row, type, error }) }); else by_module[ file ] = ({ ({ row*10000 + cnt++, row, type, error }) }); } }
468b6c2017-10-04Pontus Östlund  string da_string = "", divider;
1577242000-08-19Per Hedbor  int header_added; foreach( sort((array)by_module), [string module, array errors] ) {
468b6c2017-10-04Pontus Östlund  if (divider) { da_string += divider; divider = 0; }
1577242000-08-19Per Hedbor  array res = ({ }); int remove_suspicious = 0; sort( errors ); foreach( errors, array e )
a840292017-06-02Pontus Östlund  {
1577242000-08-19Per Hedbor  if( e[2] == "Error" ) { remove_suspicious = 1; switch( e[3] ) { case "Must return a value for a non-void function.": case "Class definition failed.": case "Illegal program pointer.": case "Illegal program identifier": continue; } } res += ({ e }); } if( sizeof( res ) ) { string he( string what ) { if( what == "Error" )
a840292017-06-02Pontus Östlund  return "<span class='notify warn inline'>"+what+"</span>";
1577242000-08-19Per Hedbor  return what; }; string hc( string what ) { return what; }; string trim_name( string what ) { array q = (what / "/"); return q[sizeof(q)-2..]*"/"; };
a840292017-06-02Pontus Östlund #define RELOAD(X) sprintf("<link-gbutton " \ "type='reload' " \
80cd682003-11-17Anders Johansson  "href='add_module.pike?config=&form.config:http;" \
a840292017-06-02Pontus Östlund  "&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>", \
80cd682003-11-17Anders Johansson  random(4711111), \ (X), \
1577242000-08-19Per Hedbor  LOCALE(253, "Reload"))
1a54012017-07-25Pontus Östlund  if( !header_added++ ) {
a840292017-06-02Pontus Östlund  da_string +=
1a54012017-07-25Pontus Östlund  "<hr><a name='errors_and_warnings'></a>" "<h3>Compile errors and warnings</h3>" "<table>"; }
1577242000-08-19Per Hedbor 
468b6c2017-10-04Pontus Östlund  da_string += "<tr>" "<td colspan='4'>" "<div class='flex-row'>" "<div class='flex col-6'>"
1a54012017-07-25Pontus Östlund  + "<b>"
468b6c2017-10-04Pontus Östlund  + module_name_from_file(module)+"</b></div>" + "<div class='flex col-6 text-right'>"
1577242000-08-19Per Hedbor  + trim_name(module)
468b6c2017-10-04Pontus Östlund  + "&nbsp;"+RELOAD(module)+"</div>" "</div></td></tr>";
1577242000-08-19Per Hedbor  foreach( res, array e )
a840292017-06-02Pontus Östlund  da_string +=
468b6c2017-10-04Pontus Östlund  "<tr class='valign-top monospace'>" "<td style='width:30px'>&nbsp;</td>" "<td class='text-right'>"+e[1]+":</td>" "<td class='text-right nowrap'>"+ he(e[2])+":</td>" "<td>"+hc(e[3])+"</td></tr>\n";
1577242000-08-19Per Hedbor 
468b6c2017-10-04Pontus Östlund  divider = "<tr><td colspan='4'><hr></td></tr>";
1577242000-08-19Per Hedbor  } } if( strlen( da_string ) ) da_string += "</table>";
a840292017-06-02Pontus Östlund 
e4445e2002-02-26Marcus Wellhardh  return da_string + format_locked_modules(locked_modules); } string format_locked_modules(array(ModuleInfo) locked_modules) { if(!sizeof(locked_modules)) return "";
a840292017-06-02Pontus Östlund 
e4445e2002-02-26Marcus Wellhardh  return
468b6c2017-10-04Pontus Östlund  "<h3>Locked modules</h3>\n"
a840292017-06-02Pontus Östlund  "<p>These modules are locked and can not be enabled because they are " "not part of the license key for this configuration.</p>\n"
468b6c2017-10-04Pontus Östlund  "<div class='notify error no-margin-top'>"+
a840292017-06-02Pontus Östlund  (((array(string))locked_modules->get_name())*"<br />\n")+"</div>";
1577242000-08-19Per Hedbor }
ab9b6d2000-02-11Per Hedbor array(string) get_module_list( function describe_module, function class_visible,
a840292017-06-02Pontus Östlund  RequestID id, void|bool fast)
f26aee2000-01-31Per Hedbor { object conf = roxen.find_configuration( id->variables->config ); object ec = roxenloader.LowErrorContainer();
f150252000-04-04Per Hedbor  int do_reload;
f26aee2000-01-31Per Hedbor  master()->set_inhibit_compile_errors( ec );
f150252000-04-04Per Hedbor  if( id->variables->reload_module_list ) roxen->clear_all_modules_cache();
f599d92000-09-03Per Hedbor  array(ModuleInfo) mods;
f26aee2000-01-31Per Hedbor  roxenloader.push_compile_error_handler( ec ); mods = roxen->all_modules(); roxenloader.pop_compile_error_handler();
a840292017-06-02Pontus Östlund  foreach( mods, ModuleInfo m ) {
60ecb82018-03-12Pontus Östlund  if ((m->type & (MODULE_DEPRECATED | MODULE_DEPRECATED_SOFT)) && !show_deprecated(id)) {
a840292017-06-02Pontus Östlund  mods -= ({ m }); } if( module_nomore( m->sname, m, conf ) ) {
f599d92000-09-03Per Hedbor  mods -= ({ m });
a840292017-06-02Pontus Östlund  } }
ab9b6d2000-02-11Per Hedbor 
f599d92000-09-03Per Hedbor  string res = "";
f26aee2000-01-31Per Hedbor  string doubles="", already="";
ab9b6d2000-02-11Per Hedbor  array w = map(mods, module_class, id);
ad28082000-11-18Martin Nilsson  mapping classes = ([]);
ab9b6d2000-02-11Per Hedbor  sort(w,mods); for(int i=0; i<sizeof(w); i++)
f26aee2000-01-31Per Hedbor  {
ab9b6d2000-02-11Per Hedbor  mixed r = w[i]; if(!classes[r[0]]) classes[r[0]] = ([ "doc":r[1], "modules":({}) ]);
07fe272008-10-01Jonas Wallden  classes[r[0]]->modules += ({ mods[i] });
ab9b6d2000-02-11Per Hedbor  }
f025022005-12-17Jonas Wallden  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 =
a840292017-06-02Pontus Östlund  lower_case(((string) m->get_name() || "") + "\0" + m->sname + "\0" + m->filename + "\0" + Roxen.html_decode_string((string) m->get_description() || LOCALE(1023, "Undocumented")));
f025022005-12-17Jonas Wallden  search_miss: {
a840292017-06-02Pontus Östlund  foreach(mod_query_words, string w) if (!has_value(compare, w)) break search_miss; search_modules[m] = 1;
f025022005-12-17Jonas Wallden  } } }
e4445e2002-02-26Marcus Wellhardh  License.Key license_key = conf->getvar("license")->get_key(); array(RoxenModule) locked_modules = ({});
a840292017-06-02Pontus Östlund 
ab9b6d2000-02-11Per Hedbor  foreach( sort(indices(classes)), string c ) { mixed r;
d39c492000-03-28Per Hedbor  if( c == "" ) continue;
a840292017-06-02Pontus Östlund  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))))
ab9b6d2000-02-11Per Hedbor  { res += r[1];
1577242000-08-19Per Hedbor  array m = classes[c]->modules; array q = m->get_name(); sort( q, m );
8f782d2017-06-07Pontus Östlund  int hits = 0;
1577242000-08-19Per Hedbor  foreach(m, object q)
ab9b6d2000-02-11Per Hedbor  { if( q->get_description() == "Undocumented" && q->type == 0 ) continue;
a840292017-06-02Pontus Östlund  if (search_modules && !search_modules[q]) continue;
ab9b6d2000-02-11Per Hedbor  object b = module_nomore(q->sname, q, conf);
a840292017-06-02Pontus Östlund  if( !b && q->locked && (!license_key || !q->unlocked(license_key, conf)) ) { locked_modules += ({ q }); continue; }
8f782d2017-06-07Pontus Östlund  hits += 1;
ab9b6d2000-02-11Per Hedbor  res += describe_module( q, b ); }
8f782d2017-06-07Pontus Östlund  if (!hits) {
6647b52017-06-09Pontus Östlund  if (class_visible == class_visible_compact) { TRACE("Do nothing\n"); // res = 0; } else { res += "<div class='module no-modules'>" "<span class='notify info inline'>No available modules</span>" "</div>"; }
8f782d2017-06-07Pontus Östlund  }
f025022005-12-17Jonas Wallden  } else { if (!search_modules)
a840292017-06-02Pontus Östlund  res += r[1];
f025022005-12-17Jonas Wallden  }
f26aee2000-01-31Per Hedbor  }
5704c22000-02-02Per Hedbor  master()->set_inhibit_compile_errors( 0 );
e4445e2002-02-26Marcus Wellhardh  return ({ res, pafeaw( ec->get(), ec->get_warnings(), locked_modules) });
f26aee2000-01-31Per Hedbor } string module_image( int type ) { return ""; }
94ebf52001-03-04Per Hedbor  string strip_leading( LocaleString what )
f7bd0d2001-03-03Per Hedbor {
94ebf52001-03-04Per Hedbor  if( !what ) return 0;
8183cc2001-08-09Martin Stjernholm  sscanf( (string)what, "%*s:%*[ \t]%s", what );
f7bd0d2001-03-03Per Hedbor  return what; }
a840292017-06-02Pontus Östlund function describe_module_normal(void|bool faster)
f26aee2000-01-31Per Hedbor {
a840292017-06-02Pontus Östlund  return lambda(object module, object block)
f26aee2000-01-31Per Hedbor  {
a840292017-06-02Pontus Östlund  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='{{ sname }}'> <input type='hidden' name='config' value='&form.config;'> <submit-gbutton type='add'>{{ add_label }}</submit-gbutton> </form> {{ /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,
60ecb82018-03-12Pontus Östlund  "deprecated" : (module->type & (MODULE_DEPRECATED | MODULE_DEPRECATED_SOFT))
a840292017-06-02Pontus Östlund  ]);
bf66c32018-02-28Pontus Östlund  return Roxen.render_mustache(tmpl, ctx);
f26aee2000-01-31Per Hedbor  }
a840292017-06-02Pontus Östlund  return "";
f26aee2000-01-31Per Hedbor  }; }
a840292017-06-02Pontus Östlund array(int|string) class_visible_normal(string c, string d, int size, RequestID id, void|bool fast)
ab9b6d2000-02-11Per Hedbor {
0b04292000-07-23Martin Nilsson  int x;
f025022005-12-17Jonas Wallden  string method = get_method(id);
a840292017-06-02Pontus Östlund  string header; // LOCALE(168, "Hide") // LOCALE(267, "View") array(array(string)) qs = ({ ({ "config", "&form.config;" }), ({ "method", "&form.method;" }) });
0b04292000-07-23Martin Nilsson 
f025022005-12-17Jonas Wallden  if (id->variables->mod_query) { x = 1;
a840292017-06-02Pontus Östlund  } else if( id->variables->unfolded == c) { x = 1; } else { qs += ({ ({ "unfolded", Roxen.http_encode_url(c) }) });
f025022005-12-17Jonas Wallden  }
0b04292000-07-23Martin Nilsson 
a840292017-06-02Pontus Östlund  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);
468b6c2017-10-04Pontus Östlund  if (d && !sizeof(String.trim_all_whites(d))) { d = 0; } if (fast && (x || d)) { content += "<dd>" + (d||"&nbsp;") + "</dd>";
a840292017-06-02Pontus Östlund  } 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);
0b04292000-07-23Martin Nilsson  return ({ x, header });
ab9b6d2000-02-11Per Hedbor }
f025022005-12-17Jonas Wallden 
a840292017-06-02Pontus Östlund string page_normal_low(RequestID id, int|void fast)
f26aee2000-01-31Per Hedbor {
8f782d2017-06-07Pontus Östlund  TRACE("page_normal_low: %O : faster(%O)\n", id, fast);
f26aee2000-01-31Per Hedbor  string desc, err;
a840292017-06-02Pontus Östlund  [desc,err] = get_module_list(describe_module_normal(fast), class_visible_normal, id, fast); string ret = "<div class='add-modules-wrapper'>"; if (fast) {
8f782d2017-06-07Pontus Östlund  ret = "<form method='post' action='add_module.pike'>" "<input type='hidden' name='config' value='&form.config;'>" "<roxen-wizard-id-variable/>" + ret;
a840292017-06-02Pontus Östlund  }
468b6c2017-10-04Pontus Östlund  if (id->variables->mod_query && !sizeof(desc)) { ret += sprintf( "<div class='notify warn'>No modules matching \"%s\" were found</div>", id->variables->mod_query); }
8f782d2017-06-07Pontus Östlund  return ret + desc + "</div>" + (fast ? "</form>" : "") + err;
f025022005-12-17Jonas Wallden }
a840292017-06-02Pontus Östlund string page_normal_search(RequestID id, void|bool fast)
f025022005-12-17Jonas Wallden { return "<use file='/template-insert' />\n" "<tmpl>" +
a840292017-06-02Pontus Östlund  page_normal_low(id, fast) +
f025022005-12-17Jonas Wallden  "</tmpl>"; }
a840292017-06-02Pontus Östlund string page_normal( RequestID id, void|bool fast )
f025022005-12-17Jonas Wallden { string content =
8f782d2017-06-07Pontus Östlund  "<form id='mod_results' method='post' action='add_module.pike' style='display: none'>" "</form>"
f025022005-12-17Jonas Wallden  "<div id='mod_default'>" +
a840292017-06-02Pontus Östlund  page_normal_low(id, fast) +
f025022005-12-17Jonas Wallden  "</div>"; return page_base( id, content, 1, 1);
f26aee2000-01-31Per Hedbor } string page_fast( RequestID id ) {
a840292017-06-02Pontus Östlund  return page_normal(id);
f26aee2000-01-31Per Hedbor }
f025022005-12-17Jonas Wallden string page_faster_search(RequestID id) { return "<use file='/template-insert' />\n" "<tmpl>" +
8f782d2017-06-07Pontus Östlund  page_normal_low(id, true) +
f025022005-12-17Jonas Wallden  "</tmpl>"; } string page_faster( RequestID id ) { string content =
6647b52017-06-09Pontus Östlund  "<form id='mod_results' method='post' action='add_module.pike'" " style='display: none'></form>"
f025022005-12-17Jonas Wallden  "<div id='mod_default'>" +
a840292017-06-02Pontus Östlund  page_normal_low(id, true) +
f025022005-12-17Jonas Wallden  "</div>"; return page_base( id, content, 0, 1);
5876e82000-04-01Martin Bähr }
6647b52017-06-09Pontus Östlund int first, skip_select;
ab9b6d2000-02-11Per Hedbor 
f335752003-09-04Anders Johansson array(int|string) class_visible_compact( string c, string d, int size,
a840292017-06-02Pontus Östlund  RequestID id )
ab9b6d2000-02-11Per Hedbor { string res="";
6647b52017-06-09Pontus Östlund  if (first++ && !skip_select) { res = "</select><br /><submit-gbutton>" + LOCALE(200, "Add Modules")+ "</submit-gbutton><hr class='section'>"; } res += "<h3 id='"+Roxen.html_encode_string(c)+"' class='no-margin-bottom'>"+c+"</h3>" "<p class='no-margin-top'>"+d+"</p>"; if (size) { skip_select = false; res += "<select size='"+size+"' multiple name='module_to_add'" " class='add-module-select'>"; } else { res += "<div class='notify info'>No available modules</div>"; skip_select = true; }
ab9b6d2000-02-11Per Hedbor  return ({ 1, res }); } string describe_module_compact( object module, object block ) {
8183cc2001-08-09Martin Stjernholm  if(!block) {
4ab2c22002-01-28Martin Stjernholm  //string modname = strip_leading (module->get_name()); string modname = module->get_name();
8183cc2001-08-09Martin Stjernholm  return "<option value='"+module->sname+"'>"+
f335752003-09-04Anders Johansson  Roxen.html_encode_string(modname) + "&nbsp;" * max (0, (int) ((49 - sizeof (modname)))) + " (" + Roxen.html_encode_string(module->sname) + ")"+
8183cc2001-08-09Martin Stjernholm  "</option>\n"; }
59d5e62000-02-23Martin Nilsson  return "";
ab9b6d2000-02-11Per Hedbor }
6647b52017-06-09Pontus Östlund // FIXME: Make this work like page_really_compact. The problem with the current // solution with get_module_list() is that the <select>s gets the height // set by how many modules are found, before those are filtered on // wether they are locked/deprecated or not. // // The result of this is that there might be completely empty selects as // well as selects which are taller than what they have rows. // // © 2107, Looks like crap
f26aee2000-01-31Per Hedbor string page_compact( RequestID id ) {
ab9b6d2000-02-11Per Hedbor  first=0; string desc, err; [desc,err] = get_module_list( describe_module_compact, class_visible_compact, id ); return page_base(id,
9e4a012000-04-06Per Hedbor  "<form action='add_module.pike' method='POST'>"
a840292017-06-02Pontus Östlund  "<roxen-wizard-id-variable />"
9e4a012000-04-06Per Hedbor  "<input type='hidden' name='config' value='&form.config;'>"+
f025022005-12-17Jonas Wallden  desc+"</select><br /><submit-gbutton vspace='3'> "
eabb192006-01-25Anders Johansson  +LOCALE(200, "Add Modules")+" </submit-gbutton><p>"
1577242000-08-19Per Hedbor  +err+"</form>",
ab9b6d2000-02-11Per Hedbor  );
f26aee2000-01-31Per Hedbor }
17041f2000-03-01Martin Nilsson string page_really_compact( RequestID id ) { first=0; object conf = roxen.find_configuration( id->variables->config ); object ec = roxenloader.LowErrorContainer(); master()->set_inhibit_compile_errors( ec );
958ad82000-08-15Martin Stjernholm  if( id->variables->reload_module_list )
7efa4d2000-08-20Per Hedbor  { if( id->variables->only ) { master()->clear_compilation_failures(); m_delete( roxen->modules, (((id->variables->only/"/")[-1])/".")[0] ); roxen->all_modules_cache = 0; } else roxen->clear_all_modules_cache(); }
958ad82000-08-15Martin Stjernholm 
17041f2000-03-01Martin Nilsson  array mods; roxenloader.push_compile_error_handler( ec ); mods = roxen->all_modules(); roxenloader.pop_compile_error_handler();
8a4cef2001-04-10Martin Nilsson  sort(map(mods->get_name(), lambda(LocaleString in) {
a840292017-06-02Pontus Östlund  in = lower_case((string)in); //sscanf(in, "%*s: %s", in); return in; }), mods);
17041f2000-03-01Martin Nilsson  string res = ""; mixed r;
e4445e2002-02-26Marcus Wellhardh  License.Key license_key = conf->getvar("license")->get_key(); array(RoxenModule) locked_modules = ({});
6647b52017-06-09Pontus Östlund  array(string) mres = ({}); bool deprecated = show_deprecated(id); mods = filter(mods, lambda (ModuleInfo m) {
60ecb82018-03-12Pontus Östlund  if ((m->type & (MODULE_DEPRECATED | MODULE_DEPRECATED_SOFT)) && !deprecated) {
6647b52017-06-09Pontus Östlund  return 0; } if ((!m->get_description() || (m->get_description() == "Undocumented")) && m->type == 0) { return 0; } object b = module_nomore(m->sname, m, conf); if (!b && m->locked && (!license_key || !m->unlocked(license_key, conf))) { locked_modules += ({ m }); return 0; } mres += ({ describe_module_compact(m, b) }); return 1; }); mres -= ({ "" });
a840292017-06-02Pontus Östlund 
eabb192006-01-25Anders Johansson  if( (r = class_visible_compact( LOCALE(200,"Add Modules"),
a840292017-06-02Pontus Östlund  LOCALE(273,"Select one or several modules to add."),
6647b52017-06-09Pontus Östlund  sizeof(mres), id )) && r[0] ) { res += r[1] + (mres*""); } else {
17041f2000-03-01Martin Nilsson  res += r[1];
f025022005-12-17Jonas Wallden  }
17041f2000-03-01Martin Nilsson  master()->set_inhibit_compile_errors( 0 ); return page_base(id, "<form action=\"add_module.pike\" method=\"post\">"
a840292017-06-02Pontus Östlund  "<roxen-wizard-id-variable />"
17041f2000-03-01Martin Nilsson  "<input type=\"hidden\" name=\"config\" value=\"&form.config;\" />"+
6647b52017-06-09Pontus Östlund  res+"</select><p><submit-gbutton> " +LOCALE(200, "Add Modules")+" </submit-gbutton></p>"
e4445e2002-02-26Marcus Wellhardh  +pafeaw(ec->get(),ec->get_warnings(),
a840292017-06-02Pontus Östlund  locked_modules)+"</form>",
17041f2000-03-01Martin Nilsson  ); }
9ba17a2000-03-24Per Hedbor string decode_site_name( string what ) {
a840292017-06-02Pontus Östlund  if( (int)what )
9ba17a2000-03-24Per Hedbor  return (string)((array(int))(what/","-({""}))); return what; }
f26aee2000-01-31Per Hedbor 
2e07c32000-03-09Martin Stjernholm 
f599d92000-09-03Per Hedbor array initial_form( RequestID id, Configuration conf, array modules ) {
10745b2001-01-29Per Hedbor  id->variables->initial = "1"; id->real_variables->initial = ({ "1" });
f599d92000-09-03Per Hedbor  string res = ""; int num;
10745b2001-01-29Per Hedbor 
6647b52017-06-09Pontus Östlund  string tmpl = #" <div class='initial-module-conf'> <h3>%s</h3> <emit source='module-variables' configuration='%s' module='%s'/> <emit noset='1' source='module-variables' configuration='%[1]s' module='%[2]s'> <dl class='config-var'> <dt class='name small'>&_.name;</dt> <dd class='value'>
fb1f072018-06-28Pontus Östlund  <if variable='_.form is *<select*'> <div class='select-wrapper'> <eval>&_.form:none;</eval> </div> </if> <else> <eval>&_.form:none;</eval> </else>
6647b52017-06-09Pontus Östlund  </dd> <dd class='doc'>&_.doc:none;</dd> </dl> </emit> </div>";
f599d92000-09-03Per Hedbor  foreach( modules, string mod )
1577242000-08-19Per Hedbor  {
f599d92000-09-03Per Hedbor  ModuleInfo mi = roxen.find_module( (mod/"!")[0] ); RoxenModule moo = conf->find_module( replace(mod,"!","#") );
6647b52017-06-09Pontus Östlund 
fb1f072018-06-28Pontus Östlund  foreach( indices(moo && moo->query() || ({})), string v ) {
6647b52017-06-09Pontus Östlund  if( moo->getvar( v )->get_flags() & VAR_INITIAL ) {
f599d92000-09-03Per Hedbor  num++;
6647b52017-06-09Pontus Östlund  res += sprintf(tmpl, LOCALE(1,"Initial variables for ") + Roxen.html_encode_string(mi->get_name()), conf->name, mod);
f599d92000-09-03Per Hedbor  break; }
a38da12000-08-20Per Hedbor  }
c2b2722000-05-22Martin Nilsson  }
f599d92000-09-03Per Hedbor  return ({res,num}); }
f26aee2000-01-31Per Hedbor 
10745b2001-01-29Per Hedbor mapping already_added = ([]);
f599d92000-09-03Per Hedbor mixed do_it_pass_2( array modules, Configuration conf, RequestID id ) {
a840292017-06-02Pontus Östlund  id->misc->do_not_goto = 1; foreach( modules, string mod )
a38da12000-08-20Per Hedbor  {
10745b2001-01-29Per Hedbor  if( already_added[mod] ) mod = already_added[ mod ];
f599d92000-09-03Per Hedbor  if( !has_value(mod, "!") || !conf->find_module( replace(mod,"!","#") ) )
a38da12000-08-20Per Hedbor  {
f599d92000-09-03Per Hedbor  RoxenModule mm = conf->enable_module( mod,0,0,1 );
eac60f2001-01-26Per Hedbor  if( !mm || !conf->otomod[mm] ) {
a840292017-06-02Pontus Östlund  report_error(LOCALE(382,"Failed to enable %s")+"\n"); return Roxen.http_redirect( site_url(id,conf->name), id ); } conf->call_low_start_callbacks( mm, roxen.find_module( (mod/"!")[0] ),
f599d92000-09-03Per Hedbor  conf->modules[ mod ] );
10745b2001-01-29Per Hedbor  modules = replace( modules, mod,
a840292017-06-02Pontus Östlund  (already_added[mod]=(mod/"!")[0]+"!"+ (conf->otomod[mm]/"#")[-1]) );
a38da12000-08-20Per Hedbor  } }
f599d92000-09-03Per Hedbor  [string cf_form, int num] = initial_form( id, conf, modules ); if( !num || id->variables["ok.x"] ) { // set initial variables from form variables... if( num ) Roxen.parse_rxml( cf_form, id ); foreach( modules, string mod )
79538a2002-12-10Martin Stjernholm  conf->call_high_start_callbacks( conf->find_module( replace(mod,"!","#") ),
a840292017-06-02Pontus Östlund  roxen.find_module( (mod/"!")[0] ), 1);
10745b2001-01-29Per Hedbor  already_added = ([ ]);
f599d92000-09-03Per Hedbor  conf->save( ); // save it all in one go
3aa50f2001-12-19Anders Johansson  conf->forcibly_added = ([]);
2df9212001-10-08Per Hedbor  return Roxen.http_redirect( site_url(id,conf->name)+"-!-/"+modules[-1]+"/" , id);
f599d92000-09-03Per Hedbor  }
6647b52017-06-09Pontus Östlund  return page_base(id,
f599d92000-09-03Per Hedbor  map( modules, lambda( string q ) {
6647b52017-06-09Pontus Östlund  return "<input type='hidden'" " name='module_to_add'" " value='"+q+"' />";
a840292017-06-02Pontus Östlund  } )*"\n"
cc75f52000-10-21Martin Nilsson  +"<input type='hidden' name='config' "
6647b52017-06-09Pontus Östlund  "value='"+conf->name+"' />"+cf_form+"<cf-ok />");
f599d92000-09-03Per Hedbor } mixed do_it( RequestID id ) { if( id->variables->encoded ) id->variables->config = decode_site_name( id->variables->config );
a115b82002-03-06Henrik Grubbström (Grubba)  Configuration conf; foreach(id->variables->config/"\0", string config) {
e4345e2006-01-19Jonas Wallden  if (conf = roxen.find_configuration( config )) {
a115b82002-03-06Henrik Grubbström (Grubba)  id->variables->config = config; break; } }
f599d92000-09-03Per Hedbor 
e0e5332002-08-12Henrik Grubbström (Grubba)  if (!conf) {
e165eb2002-08-16Anders Johansson  return sprintf(LOCALE(356, "Configuration %O not found."),
a840292017-06-02Pontus Östlund  id->variables->config);
e0e5332002-08-12Henrik Grubbström (Grubba)  }
f599d92000-09-03Per Hedbor  if( !conf->inited ) conf->enable_all_modules();
10745b2001-01-29Per Hedbor 
f599d92000-09-03Per Hedbor  array modules = (id->variables->module_to_add/"\0")-({""}); if( !sizeof( modules ) ) return Roxen.http_redirect( site_url(id,conf->name ), id ); return do_it_pass_2( modules, conf, id );
f26aee2000-01-31Per Hedbor } mixed parse( RequestID id ) { if( !config_perm( "Add Module" ) )
e3aab72000-07-25Andreas Lange  return LOCALE(226, "Permission denied");
f26aee2000-01-31Per Hedbor 
a0dc3f2016-02-12Henrik Grubbström (Grubba)  if (!id->variables->config) { return Roxen.http_redirect("/sites/", id); }
8f782d2017-06-07Pontus Östlund  if( id->variables->module_to_add && !id->variables->reload) {
f26aee2000-01-31Per Hedbor  return do_it( id );
8f782d2017-06-07Pontus Östlund  }
f26aee2000-01-31Per Hedbor 
a115b82002-03-06Henrik Grubbström (Grubba)  Configuration conf; foreach(id->variables->config/"\0", string config) {
f025022005-12-17Jonas Wallden  if (conf = roxen.find_configuration(config)) {
a115b82002-03-06Henrik Grubbström (Grubba)  id->variables->config = config; break; } }
62e1bb2000-11-08Per Hedbor  if( !config_perm( "Site:"+conf->name ) ) return LOCALE(226,"Permission denied");
f150252000-04-04Per Hedbor  if( !conf->inited ) conf->enable_all_modules();
f025022005-12-17Jonas Wallden  string method = get_method(id); if (id->variables->mod_query) {
57e6f02006-02-07Jonas Wallden  // 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");
a840292017-06-02Pontus Östlund 
f025022005-12-17Jonas Wallden  // This can be invoked from both Normal and Faster methods return (method == "faster" ?
a840292017-06-02Pontus Östlund  page_faster_search(id) : page_normal_search(id));
f025022005-12-17Jonas Wallden  }
a840292017-06-02Pontus Östlund 
d6b1b52005-12-17Jonas Wallden  return this_object()["page_" + method]( id );
f26aee2000-01-31Per Hedbor }