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>
10745b2001-01-29Per Hedbor int no_reload() { if( sizeof( already_added ) ) return 1; // Reloading this script now would destroy state. }
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"), ]) ]); return Mustache()->render(tmpl, ctx); }
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 }) }); } } string da_string = ""; int header_added; foreach( sort((array)by_module), [string module, array errors] ) { 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")) if( !header_added++ )
a840292017-06-02Pontus Östlund  da_string +=
80cd682003-11-17Anders Johansson  "<p><a name='errors_and_warnings'></a><br />"
cc75f52000-10-21Martin Nilsson  "<font size='+2'><b><font color='&usr.warncolor;'>"
1577242000-08-19Per Hedbor  "Compile errors and warnings</font></b><br />" "<table width=100% cellpadding='3' cellspacing='0' border='0'>"; da_string += "<tr><td></td>"
cc75f52000-10-21Martin Nilsson  "<td colspan='3' bgcolor='&usr.content-titlebg;'>"
1577242000-08-19Per Hedbor  + "<b><font color='&usr.content-titlefg;' size='+1'>" + module_name_from_file(module)+"</font></b></td>" + "<td align='right' bgcolor='&usr.content-titlebg;'>" "<font color='&usr.content-titlefg;' size='+1'>" + trim_name(module) + "</font>&nbsp;"+RELOAD(module)+"</td><td></td></tr>"; foreach( res, array e )
a840292017-06-02Pontus Östlund  da_string +=
99710c2000-12-18Martin Nilsson  "<tr valign='top'><td></td><td><img src='/internal-roxen-unit' width='30' height='1' alt='' />"
cc75f52000-10-21Martin Nilsson  "</td><td align='right'>" "<tt>"+e[1]+":</tt></td><td align='right'><tt>"+
1577242000-08-19Per Hedbor  he(e[2])+":</tt></td><td><tt>"+hc(e[3])+"</tt></td></tr>\n";
cc75f52000-10-21Martin Nilsson  da_string += "<tr valign='top'><td colspan='5'>&nbsp;</td><td></td></tr>\n";
1577242000-08-19Per Hedbor  } } if( strlen( da_string ) ) da_string += "</table>"; // "<pre>"+Roxen.html_encode_string( sprintf( "%O", by_module ) )+"</pre>";
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
a840292017-06-02Pontus Östlund  "<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>";
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 ) { if (m->deprecated && !show_deprecated(id)) { TRACE("::: DEPRECATED ModuleInfo: %O\n", m); 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 ); 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; }
ab9b6d2000-02-11Per Hedbor  res += describe_module( q, b ); }
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, "deprecated" : module->deprecated ]); return Mustache()->render(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); 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);
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 { 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) { ret += "<input type='hidden' name='config' value='&form.config;'>"; } return ret + desc + "</div>" + 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 = "<div id='mod_results' style='display: none'>" "</div>" "<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 }
5876e82000-04-01Martin Bähr string describe_module_faster( object module, object block) { if(!block) { return sprintf(
4ab2c22002-01-28Martin Stjernholm  #"
8183cc2001-08-09Martin Stjernholm  <tr><td colspan='2'><table width='100%%'>
a840292017-06-02Pontus Östlund  <td>#FASTER#<font size='+2'>%s</font></td>
f025022005-12-17Jonas Wallden  <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'>
5876e82000-04-01Martin Bähr  <option value='%s'>%s</option></select>
f025022005-12-17Jonas Wallden  </td><td valign='top'>%s<p class='dimtext'>%s</p></td>
5876e82000-04-01Martin Bähr  </tr> ",
4ab2c22002-01-28Martin Stjernholm  //Roxen.html_encode_string(strip_leading(module->get_name())), Roxen.html_encode_string(module->get_name()),
8183cc2001-08-09Martin Stjernholm  Roxen.html_encode_string (module->sname),
5876e82000-04-01Martin Bähr  module_image(module->type), module->sname,
4ab2c22002-01-28Martin Stjernholm  //Roxen.html_encode_string(strip_leading(module->get_name())), Roxen.html_encode_string(module->get_name()),
82c0202009-03-17Jonas Wallden  module->get_description() || LOCALE(1023, "Undocumented"),
e3aab72000-07-25Andreas Lange  LOCALE(266, "Will be loaded from: ")+module->filename
5876e82000-04-01Martin Bähr  ); } else { if( block == module ) return ""; return ""; } }
f335752003-09-04Anders Johansson array(int|string) class_visible_faster( string c, string d, int size,
a840292017-06-02Pontus Östlund  RequestID id )
5876e82000-04-01Martin Bähr {
0b04292000-07-23Martin Nilsson  int x;
f025022005-12-17Jonas Wallden  string method = get_method(id);
9e4a012000-04-06Per Hedbor  string header = ("<tr><td colspan='2'><table width='100%' cellspacing='0' " "border='0' cellpadding='3' bgcolor='&usr.content-titlebg;'>"
f025022005-12-17Jonas Wallden  "<tr><td nowrap='nowrap' valign='top'>"); if (id->variables->mod_query) {
3ffadc2005-12-19Jonas Wallden  header+=("<gbutton hspace='5' vspace='5' dim='1'> "+LOCALE(267, "View")+
a840292017-06-02Pontus Östlund  " </gbutton><br>" "<submit-gbutton hspace='5' vspace='2'> "+LOCALE(200, "Add Modules")+ " </submit-gbutton>");
f025022005-12-17Jonas Wallden  x = 1; } else if( id->variables->unfolded == c ) {
f491312004-10-11Martin Stjernholm  header+=("<a name='"+Roxen.html_encode_string(c)+
a840292017-06-02Pontus Östlund  "'></a><gbutton hspace='5' vspace='5' dim='1'> "+LOCALE(267, "View")+ " </gbutton><br>" "<submit-gbutton hspace='5' vspace='2'> "+LOCALE(200, "Add Modules")+ " </submit-gbutton>");
0b04292000-07-23Martin Nilsson  x=1; } else
f491312004-10-11Martin Stjernholm  header+=("<a name='"+Roxen.html_encode_string(c)+
a840292017-06-02Pontus Östlund  "'></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>");
0b04292000-07-23Martin Nilsson  header+=("</td><td width='100%'>"
a840292017-06-02Pontus Östlund  "<font color='&usr.content-titlefg;' size='+2'>"+c+"</font>" "<br />"+d+"</td></tr></table></td></tr>\n");
0b04292000-07-23Martin Nilsson  return ({ x, header });
5876e82000-04-01Martin Bähr }
f025022005-12-17Jonas Wallden string page_faster_low(RequestID id)
5876e82000-04-01Martin Bähr { string desc, err; [desc,err] = get_module_list( describe_module_faster, class_visible_faster, id );
f025022005-12-17Jonas Wallden  return "<form method='post' action='add_module.pike'>" "<input type='hidden' name='config' value='&form.config;'>"
e1fff72016-01-15Henrik Grubbström (Grubba)  "<roxen-wizard-id-variable />"
f025022005-12-17Jonas Wallden  "<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'>" +
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 }
ab9b6d2000-02-11Per Hedbor int first;
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=""; if(first++)
f025022005-12-17Jonas Wallden  res = "</select><br /><submit-gbutton vspace='3'> "+
eabb192006-01-25Anders Johansson  LOCALE(200, "Add Modules")+ " </submit-gbutton> ";
f491312004-10-11Martin Stjernholm  res += "<p><a name='"+Roxen.html_encode_string(c)+ "'></a><font size='+2'>"+c+"</font><br />"+d+"<p>"
80cd682003-11-17Anders Johansson  "<select size='"+size+"' multiple name='module_to_add' class='add-module-select'>";
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 }
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 = ({});
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."), sizeof(mods), id )) && r[0] ) {
17041f2000-03-01Martin Nilsson  res += r[1]; foreach(mods, object q) {
4d32e52001-07-31Per Hedbor  if( (!q->get_description() ||
a840292017-06-02Pontus Östlund  (q->get_description() == "Undocumented")) && q->type == 0 ) continue;
17041f2000-03-01Martin Nilsson  object b = module_nomore(q->sname, q, conf);
9af9a52008-04-08Henrik Grubbström (Grubba)  if( !b && q->locked &&
a840292017-06-02Pontus Östlund  (!license_key || !q->unlocked(license_key, conf)) )
e4445e2002-02-26Marcus Wellhardh  {
a840292017-06-02Pontus Östlund  locked_modules += ({ q }); continue;
e4445e2002-02-26Marcus Wellhardh  }
17041f2000-03-01Martin Nilsson  res += describe_module_compact( q, b ); }
f025022005-12-17Jonas Wallden  } 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;\" />"+
ad28082000-11-18Martin Nilsson  res+"</select><br /><submit-gbutton> "
eabb192006-01-25Anders Johansson  +LOCALE(200, "Add Modules")+" </submit-gbutton><br />"
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 
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,"!","#") ); foreach( indices(moo->query()), string v )
1577242000-08-19Per Hedbor  {
f599d92000-09-03Per Hedbor  if( moo->getvar( v )->get_flags() & VAR_INITIAL ) { num++; res += "<tr><td colspan='3'><h2>"
c183182000-09-09Andreas Lange  +LOCALE(1,"Initial variables for ")+
a840292017-06-02Pontus Östlund  //Roxen.html_encode_string(strip_leading(mi->get_name())) Roxen.html_encode_string(mi->get_name()) +"</h2></td></tr>"
d672ca2001-01-29Per Hedbor  "<emit source='module-variables' "
a840292017-06-02Pontus Östlund  " configuration=\""+conf->name+"\""
d672ca2001-01-29Per Hedbor  " module=\""+mod+#"\"/> <emit noset='1' source='module-variables' "
a840292017-06-02Pontus Östlund  " configuration=\""+conf->name+"\""
f599d92000-09-03Per Hedbor  " module=\""+mod+#"\">
d672ca2001-01-29Per Hedbor  <tr> <td width='150' valign='top' colspan='2'><b>&_.name;</b></td> <td valign='top'><eval>&_.form:none;</eval></td></tr> <tr> <td width='30'><img src='/internal-roxen-unit' width=50 height=1 alt='' /></td> <td colspan=2>&_.doc:none;</td></tr>
06fbff2002-09-26Anders Johansson  <tr><td colspan='3'><img src='/internal-roxen-unit' height='18' /></td></tr>
f599d92000-09-03Per Hedbor </emit>"; 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  } return page_base(id,"<table>"+ map( modules, lambda( string q ) {
cc75f52000-10-21Martin Nilsson  return "<input type='hidden' "
f599d92000-09-03Per Hedbor  "name='module_to_add' " "value='"+q+"' />";
a840292017-06-02Pontus Östlund  } )*"\n"
cc75f52000-10-21Martin Nilsson  +"<input type='hidden' name='config' "
a840292017-06-02Pontus Östlund  "value='"+conf->name+"' />"+cf_form+"</table><p><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); } if( id->variables->module_to_add )
f26aee2000-01-31Per Hedbor  return do_it( id );
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 }