1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
// The outlined box module 
// 
// Fredrik Noring et al 
// 
// Several modifications by Francesco Chemolli. 
 
 
constant cvs_version = "$Id: obox.pike,v 1.11 1999/05/08 06:23:26 neotron Exp $"; 
constant thread_safe=1; 
 
#include <module.h> 
inherit "module"; 
inherit "roxenlib"; 
 
constant unit_gif = "/internal-roxen-unit"; 
 
static private int loaded; 
 
static private string doc() 
{ 
  return !loaded?"":replace(Stdio.read_bytes("modules/tags/doc/obox")||"", 
                            ({ "{", "}" }), ({ "&lt;", "&gt;" })); 
} 
 
static string img_placeholder (mapping args) 
{ 
  int width=((int)args->outlinewidth)||1; 
 
  return sprintf("<img src=\"%s\" alt=\"\" width=%d height=%d>", 
                 unit_gif, width, width); 
} 
 
static string handle_title(string name, mapping junk_args, 
                           string contents, mapping args) 
{ 
  args->title=contents; 
  return ""; 
} 
 
static string horiz_line(mapping args) 
{ 
  args->fixedleft=""; 
  return sprintf("<tr><td colspan=5 bgcolor=\"%s\">\n" 
                 "%s</td></tr>\n", 
                 args->outlinecolor, 
                 img_placeholder(args)); 
} 
 
static string title(mapping args) 
{ 
  if (!args->title) 
    return horiz_line(args); 
  string empty=img_placeholder(args); 
  switch (args->style) { 
  case "groupbox": 
    if (!args->left && !args->fixedleft) 
      if (args->width && !args->fixedright) 
        args->fixedleft = "7"; 
      else 
        args->left = "1"; 
    if (!args->right && !args->fixedright) 
      args->right = "1"; 
    return sprintf("<tr><td colspan=2><font size=-3>&nbsp;</font></td>\n" 
                   "<td rowspan=3%s>&nbsp;<b>"              /* bgcolor */ 
                   "%s%s%s"                 /* titlecolor, title, titlecolor */ 
                   "</b>&nbsp;</td>\n" 
                   "<td colspan=2><font size=-3>&nbsp;</font></td></tr>\n" 
                   "<tr%s>"                         /* bgcolor */ 
                   "<td bgcolor=\"%s\" colspan=2>\n"        /* outlinecolor */ 
                   "%s</td>\n"                              /* empty */ 
                   "<td bgcolor=\"%s\" colspan=2>\n" 
                   "%s</td></tr>\n"                 /* empty */ 
 
                   "<tr%s><td bgcolor=\"%s\">"      /* bgcolor, outlinecolor */ 
                   "%s</td>\n"                              /* empty */ 
                   "<td%s><font size=-3>%s</font></td>" /* left, fixedleft */ 
                   "<td%s><font size=-3>%s</font></td>\n" /* right, fixedright */ 
                   "<td bgcolor=\"%s\">"            /* outlinecolor */ 
                   "%s</td></tr>\n"                 /* empty */ 
                   , 
                   args->bgcolor ? " bgcolor=\""+args->bgcolor+"\"" : "", 
                   args->titlecolor ? "<FONT color=\""+args->titlecolor+"\">" : "", 
                   args->title, 
                   args->titlecolor ? "</FONT>" : "", 
                   args->bgcolor ? " bgcolor=\""+args->bgcolor+"\"" : "", 
                   args->outlinecolor, 
                   empty, 
                   args->outlinecolor, 
                   empty, 
                   args->bgcolor ? " bgcolor=\""+args->bgcolor+"\"" : "", 
                   args->outlinecolor, 
                   empty, 
                   (args->left ? " width="+args->left+"000" : ""), 
                   (args->fixedleft ? 
                    String.strmult ("&nbsp;", (int) args->fixedleft) : "&nbsp;"), 
                   (args->right ? " width="+args->right+"000" : ""), 
                   (args->fixedright ? 
                    String.strmult ("&nbsp;", (int) args->fixedright) : "&nbsp;"), 
                   args->outlinecolor, 
                   empty); 
  case "caption": 
    return sprintf("<TR bgcolor=\"%s\">" 
                   "<TD>%s</TD>" 
                   "<TD%s>&nbsp;</TD>" 
                   "<TD>%s%s%s</TD>" 
                   "<TD%s>&nbsp;</TD>" 
                   "<TD>%s</TD></TR>", 
                   args->outlinecolor, 
                   empty, 
                   (args->left ? " width="+args->left : ""), 
                   args->titlecolor ? "<FONT color=\""+args->titlecolor+"\">" : "", 
                   args->title, 
                   args->titlecolor ? "</FONT>" : "", 
                   (args->right ? " width="+args->right : ""), 
                   empty); 
  } 
} 
 
string container_obox(string name, mapping args, 
                      string contents, object request_id) 
{ 
  string s; 
   
  if (args->help) { 
    args->right = 250; 
    args->title = "The Outlined Box container tag"; 
    contents = doc(); 
  } 
 
  // Set the defaults... 
  args->outlinecolor = args->outlinecolor || "#000000"; 
  args->style = args->style || "groupbox"; 
  if (!args->title) { 
    contents=parse_html(contents,([]),(["title":handle_title,]),args); 
  } 
 
  switch (name) { 
  case "obox": 
    s = title(args); 
    s = "<table border=0 cellpadding=0 cellspacing=0" + 
      (args->align?" align="+args->align:"") + 
      (args->width ? " width=" + args->width : "") + ">\n" + 
      s + 
      "<tr" + 
      (args->bgcolor?" bgcolor=\""+args->bgcolor:"") + 
      "\"><td bgcolor=\"" + args->outlinecolor + "\">" + 
      img_placeholder(args) + "</td>\n" 
      "<td" + (args->width && !args->fixedleft && !args->fixedright ? " width=1" : "") + 
      (args->aligncontents ? " align=" + args->aligncontents : "") + " colspan=3" + ">\n" 
      "<table border=0 cellspacing=0 cellpadding=" + (args->padding || "5") + 
      (args->spacing?" width="+(string)args->spacing:"")+">" 
      "<tr><td>\n"; 
 
      if (args->textcolor) { 
        s += "<font color=\""+args->textcolor+"\">" + contents + "</font>"; 
      } else { 
        s += contents; 
      } 
       
      s += "</td></tr></table>\n" 
        "</td><td bgcolor=\"" + args->outlinecolor + "\">" + 
        img_placeholder(args) + "</td></tr>\n" + 
        horiz_line(args) + "</table>\n"; 
 
    break; 
  } 
   
  return s; 
} 
 
array register_module() 
{ 
  return ({ 
    MODULE_PARSER, 
    ([ 
      "standard":"Outlined box", 
      "svenska":"Ramlåda", 
    ]), 
    ([  
      "standard": 
      "This is a container tag making outlined boxes.<p>" 
      "<tt>&lt;obox help&gt;&lt;/obox&gt;</tt> gives help.\n\n " 
      "<obox title=example>contents</obox>", 
      "svenska": 
      "<tt>&lt;obox help&gt;&lt;/obox&gt;</tt> är en tag som ramar " 
      "in det som står i den. <obox title=exempel>innehåll</obox>", 
    ]), 0, 1 }); 
} 
 
void start(int num, object configuration) 
{ 
  loaded = 1; 
} 
 
mapping query_container_callers() 
{ 
  return ([ "obox":container_obox, ]); 
}