Roxen.git / server / modules / tags / configtablist.pike

version» Context lines:

Roxen.git/server/modules/tags/configtablist.pike:1:   /* -  * $Id: configtablist.pike,v 1.9 1998/03/14 20:57:30 js Exp $ +  * $Id: configtablist.pike,v 1.10 1998/03/19 15:33:11 js Exp $    *    * Makes a tab-list like the one in the config-interface.    *    * $Author: js $    */    - constant cvs_version="$Id: configtablist.pike,v 1.9 1998/03/14 20:57:30 js Exp $"; + constant cvs_version="$Id: configtablist.pike,v 1.10 1998/03/19 15:33:11 js Exp $";   constant thread_safe=1;    -  + #define use_contents_cache 0 + #define use_gif_cache 1   #include <module.h>   inherit "module";   inherit "roxenlib";    -  + #if use_contents_cache + mapping(string:string) contents_cache = ([]); + #endif +  + #if use_gif_cache + mapping(string:string) gif_cache = ([]); + #endif +    /*    * Functions    */      array register_module()   {    return(({ MODULE_PARSER|MODULE_LOCATION, "Config tab-list",    "Adds some tags for making a config-interface "    "look-alike tab-list.<br>\n"    "Usage:<br>\n"
Roxen.git/server/modules/tags/configtablist.pike:73:    if (a->border) {    img_attrs->border = a->border;    m_delete(a, "border");    } else {    img_attrs->border="0";    }    return make_container("a", a, make_container("b", ([]),    make_tag("img", img_attrs)));   }    + int my_hash(mixed o) + { +  switch(sprintf("%t",o)) +  { +  case "string": return hash(o); +  case "int": return o; +  case "mapping": +  int h = 17 + sizeof(o); +  foreach(indices(o), mixed index) +  h += hash(index) * my_hash(o[index]); +  return h; +  +  case "array": +  return hash(sprintf("%O",o)); +  default: +  return hash(encode_value(o)); +  } + } +    string tag_config_tablist(string t, mapping a, string contents)   { -  return(replace(parse_html(contents, ([]), (["tab":tag_config_tab])), -  ({ "\n", "\r" }), ({ "", "" }))); + #if use_contents_cache +  object md5 = Crypto.md5(); +  md5->update(contents+my_hash(a)); +  string key=md5->digest(); +  if(contents_cache[key]) +  return contents_cache[key]; + #endif +  string res=replace(parse_html(contents, ([]), (["tab":tag_config_tab])), +  ({ "\n", "\r" }), ({ "", "" })); + #if use_contents_cache +  contents_cache[key]=res; + #endif +  return res;   }      mapping query_container_callers()   {    return ([ "config_tablist":tag_config_tablist ]);   }      #if constant(thread_create)   object interface_lock = Thread.Mutex();   #endif /* constant(thread_create) */
Roxen.git/server/modules/tags/configtablist.pike:102: Inside #if constant(thread_create)
   //    // load_interface() shouldn't be called recursively,    // so don't protect against it.    mixed key = interface_lock->lock();   #endif /* constant(thread_create) */    return(roxen->configuration_interface());   }      mapping find_file(string f, object id)   { +  string s; + #if use_gif_cache +  if(s=gif_cache[f]) +  { +  werror("Configtablist: "+f+" found in cache.\n"); +  return http_string_answer(s,"image/gif"); +  } + #endif +     array pagecolor; //=({ 122, 122, 122 }); //parse_color("lightblue");    array(string) arr = f/"/";    if (sizeof(arr) > 1) {    object interface = load_interface();    object(Image.image) button;       if (arr[-1][sizeof(arr[-1])-4..] == ".gif") {    arr[-1] = arr[-1][..sizeof(arr[-1])-5];    }   
Roxen.git/server/modules/tags/configtablist.pike:128:    pagecolor);    break;    case "u": /* Unselected */    button = interface->draw_unselected_button(arr[2..]*"/",    interface->button_font,    pagecolor);    break;    default:    return 0;    } -  return http_string_answer(Image.GIF.encode(button,@pagecolor), -  "image/gif"); +  +  s=Image.GIF.encode(button,@pagecolor); + #if use_gif_cache +  if(!gif_cache[f]) +  gif_cache[f]=s; + #endif +  return http_string_answer(s,"image/gif");    }    return 0;   }