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> #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; } 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'>"
e1fff72016-01-15Henrik Grubbström (Grubba)  "<roxen-wizard-id-variable />"
f025022005-12-17Jonas Wallden  "<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>";
719f172011-10-27Jonas Wallden  return sprintf( "<use file='/template' />"
a115b82002-03-06Henrik Grubbström (Grubba)  "<tmpl title=' %s'%s>"
719f172011-10-27Jonas Wallden  "<topmenu base='/' selected='sites'/>"
ab9b6d2000-02-11Per Hedbor  "<content><cv-split>"
9e4a012000-04-06Per Hedbor  "<subtablist width='100%%'>"
f26aee2000-01-31Per Hedbor  "<st-tabs></st-tabs>" "<st-page>"
5ac3b72008-06-12 Erik Dahl  "<h2>Site: '&form.config;'</h2>"
cc75f52000-10-21Martin Nilsson  "<if not='1' variable='form.initial'>"
f025022005-12-17Jonas Wallden  "<table width='100%%' border='0' cellspacing='4' " " cellpadding='0'>" "<tr><td nowrap='nowrap'>%s:</td><td>"
d6b1b52005-12-17Jonas Wallden  "<form action='' style='margin: 0'>" "<input type='hidden' name='config' value='&form.config;'>"
e1fff72016-01-15Henrik Grubbström (Grubba)  "<roxen-wizard-id-variable />"
d6b1b52005-12-17Jonas Wallden  "<default variable='form.method' value='%s'>" "<select name='method' onchange='submit()'>" "<option value='normal'>%s</option>"
f025022005-12-17Jonas Wallden  // "<option value='fast'>%s</option>"
d6b1b52005-12-17Jonas Wallden  "<option value='faster'>%s</option>" "<option value='compact'>%s</option>" "<option value='really_compact'>%s</option>" "</select>" "</default>" "</form>"
f025022005-12-17Jonas Wallden  "</td>" "<td>&nbsp;&nbsp;</td>" "<td width='100%%' nowrap='nowrap'>%s</td>" // search form "<td>&nbsp;&nbsp;</td>" "<td align='right'>"
b411b32000-08-25Andreas Lange  "<gbutton href='add_module.pike?config=&form.config:http;"
e1fff72016-01-15Henrik Grubbström (Grubba)  "&amp;reload_module_list=yes&amp;method=%s&amp;&usr.set-wiz-id;' "
d6b1b52005-12-17Jonas Wallden  "> %s </gbutton>" "</td><td>"
80cd682003-11-17Anders Johansson  "<gbutton href='site.html/&form.config;/' " "> %s </gbutton>"
d6b1b52005-12-17Jonas Wallden  "</td></tr></table>"
f599d92000-09-03Per Hedbor  "<p>\n</if>%s\n</p>\n"
f26aee2000-01-31Per Hedbor  "</st-page></subtablist></td></tr></table>"
e3aab72000-07-25Andreas Lange  "</cv-split></content></tmpl>",
eabb192006-01-25Anders Johansson  LOCALE(251,"Add Module"),
a115b82002-03-06Henrik Grubbström (Grubba)  noform?" noform='noform'":"",
eabb192006-01-25Anders Johansson  LOCALE(421, "List Type"),
d6b1b52005-12-17Jonas Wallden  method,
eabb192006-01-25Anders Johansson  LOCALE(280, "Normal"),
f025022005-12-17Jonas Wallden  // LOCALE(0, "Fast"),
eabb192006-01-25Anders Johansson  LOCALE(284, "Faster"), LOCALE(286, "Compact"), LOCALE(531, "Really Compact"),
f025022005-12-17Jonas Wallden  (show_search_form && search_form) || "",
d6b1b52005-12-17Jonas Wallden  method,
f025022005-12-17Jonas Wallden  LOCALE(272,"Reload Module List"),
d6b1b52005-12-17Jonas Wallden  LOCALE(202,"Cancel"),
f025022005-12-17Jonas Wallden  content);
f26aee2000-01-31Per Hedbor }
1577242000-08-19Per Hedbor  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 ) )
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 ) { 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" )
ab05fb2000-08-23Per Hedbor  return "<font color='&usr.warncolor;'>"+what+"</font>";
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..]*"/"; };
80cd682003-11-17Anders Johansson #define RELOAD(X) sprintf("<gbutton " \ "img-align='middle' " \ "href='add_module.pike?config=&form.config:http;" \
e1fff72016-01-15Henrik Grubbström (Grubba)  "&amp;method=&form.method;" \ "&amp;random=%d&amp;only=%s" \ "&amp;reload_module_list=yes" \ "&amp;&usr.set-wiz-id;" \
d6b1b52005-12-17Jonas Wallden  "#errors_and_warnings'> %s </gbutton>", \
80cd682003-11-17Anders Johansson  random(4711111), \ (X), \
1577242000-08-19Per Hedbor  LOCALE(253, "Reload")) if( !header_added++ ) 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 ) 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>";
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 ""; 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'>"+
6e42292002-02-26Marcus Wellhardh  (((array(string))locked_modules->get_name())*"<br />\n")+"</font></blockquote>";
1577242000-08-19Per Hedbor }
ab9b6d2000-02-11Per Hedbor array(string) get_module_list( function describe_module, function class_visible, RequestID id )
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();
f599d92000-09-03Per Hedbor  foreach( mods, ModuleInfo m ) if( module_nomore( m->sname, m, conf ) ) mods -= ({ m });
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 = lower_case(((string) m->get_name() || "") + "\0" + m->sname + "\0" + m->filename + "\0" +
07fe272008-10-01Jonas Wallden  Roxen.html_decode_string((string) m->get_description() ||
82c0202009-03-17Jonas Wallden  LOCALE(1023, "Undocumented")));
f025022005-12-17Jonas Wallden  search_miss: { foreach(mod_query_words, string w) if (!has_value(compare, w)) break search_miss; search_modules[m] = 1; } } }
e4445e2002-02-26Marcus Wellhardh  License.Key license_key = conf->getvar("license")->get_key(); array(RoxenModule) locked_modules = ({});
ab9b6d2000-02-11Per Hedbor  foreach( sort(indices(classes)), string c ) { mixed r;
d39c492000-03-28Per Hedbor  if( c == "" ) continue;
f335752003-09-04Anders Johansson  if( (r = class_visible( c, classes[c]->doc, sizeof(classes[c]->modules), id )) &&
f025022005-12-17Jonas Wallden  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;
f025022005-12-17Jonas Wallden  if (search_modules && !search_modules[q]) continue;
ab9b6d2000-02-11Per Hedbor  object b = module_nomore(q->sname, q, conf);
9af9a52008-04-08Henrik Grubbström (Grubba)  if( !b && q->locked && (!license_key || !q->unlocked(license_key, conf)) )
e4445e2002-02-26Marcus Wellhardh  { locked_modules += ({ q }); continue; }
ab9b6d2000-02-11Per Hedbor  res += describe_module( q, b ); }
f025022005-12-17Jonas Wallden  } else { if (!search_modules) res += r[1]; }
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; }
f26aee2000-01-31Per Hedbor  function describe_module_normal( int image ) { return lambda( object module, object block) { if(!block) {
4ab2c22002-01-28Martin Stjernholm  return sprintf( #"
9e4a012000-04-06Per Hedbor  <tr> <td colspan='2'> <table width='100%%'> <tr> <td><font size='+2'>%s</font></td>
f025022005-12-17Jonas Wallden  <td align='right'><span class='dimtext'>(%s)</span> %s</td>
9e4a012000-04-06Per Hedbor  </tr> </table> </td> </tr> <tr> <td valign='top'>
f025022005-12-17Jonas Wallden  <form method='post' action='add_module.pike' style='margin: 0 10px 0 0'>
a115b82002-03-06Henrik Grubbström (Grubba)  <roxen-automatic-charset-variable/>
e1fff72016-01-15Henrik Grubbström (Grubba)  <roxen-wizard-id-variable />
9e4a012000-04-06Per Hedbor  <input type='hidden' name='module_to_add' value='%s'> <input type='hidden' name='config' value='&form.config;'>
cc75f52000-10-21Martin Nilsson  <submit-gbutton preparse='1'>%s</submit-gbutton>
9e4a012000-04-06Per Hedbor  </form> </td>
cc75f52000-10-21Martin Nilsson  <td valign='top'>
f025022005-12-17Jonas Wallden  %s <p class='dimtext'>%s</p>
9e4a012000-04-06Per Hedbor  </td> </tr>
f26aee2000-01-31Per Hedbor ",
4ab2c22002-01-28Martin Stjernholm  //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):""),
07fe272008-10-01Jonas Wallden  module->sname, LOCALE(251, "Add Module"),
82c0202009-03-17Jonas Wallden  module->get_description() || LOCALE(1023, "Undocumented"),
07fe272008-10-01Jonas Wallden  LOCALE(266, "Will be loaded from: ")+module->filename
f26aee2000-01-31Per Hedbor ); } else { if( block == module ) return "";
ab9b6d2000-02-11Per Hedbor  return "";
f26aee2000-01-31Per Hedbor  } }; }
f335752003-09-04Anders Johansson array(int|string) class_visible_normal( string c, string d, int size, RequestID id )
ab9b6d2000-02-11Per Hedbor {
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' "
f025022005-12-17Jonas Wallden  "bgcolor='&usr.content-titlebg;'><tr><td valign='top'>");
0b04292000-07-23Martin Nilsson 
f025022005-12-17Jonas Wallden  if (id->variables->mod_query) { x = 1; } else if( id->variables->unfolded == c) {
f491312004-10-11Martin Stjernholm  header+=("<a name='"+Roxen.html_encode_string(c)+
3ffadc2005-12-19Jonas Wallden  "'></a><gbutton hspace='5' vspace='5' "
10745b2001-01-29Per Hedbor  "href='add_module.pike?config=&form.config;"
e1fff72016-01-15Henrik Grubbström (Grubba)  "&amp;method=" + method + "&amp;&usr.set-wiz-id;#"+ Roxen.http_encode_url(c)+"' > "+
6150972001-01-29Per Hedbor  LOCALE(168, "Hide")+" </gbutton>");
0b04292000-07-23Martin Nilsson  x=1;
f025022005-12-17Jonas Wallden  } else {
f491312004-10-11Martin Stjernholm  header+=("<a name='"+Roxen.html_encode_string(c)+
3ffadc2005-12-19Jonas Wallden  "'></a><gbutton hspace='5' vspace='5' "
0b04292000-07-23Martin Nilsson  "href='add_module.pike?config=&form.config;"
e1fff72016-01-15Henrik Grubbström (Grubba)  "&amp;method=" + method + "&amp;unfolded="+Roxen.http_encode_url(c)+ "&amp;&usr.set-wiz-id;#"+Roxen.http_encode_url(c)+"' > "+
e3aab72000-07-25Andreas Lange  LOCALE(267, "View")+" </gbutton>");
f025022005-12-17Jonas Wallden  }
0b04292000-07-23Martin Nilsson  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 });
ab9b6d2000-02-11Per Hedbor }
f025022005-12-17Jonas Wallden  string page_normal_low(RequestID id, int|void noimage)
f26aee2000-01-31Per Hedbor { string desc, err;
ab9b6d2000-02-11Per Hedbor  [desc,err] = get_module_list( describe_module_normal(!noimage), class_visible_normal, id );
f025022005-12-17Jonas Wallden  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);
f26aee2000-01-31Per Hedbor } string page_fast( RequestID id ) { return page_normal( id, 1 ); }
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%%'> <td><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, 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")+
f025022005-12-17Jonas Wallden  " </gbutton><br>"
eabb192006-01-25Anders Johansson  "<submit-gbutton hspace='5' vspace='2'> "+LOCALE(200, "Add Modules")+
f025022005-12-17Jonas Wallden  " </submit-gbutton>"); x = 1; } else if( id->variables->unfolded == c ) {
f491312004-10-11Martin Stjernholm  header+=("<a name='"+Roxen.html_encode_string(c)+
3ffadc2005-12-19Jonas Wallden  "'></a><gbutton hspace='5' vspace='5' dim='1'> "+LOCALE(267, "View")+
f025022005-12-17Jonas Wallden  " </gbutton><br>"
eabb192006-01-25Anders Johansson  "<submit-gbutton hspace='5' vspace='2'> "+LOCALE(200, "Add Modules")+
f025022005-12-17Jonas Wallden  " </submit-gbutton>");
0b04292000-07-23Martin Nilsson  x=1; } else
f491312004-10-11Martin Stjernholm  header+=("<a name='"+Roxen.html_encode_string(c)+
3ffadc2005-12-19Jonas Wallden  "'></a><gbutton hspace='5' vspace='5' "
0b04292000-07-23Martin Nilsson  "href='add_module.pike?config=&form.config;"
e1fff72016-01-15Henrik Grubbström (Grubba)  "&amp;method=" + method + "&amp;unfolded="+Roxen.http_encode_url(c)+ "&amp;&usr.set-wiz-id;#"+Roxen.http_encode_url(c)+"' > "+
e3aab72000-07-25Andreas Lange  LOCALE(267, "View")+" </gbutton>");
0b04292000-07-23Martin Nilsson  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 });
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'>" + page_faster_low(id) + "</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, 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'>"
e1fff72016-01-15Henrik Grubbström (Grubba)  "<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) { in = lower_case((string)in);
4ab2c22002-01-28Martin Stjernholm  //sscanf(in, "%*s: %s", in);
8a4cef2001-04-10Martin Nilsson  return in;
979e802000-11-26Martin Nilsson  }), 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 = ({});
eabb192006-01-25Anders Johansson  if( (r = class_visible_compact( LOCALE(200,"Add Modules"),
f335752003-09-04Anders Johansson  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() || (q->get_description() == "Undocumented")) &&
17041f2000-03-01Martin Nilsson  q->type == 0 ) continue; object b = module_nomore(q->sname, q, conf);
9af9a52008-04-08Henrik Grubbström (Grubba)  if( !b && q->locked && (!license_key || !q->unlocked(license_key, conf)) )
e4445e2002-02-26Marcus Wellhardh  { locked_modules += ({ q }); continue; }
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\">"
e1fff72016-01-15Henrik Grubbström (Grubba)  "<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(), locked_modules)+"</form>",
17041f2000-03-01Martin Nilsson  ); }
9ba17a2000-03-24Per Hedbor string decode_site_name( string what ) { if( (int)what ) 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 ")+
4ab2c22002-01-28Martin Stjernholm  //Roxen.html_encode_string(strip_leading(mi->get_name())) Roxen.html_encode_string(mi->get_name())
f7bd0d2001-03-03Per Hedbor  +"</h2></td></tr>"
d672ca2001-01-29Per Hedbor  "<emit source='module-variables' " " configuration=\""+conf->name+"\"" " module=\""+mod+#"\"/> <emit noset='1' source='module-variables' " " 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 ) { 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] ) {
c96d642001-03-05Martin Nilsson  report_error(LOCALE(382,"Failed to enable %s")+"\n");
eac60f2001-01-26Per Hedbor  return Roxen.http_redirect( site_url(id,conf->name), id ); }
f599d92000-09-03Per Hedbor  conf->call_low_start_callbacks( mm, roxen.find_module( (mod/"!")[0] ), conf->modules[ mod ] );
10745b2001-01-29Per Hedbor  modules = replace( modules, mod, (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,"!","#") ),
0a1a762006-05-31Martin Stjernholm  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+"' />"; } )*"\n"
cc75f52000-10-21Martin Nilsson  +"<input type='hidden' name='config' "
10745b2001-01-29Per Hedbor  "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."),
e0e5332002-08-12Henrik Grubbström (Grubba)  id->variables->config); }
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");
f025022005-12-17Jonas Wallden  // This can be invoked from both Normal and Faster methods return (method == "faster" ? page_faster_search(id) : page_normal_search(id, 1)); }
d6b1b52005-12-17Jonas Wallden  return this_object()["page_" + method]( id );
f26aee2000-01-31Per Hedbor }