« lib/auto/share/dist/App-SocialCalc-Multiplayer/SocialCalcServersideUtilities.pm
↑ Summary
lib/auto/share/dist/App-SocialCalc-Multiplayer/socialcalcserver.pl »
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use CGI qw(:standard); | ||
| 5 | use URI; | ||
| 6 | use HTTP::Daemon; | ||
| 7 | use HTTP::Status; | ||
| 8 | use HTTP::Response; | ||
| 9 | use Socket; | ||
| 10 | use CGI::Cookie; | ||
| 11 | use LWP::UserAgent; | ||
| 12 | |||
| 13 | use SocialCalcServersideUtilities; | ||
| 14 | |||
| 15 | |||
| 16 | my $datadir = "se2-data/"; | ||
| 17 | my $versionstr = "2.02"; | ||
| 18 | my $jsdir = "/sgi/scjstest/"; | ||
| 19 | |||
| 20 | # | ||
| 21 | # This whole first section lets this code run either as a CGI script on a server | ||
| 22 | # or standalone on the desktop run from the Perl command line. | ||
| 23 | # | ||
| 24 | # The main processing starts with process_request. | ||
| 25 | # | ||
| 26 | |||
| 27 | if ($ENV{REQUEST_METHOD}) { # being run as a CGI on a server | ||
| 28 | print "Content-type: text/html\n\n"; | ||
| 29 | my $q = new CGI; | ||
| 30 | print process_request($q); | ||
| 31 | exit; | ||
| 32 | } | ||
| 33 | |||
| 34 | # running locally - do mini-server | ||
| 35 | |||
| 36 | my $d = HTTP::Daemon->new ( | ||
| 37 | LocalPort => 6557, | ||
| 38 | Reuse => 1); | ||
| 39 | |||
| 40 | if (!$d) { | ||
| 41 | print "simpleedit could not start on 127.0.0.1:6557\n"; | ||
| 42 | exit; | ||
| 43 | } | ||
| 44 | |||
| 45 | print "simpleedit15\nAccess at: http://127.0.0.1:6557/\n"; | ||
| 46 | |||
| 47 | while (my $c = $d->accept) { | ||
| 48 | |||
| 49 | # Make sure the request is from our machine | ||
| 50 | |||
| 51 | if ($c) { | ||
| 52 | my ($port, $host) = sockaddr_in(getpeername($c)); | ||
| 53 | if ($host ne inet_aton("127.0.0.1")) { | ||
| 54 | $c->close; # no - ignore request completely | ||
| 55 | undef($c); | ||
| 56 | next; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | # Process the request | ||
| 61 | |||
| 62 | while ((defined $c) && (my $r = $c->get_request)) { | ||
| 63 | if ($r->method eq 'POST' || $r->method eq 'GET') { | ||
| 64 | $c->force_last_request; | ||
| 65 | my $uri = $r->uri; | ||
| 66 | if ($uri =~ /favicon/) { # if this is a request for favicon.ico, ignore | ||
| 67 | $c->send_error(RC_NOT_FOUND); | ||
| 68 | next; | ||
| 69 | } | ||
| 70 | if ($uri =~ /\/quit$/) { | ||
| 71 | $c->send_file_response("quitmessage.html"); | ||
| 72 | $c->close; | ||
| 73 | undef($c); | ||
| 74 | exit; | ||
| 75 | } | ||
| 76 | if ($uri =~ /\/([a-z\-0-9]+)\.(gif|js|css)$/) { # ok request | ||
| 77 | $uri = "$1.$2"; | ||
| 78 | $uri = "images/$uri" if $2 eq "gif"; | ||
| 79 | # if ($2 eq "js") { | ||
| 80 | # $res->content_type("text/html; charset=UTF-8"); | ||
| 81 | # } | ||
| 82 | $c->send_file_response($uri); | ||
| 83 | next; | ||
| 84 | } | ||
| 85 | |||
| 86 | my $resp=""; | ||
| 87 | if ($r->method eq 'POST') { | ||
| 88 | my $q = new CGI($r->content()); | ||
| 89 | $resp = process_request($q) | ||
| 90 | } | ||
| 91 | else { | ||
| 92 | my $q = new CGI($r->uri->query()); | ||
| 93 | $resp = process_request($q) | ||
| 94 | } | ||
| 95 | my $res = new HTTP::Response(200); | ||
| 96 | $res->content_type("text/html; charset=UTF-8"); | ||
| 97 | $res->expires("-1d"); | ||
| 98 | $res->content($resp); | ||
| 99 | $c->send_response($res); | ||
| 100 | } | ||
| 101 | |||
| 102 | else { | ||
| 103 | $c->send_error(RC_FORBIDDEN); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | $c->close; | ||
| 108 | undef($c); | ||
| 109 | } | ||
| 110 | |||
| 111 | # | ||
| 112 | # Main routine starts here: | ||
| 113 | # | ||
| 114 | |||
| 115 | sub process_request { | ||
| 116 | |||
| 117 | my ($request) = @_; | ||
| 118 | my $q = new CGI($request); | ||
| 119 | |||
| 120 | my $response; | ||
| 121 | |||
| 122 | my ($statusmessage); | ||
| 123 | |||
| 124 | if ($q->param("loadsheet")) { # Ajax request: loadsheet=pagename.sheetname | ||
| 125 | my $fullsheetname = $q->param("loadsheet"); | ||
| 126 | $fullsheetname =~ m/^(.*)\.(.*)$/; | ||
| 127 | my $pagename = $1; | ||
| 128 | my $sheetname = $2; | ||
| 129 | my $page = {}; | ||
| 130 | load_page($q, $pagename, $page); | ||
| 131 | my $sheetstr = $page->{items}{$sheetname}{text}; | ||
| 132 | my $htmlpos = index($sheetstr, "\nHTML:\n"); | ||
| 133 | if ($htmlpos >= 0) { | ||
| 134 | $sheetstr = substr($sheetstr, 0, $htmlpos); | ||
| 135 | } | ||
| 136 | sleep 1; | ||
| 137 | return $sheetstr; | ||
| 138 | } | ||
| 139 | |||
| 140 | if ($q->param("wikitext")) { # Ajax request: wikitext=wikitext-url-encoded | ||
| 141 | my $wikitext = $q->param("wikitext"); | ||
| 142 | $wikitext = expand_wikitext($wikitext); | ||
| 143 | sleep 1; | ||
| 144 | return $wikitext; | ||
| 145 | } | ||
| 146 | |||
| 147 | if ($q->param("rpc")) { # Ajax request: rpc=functionname&arg1=...&arg2=... | ||
| 148 | # assume socialtext() function | ||
| 149 | my $nargs = $q->param("a")-0; | ||
| 150 | if (!$nargs) { | ||
| 151 | return "e#VALUE!:Bad arguments"; | ||
| 152 | } | ||
| 153 | my (@argvals, @argtypes, $returnstr); | ||
| 154 | for (my $i=1;$i<=$nargs;$i++) { | ||
| 155 | $q->param("a$i") =~ m/^(.*?)\:(.*)$/; | ||
| 156 | $argvals[$i] = $2; | ||
| 157 | $argtypes[$i] = $1; | ||
| 158 | } | ||
| 159 | my $func = $argvals[1]; | ||
| 160 | if ($func eq "regexget") { | ||
| 161 | my $ua = LWP::UserAgent->new; | ||
| 162 | $ua->agent("WKCcallableUtilities"); | ||
| 163 | $ua->timeout(5); | ||
| 164 | my $req = HTTP::Request->new("GET", $argvals[2]); | ||
| 165 | $req->header('Accept' => '*/*'); | ||
| 166 | my $res = $ua->request($req); | ||
| 167 | if ($res->is_success) { | ||
| 168 | my $returnedhtml = $res->content; | ||
| 169 | if ($argvals[3] && $returnedhtml =~ m/$argvals[3]/s) { | ||
| 170 | $returnstr = $1; | ||
| 171 | } | ||
| 172 | else { | ||
| 173 | $returnstr = $returnedhtml; | ||
| 174 | } | ||
| 175 | $returnstr = ($argvals[4] || "t") . ":" . $returnstr; | ||
| 176 | } | ||
| 177 | else { | ||
| 178 | $returnstr = "t:Unable to do regexget HTTP request: " . $res->status_line; | ||
| 179 | } | ||
| 180 | return $returnstr; | ||
| 181 | } | ||
| 182 | elsif ($func eq "wait") { | ||
| 183 | my $waittime = $argvals[2] > 0 ? $argvals[2] : 1; | ||
| 184 | sleep $waittime < 30 ? $waittime : 30; | ||
| 185 | return "b:0"; | ||
| 186 | } | ||
| 187 | else { | ||
| 188 | for (my $i=1;$i<=$nargs;$i++) { | ||
| 189 | $returnstr .= " $argvals[$i]($argtypes[$i])"; | ||
| 190 | } | ||
| 191 | return "t:$returnstr"; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | my $pagename = $q->param('pagename'); | ||
| 196 | |||
| 197 | if ($q->param('newpage')) { | ||
| 198 | $pagename = $q->param('newpagename'); | ||
| 199 | } | ||
| 200 | |||
| 201 | $pagename =~ s/[^a-zA-Z0-9_\-]*//g; | ||
| 202 | if (!$pagename) { | ||
| 203 | $pagename = "home"; | ||
| 204 | $statusmessage .= "No pagename given - using '$pagename'<br>"; | ||
| 205 | } | ||
| 206 | |||
| 207 | if ($q->param('savepageedit')) { | ||
| 208 | my $newstr; | ||
| 209 | $newstr = $q->param('pagetext'); | ||
| 210 | if ($q->param('edittype') eq "clean") { | ||
| 211 | my $page = {}; | ||
| 212 | load_page($q, $pagename, $page); | ||
| 213 | $newstr =~ s/^\[(spreadsheet|datatable|drawing)\:(.+?)\]/"[$1:$2:\n" . $page->{items}{$2}{text} . "\n:$1]"/gme; | ||
| 214 | } | ||
| 215 | open (PAGEFILEOUT, ">$datadir$pagename.page.txt"); | ||
| 216 | print PAGEFILEOUT $newstr; | ||
| 217 | close PAGEFILEOUT; | ||
| 218 | $statusmessage .= "Saved updated page '$pagename'.<br>"; | ||
| 219 | } | ||
| 220 | |||
| 221 | if ($q->param("editpage") || $q->param("editrawpage")) { # when one of the "editpage" buttons is pressed | ||
| 222 | return do_editpage($q, $pagename, $statusmessage); | ||
| 223 | } | ||
| 224 | |||
| 225 | foreach my $p ($q->param) { # go through all the parameters | ||
| 226 | if ($p =~ /^edit(spreadsheet|datatable):(.*)/) { # "editspreadsheet:sheetname" pressed | ||
| 227 | return start_editsheet($pagename, $2, $q, $statusmessage); | ||
| 228 | } | ||
| 229 | if ($p =~ /^editdrawing:(.*)/) { # "editdrawing:sheetname" pressed | ||
| 230 | return start_editdrawing($pagename, $1, $q, $statusmessage); | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | if ($q->param('savespreadsheet')) { # save the edited spreadsheet | ||
| 235 | my $page = {}; | ||
| 236 | load_page($q, $pagename, $page); | ||
| 237 | my $pagestr = $page->{raw}; | ||
| 238 | my $sheetname = $q->param('sheetname'); | ||
| 239 | my $sheettype = $page->{items}{$sheetname}{type}; | ||
| 240 | |||
| 241 | $pagestr =~ s/^\[$sheettype\:$sheetname:.*?\:$sheettype\]/"[$sheettype:$sheetname:\n" . $q->param('newstr') . "\n:$sheettype]"/sme; | ||
| 242 | |||
| 243 | open (PAGEFILEOUT, ">$datadir$pagename.page.txt"); | ||
| 244 | print PAGEFILEOUT $pagestr; | ||
| 245 | close PAGEFILEOUT; | ||
| 246 | $statusmessage = | ||
| 247 | "Saved updated $sheettype '$sheetname' on page '$pagename'.<br>"; | ||
| 248 | } | ||
| 249 | |||
| 250 | $response = do_displaypage($q, $pagename, $statusmessage); # Otherwise, display page | ||
| 251 | |||
| 252 | return $response; | ||
| 253 | |||
| 254 | } | ||
| 255 | |||
| 256 | # | ||
| 257 | # load_page($q, $pagename, \%page) | ||
| 258 | # | ||
| 259 | # Loads the specified page and puts the parts into %page: | ||
| 260 | # | ||
| 261 | # %page{raw} - raw page text | ||
| 262 | # %page{clean} - page text with embedded items' bodies removed | ||
| 263 | # %page{items}{name} - hash with embedded item "name"'s info | ||
| 264 | # %page{items}{name}{text} - text of embedded item's body | ||
| 265 | # %page{items}{name}{type} - type embedded item (e.g., "spreadsheet") | ||
| 266 | # | ||
| 267 | |||
| 268 | sub load_page { | ||
| 269 | |||
| 270 | my ($q, $pagename, $page) = @_; | ||
| 271 | |||
| 272 | $page->{bodies} = {}; | ||
| 273 | |||
| 274 | open (PAGEFILEIN, "$datadir$pagename.page.txt"); | ||
| 275 | my ($rawstr, $cleanstr); | ||
| 276 | while (my $line = <PAGEFILEIN>) { | ||
| 277 | $line =~ s/\r//g; | ||
| 278 | $rawstr .= $line; | ||
| 279 | if ($line =~ m/^\[(spreadsheet|datatable|drawing)\:(.*?)\:/) { | ||
| 280 | my $type = $1; | ||
| 281 | my $name = $2; | ||
| 282 | $page->{items}{$name} = {type => $type, text => ""}; | ||
| 283 | my $itemstr; | ||
| 284 | while (my $sline = <PAGEFILEIN>) { | ||
| 285 | $sline =~ s/\r//g; | ||
| 286 | $rawstr .= $sline; | ||
| 287 | last if substr($sline, 0, length($type)+2) eq ":$type]"; | ||
| 288 | $itemstr .= $sline; | ||
| 289 | } | ||
| 290 | $page->{items}{$name}{text} = $itemstr; | ||
| 291 | $cleanstr .= "[$type:$name]\n"; | ||
| 292 | } | ||
| 293 | else { | ||
| 294 | $cleanstr .= $line; | ||
| 295 | } | ||
| 296 | } | ||
| 297 | close PAGEFILEIN; | ||
| 298 | $page->{raw} = $rawstr; | ||
| 299 | $page->{clean} = $cleanstr; | ||
| 300 | |||
| 301 | return; | ||
| 302 | } | ||
| 303 | |||
| 304 | # | ||
| 305 | # $response = do_displaypage($q, $pagename, $statusmessage) - Display page | ||
| 306 | # | ||
| 307 | |||
| 308 | sub do_displaypage { | ||
| 309 | |||
| 310 | my ($q, $pagename, $statusmessage) = @_; | ||
| 311 | my $response; | ||
| 312 | |||
| 313 | my $page = {}; | ||
| 314 | load_page($q, $pagename, $page); | ||
| 315 | |||
| 316 | open (PAGEFILEIN, "$datadir$pagename.page.txt"); | ||
| 317 | my $pagestr; | ||
| 318 | while (my $line = <PAGEFILEIN>) { | ||
| 319 | $line =~ s/\r//g; | ||
| 320 | if ($line =~ m/^\[(spreadsheet|datatable|drawing)\:(.*?)\:/) { | ||
| 321 | my $sheettype = $1; | ||
| 322 | my $sheetname = $2; | ||
| 323 | my $sheetstr; | ||
| 324 | while (my $sline = <PAGEFILEIN>) { | ||
| 325 | $sline =~ s/\r//g; | ||
| 326 | last if $sline =~ m/^:(spreadsheet|datatable|drawing)]/; | ||
| 327 | $sheetstr .= $sline; | ||
| 328 | } | ||
| 329 | my $htmlpos = index($sheetstr, "\nHTML:\n"); | ||
| 330 | my $html=""; | ||
| 331 | my $localhtml=""; | ||
| 332 | if ($htmlpos >= 0) { | ||
| 333 | $html = substr($sheetstr, $htmlpos+7); | ||
| 334 | $sheetstr = substr($sheetstr, 0, $htmlpos); | ||
| 335 | my $sheet = CreateSheet(); | ||
| 336 | my $parts = DecodeSpreadsheetSave($sheetstr); | ||
| 337 | ParseSheetSave($sheet, $parts->{sheet}); | ||
| 338 | my $context = CreateRenderContext($sheet); | ||
| 339 | $localhtml = RenderSheet($context, {newwinlinks => 0}); | ||
| 340 | } | ||
| 341 | else { | ||
| 342 | $html = "Sheet goes here"; | ||
| 343 | $localhtml = "Sheet goes here"; | ||
| 344 | } | ||
| 345 | $sheetstr = special_chars($sheetstr); | ||
| 346 | $pagestr .= <<"EOF"; | ||
| 347 | <textarea id="sheetdata-$sheetname" style="display:none;">$sheetstr</textarea> | ||
| 348 | <table cellspacing="0" cellpadding="0" width="100%"> | ||
| 349 | <tr onmouseout="hide_buttons(!document.getElementById('showb').checked);" | ||
| 350 | onmouseover="hide_buttons(false);"><td valign="top" id="sheet-$sheetname">$localhtml</td> | ||
| 351 | <td class="hideable" width="5" style="visibility:hidden;border-top:1px solid #80A9F3;border-bottom:1px solid #80A9F3;padding:6px;"> </td> | ||
| 352 | <td class="hideable" width="100" valign="middle" style="visibility:hidden;border-left:1px solid #80A9F3;padding:6px;"> | ||
| 353 | <span style="font-size:smaller;">$sheettype:<br>$sheetname<br></span> | ||
| 354 | <input type="submit" name="edit$sheettype:$sheetname" value="Edit" style="font-size:smaller;"> | ||
| 355 | </td></tr></table> | ||
| 356 | <script> | ||
| 357 | if("$sheettype"!="spreadsheet") show_$sheettype("$sheetname"); | ||
| 358 | </script> | ||
| 359 | EOF | ||
| 360 | } | ||
| 361 | else { | ||
| 362 | $pagestr .= expand_wikitext($line); | ||
| 363 | } | ||
| 364 | } | ||
| 365 | |||
| 366 | close PAGEFILEIN; | ||
| 367 | |||
| 368 | $response = <<"EOF"; | ||
| 369 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 370 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 371 | <html> | ||
| 372 | <head> | ||
| 373 | <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| 374 | <title>Simple Page Editor With Spreadsheets $versionstr</title> | ||
| 375 | <script type="text/javascript" src="${jsdir}socialcalcconstants.js"></script> | ||
| 376 | <script type="text/javascript" src="${jsdir}socialcalc-3.js"></script> | ||
| 377 | <script type="text/javascript" src="${jsdir}socialcalctableeditor.js"></script> | ||
| 378 | <script type="text/javascript" src="${jsdir}formatnumber2.js"></script> | ||
| 379 | <script type="text/javascript" src="${jsdir}formula1.js"></script> | ||
| 380 | <script type="text/javascript" src="${jsdir}drawlib3.js"></script> | ||
| 381 | <script> | ||
| 382 | |||
| 383 | function show_datatable(sheetname) { | ||
| 384 | var sheet = new SocialCalc.Sheet(); | ||
| 385 | sheet.ParseSheetSave(document.getElementById("sheetdata-"+sheetname).value); | ||
| 386 | var context=new SocialCalc.RenderContext(sheet); | ||
| 387 | context.CalculateCellSkipData(); | ||
| 388 | context.CalculateColWidthData(); | ||
| 389 | context.showGrid=true; | ||
| 390 | context.showRCHeaders=true; | ||
| 391 | var teobj=new SocialCalc.TableEditor(context); | ||
| 392 | teobj.imageprefix="/sgi/scjstest/sc"; | ||
| 393 | teobj.recalcFunction = null; | ||
| 394 | var sizes = SocialCalc.GetViewportInfo(); | ||
| 395 | var teelement=teobj.CreateTableEditor(800, 300); | ||
| 396 | var teid=document.getElementById("sheet-"+sheetname); | ||
| 397 | teid.replaceChild(teelement, teid.firstChild); | ||
| 398 | teobj.SchedulePositionCalculations(); | ||
| 399 | } | ||
| 400 | |||
| 401 | function show_drawing(sheetname) { | ||
| 402 | var teid=document.getElementById("sheet-"+sheetname); | ||
| 403 | var sheet = new SocialDraw.Sheet(teid, false, document.getElementById("sheetdata-"+sheetname).value); | ||
| 404 | sheet.Display(); | ||
| 405 | } | ||
| 406 | |||
| 407 | function hide_buttons(hide) { | ||
| 408 | var val=hide ? 'hidden':'visible'; | ||
| 409 | var tds = document.getElementsByTagName("td"); | ||
| 410 | for (var i=0; i<tds.length; i++) { | ||
| 411 | if (tds[i].className=="hideable") tds[i].style.visibility=val; | ||
| 412 | } | ||
| 413 | } | ||
| 414 | </script> | ||
| 415 | <style> | ||
| 416 | body, td, input, texarea | ||
| 417 | {font-family:verdana,helvetica,sans-serif;font-size:small;} | ||
| 418 | </style> | ||
| 419 | </head> | ||
| 420 | <body> | ||
| 421 | <form action="" method="POST"> | ||
| 422 | <div style="padding:6px;background-color:#80A9F3;"> | ||
| 423 | <div style="font-weight:bold;color:white;">SIMPLE SYSTEM FOR EDITING PAGES WITH SPREADSHEETS AND MORE</div> | ||
| 424 | <div style="color:#FDD;font-weight:bold;">$statusmessage </div> | ||
| 425 | <table cellspacing="0" cellpadding="0" width="100%"> | ||
| 426 | <tr> | ||
| 427 | <td> | ||
| 428 | Viewing page: <span style="font-style:italic;font-weight:bold;">$pagename</span> | ||
| 429 | <input type="submit" name="editpage" value="Edit This Page" style="font-size:smaller;"> | ||
| 430 | </td> | ||
| 431 | <td align="right"> | ||
| 432 | <input type="submit" name="editrawpage" value="Edit Raw Page" style="font-size:smaller;"> | ||
| 433 | </td></tr></table> | ||
| 434 | </div> | ||
| 435 | <div style="border:6px solid #80A9F3;padding:0px 10px 10px 10px;"> | ||
| 436 | <div style="padding-top:5px;"> | ||
| 437 | <table cellpadding="0" cellspacing="0"><tr><td width="100%"></td><td valign="top"> | ||
| 438 | <input id="showb" type="checkbox" value="1" onclick="hide_buttons(!this.checked);"> | ||
| 439 | </td><td style="font-size:smaller;padding-left:4px;">Show item<br>edit buttons</td> | ||
| 440 | </tr></table> | ||
| 441 | </div> | ||
| 442 | $pagestr | ||
| 443 | </div> | ||
| 444 | <div style="padding:6px;background-color:#80A9F3;"> | ||
| 445 | <div style="font-weight:bold;font-size:smaller;">Pages:</div> | ||
| 446 | <div style="font-size:smaller;"> | ||
| 447 | EOF | ||
| 448 | |||
| 449 | my @pagefiles = glob("$datadir*.page.txt"); # Get list of all pages | ||
| 450 | for (my $pnum=0; $pnum <= $#pagefiles; $pnum++) { | ||
| 451 | $pagefiles[$pnum] =~ m/^(?:.*\/){0,1}(.*).page.txt$/; | ||
| 452 | $response .= ", " if $pnum!=0; | ||
| 453 | $response .= qq!<a href="?pagename=$1">$1</a>!; | ||
| 454 | } | ||
| 455 | |||
| 456 | $response .= <<"EOF"; | ||
| 457 | </div> | ||
| 458 | <br> | ||
| 459 | <input type="hidden" name="pagename" value="$pagename"> | ||
| 460 | </form> | ||
| 461 | <form action="" method="POST"> | ||
| 462 | <input type="text" name="newpagename" value=""> | ||
| 463 | <input type="submit" name="newpage" value="Create New Page"> | ||
| 464 | </form> | ||
| 465 | </div> | ||
| 466 | <br> | ||
| 467 | </body> | ||
| 468 | </html> | ||
| 469 | EOF | ||
| 470 | |||
| 471 | return $response; | ||
| 472 | } | ||
| 473 | |||
| 474 | |||
| 475 | # | ||
| 476 | # do_editpage($q, $pagename, $statusmessage) - Show page editing display | ||
| 477 | # | ||
| 478 | |||
| 479 | sub do_editpage { | ||
| 480 | |||
| 481 | my ($q, $pagename, $statusmessage) = @_; | ||
| 482 | my $response; | ||
| 483 | |||
| 484 | my $page = {}; | ||
| 485 | load_page($q, $pagename, $page); | ||
| 486 | |||
| 487 | my $edittype = $q->param("editpage") ? "clean" : "raw"; | ||
| 488 | |||
| 489 | my $pagestr = special_chars($page->{$edittype}); | ||
| 490 | |||
| 491 | $response = <<"EOF"; | ||
| 492 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 493 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 494 | <html> | ||
| 495 | <head> | ||
| 496 | <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| 497 | <title>Simple Page Editor With Spreadsheets $versionstr</title> | ||
| 498 | <style> | ||
| 499 | body, td, input, texarea | ||
| 500 | {font-family:verdana,helvetica,sans-serif;font-size:small;} | ||
| 501 | </style> | ||
| 502 | </head> | ||
| 503 | <body> | ||
| 504 | <form name="f0" action="" method="POST"> | ||
| 505 | <div style="padding:6px;background-color:#80A9F3;"> | ||
| 506 | <div style="font-weight:bold;color:white;">SIMPLE SYSTEM FOR EDITING PAGES WITH SPREADSHEETS AND MORE</div> | ||
| 507 | <div style="color:#FDD;font-weight:bold;">$statusmessage </div> | ||
| 508 | <div style="margin-bottom:6px;">Editing page: <span style="font-style:italic;font-weight:bold;">$pagename</span></div> | ||
| 509 | <script> | ||
| 510 | function addss(sstype) { | ||
| 511 | var now = new Date(); | ||
| 512 | var name = ""+now.getFullYear()+(now.getMonth()+101).toString().substr(1)+(now.getDate()+100).toString().substr(1)+ | ||
| 513 | (now.getHours()+100).toString().substr(1)+(now.getMinutes()+100).toString().substr(1)+(now.getSeconds()+100).toString().substr(1); | ||
| 514 | var sname = | ||
| 515 | prompt("New "+sstype+" name (alphanumeric only, unique on page):", name); | ||
| 516 | if (!sname) return false; | ||
| 517 | sname = sname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); | ||
| 518 | if (!sname) return false; | ||
| 519 | document.f0.pagetext.value = | ||
| 520 | document.f0.pagetext.value + "\\n["+sstype+":" + sname +"]\\n"; | ||
| 521 | return false; | ||
| 522 | } | ||
| 523 | </script> | ||
| 524 | <div style="margin-bottom:4px;"> | ||
| 525 | <table cellspacing="0" cellpadding="0" width="100%"> | ||
| 526 | <tr> | ||
| 527 | <td> | ||
| 528 | <input type="submit" name="savepageedit" value="Save"> | ||
| 529 | <input type="hidden" name="edittype" value="$edittype"> | ||
| 530 | <input type="submit" name="canceledit" value="Cancel"> | ||
| 531 | </td> | ||
| 532 | <td align="right"> | ||
| 533 | EOF | ||
| 534 | |||
| 535 | if ($edittype eq "clean") { | ||
| 536 | $response .= <<"EOF"; | ||
| 537 | <input type="submit" value="Add Spreadsheet" onclick="return addss('spreadsheet');" style="font-size:smaller;"> | ||
| 538 | <input type="submit" value="Add Data Table" onclick="return addss('datatable');" style="font-size:smaller;"> | ||
| 539 | <input type="submit" value="Add Character Drawing" onclick="return addss('drawing');" style="font-size:smaller;"> | ||
| 540 | EOF | ||
| 541 | } | ||
| 542 | |||
| 543 | $response .= <<"EOF"; | ||
| 544 | </td></tr></table> | ||
| 545 | </div> | ||
| 546 | <textarea name="pagetext" rows="20" style="width:100%;">$pagestr</textarea> | ||
| 547 | <input type="hidden" name="pagename" value="$pagename"> | ||
| 548 | </div> | ||
| 549 | </form> | ||
| 550 | </body> | ||
| 551 | </html> | ||
| 552 | EOF | ||
| 553 | |||
| 554 | return $response; | ||
| 555 | } | ||
| 556 | |||
| 557 | # | ||
| 558 | # start_editsheet($pagename, $sheetname, $q, $statusmessage) | ||
| 559 | # - render initial editing display | ||
| 560 | # | ||
| 561 | |||
| 562 | sub start_editsheet { | ||
| 563 | |||
| 564 | my ($pagename, $sheetname, $q, $statusmessage) = @_; | ||
| 565 | |||
| 566 | my ($response, $sheetstr); | ||
| 567 | |||
| 568 | my $page = {}; | ||
| 569 | load_page($q, $pagename, $page); | ||
| 570 | |||
| 571 | $sheetstr = $page->{items}{$sheetname}{text}; | ||
| 572 | |||
| 573 | my $htmlpos = index($sheetstr, "\nHTML:\n"); | ||
| 574 | if ($htmlpos >= 0) { | ||
| 575 | $sheetstr = substr($sheetstr, 0, $htmlpos); | ||
| 576 | } | ||
| 577 | |||
| 578 | $response = <<"EOF"; # output page with edit JS code | ||
| 579 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 580 | <html> | ||
| 581 | <head> | ||
| 582 | <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| 583 | <title>Simple Page Editor With Spreadsheets $versionstr</title> | ||
| 584 | <script type="text/javascript" src="${jsdir}socialcalcconstants.js"></script> | ||
| 585 | <script type="text/javascript" src="${jsdir}socialcalc-3.js"></script> | ||
| 586 | <script type="text/javascript" src="${jsdir}socialcalctableeditor.js"></script> | ||
| 587 | <script type="text/javascript" src="${jsdir}formatnumber2.js"></script> | ||
| 588 | <script type="text/javascript" src="${jsdir}formula1.js"></script> | ||
| 589 | <script type="text/javascript" src="${jsdir}socialcalcpopup.js"></script> | ||
| 590 | <script type="text/javascript" src="${jsdir}socialcalcspreadsheetcontrol.js"></script> | ||
| 591 | <style> | ||
| 592 | body, td, input, texarea | ||
| 593 | {font-family:verdana,helvetica,sans-serif;font-size:small;} | ||
| 594 | </style> | ||
| 595 | </head> | ||
| 596 | <body> | ||
| 597 | <form name="f0" action="" method="POST"> | ||
| 598 | <div style="padding:6px;background-color:#80A9F3;"> | ||
| 599 | <div style="font-weight:bold;color:white;">SIMPLE SYSTEM FOR EDITING PAGES WITH SPREADSHEETS AND MORE</div> | ||
| 600 | <div style="color:#FDD;font-weight:bold;">$statusmessage </div> | ||
| 601 | <div style="margin-bottom:6px;">Editing page: <span style="font-style:italic;font-weight:bold;">$pagename</span></div> | ||
| 602 | <input type="submit" name="savespreadsheet" value="Save" onclick="dosave();"> | ||
| 603 | <input type="submit" name="cancelspreadsheet" value="Cancel"> | ||
| 604 | <textarea name="savestr" id="sheetdata" style="display:none;">$sheetstr</textarea> | ||
| 605 | <input type="hidden" name="newstr" id="newdata" value=""> | ||
| 606 | <input type="hidden" name="pagename" value="$pagename"> | ||
| 607 | <input type="hidden" name="sheetname" value="$sheetname"> | ||
| 608 | </div> | ||
| 609 | </form> | ||
| 610 | <div id="msg" style="position:absolute;right:15px;"> | ||
| 611 | <input type="button" style="font-size:x-small;" value="Clear" onclick="addmsg('',true);"><br> | ||
| 612 | <input type="button" style="font-size:x-small;" value="ShowCols" onclick="showvalue();"><br> | ||
| 613 | <textarea id="msgtext" style="margin-top:10px;width:140px;height:500px;"></textarea> | ||
| 614 | </div> | ||
| 615 | <div id="tableeditor" style="margin:8px 170px 10px 0px;">editor goes here</div> | ||
| 616 | <script> | ||
| 617 | |||
| 618 | document.getElementById("msgtext").value = ""; | ||
| 619 | |||
| 620 | function setmsg(msg) {document.getElementById("msg").innerHTML = msg;} | ||
| 621 | function addmsg(msg, clear) { | ||
| 622 | var msgtextid = document.getElementById("msgtext"); | ||
| 623 | if (!msgtextid) { | ||
| 624 | document.getElementById("msg").innerHTML = '<textarea id="msgtext" cols="60" rows="5"></textarea>'; | ||
| 625 | msgtextid = document.getElementById("msgtext"); | ||
| 626 | } | ||
| 627 | if (clear) msgtextid.value = ""; | ||
| 628 | if (msgtextid.value.length>0) msgtextid.value += "\\n"; | ||
| 629 | msgtextid.value += msg; | ||
| 630 | } | ||
| 631 | var heights=[]; | ||
| 632 | function showvalue() { | ||
| 633 | addmsg(spreadsheet.editor.colwidth, true); | ||
| 634 | } | ||
| 635 | |||
| 636 | // formatting callbacks | ||
| 637 | |||
| 638 | // Simple ExpandWiki code for testing | ||
| 639 | |||
| 640 | SocialCalc.Callbacks.expand_wiki = function(displayvalue, sheetobj, linkstyle, valueformat) { | ||
| 641 | |||
| 642 | var subtype = valueformat.substring(9); // stuff after text-wiki | ||
| 643 | var result = ""; | ||
| 644 | var matches, url, scestring; | ||
| 645 | |||
| 646 | switch (subtype) { | ||
| 647 | case "": | ||
| 648 | result = SocialCalc.default_expand_markup(displayvalue, sheetobj, linkstyle); | ||
| 649 | break; | ||
| 650 | |||
| 651 | case "-pagelink": | ||
| 652 | matches = displayvalue.match(/\\[(\\S+)\\s+(.+)\\]/); | ||
| 653 | if (matches) { | ||
| 654 | url = encodeURI(matches[1]); | ||
| 655 | scestring = SocialCalc.special_chars(matches[2]); | ||
| 656 | } | ||
| 657 | else { | ||
| 658 | matches = displayvalue.match(/\\[(.*)\\]/); | ||
| 659 | if (matches) { | ||
| 660 | url = encodeURI(matches[1]); | ||
| 661 | scestring = SocialCalc.special_chars(matches[1]); | ||
| 662 | } | ||
| 663 | else { | ||
| 664 | url = encodeURI(displayvalue); | ||
| 665 | scestring = SocialCalc.special_chars(displayvalue); | ||
| 666 | } | ||
| 667 | } | ||
| 668 | result = '<a href="?pagename='+url+'" target="_blank">'+scestring+'</a>'; | ||
| 669 | return result+ '<img src="'+spreadsheet.imagePrefix+'sc-wikilinkflag.gif" title="Link to other wiki page" alt="Link to other wiki page">'; | ||
| 670 | |||
| 671 | default: | ||
| 672 | result = SocialCalc.special_chars(valueformat+": "+displayvalue); | ||
| 673 | break; | ||
| 674 | } | ||
| 675 | |||
| 676 | return '<img src="'+spreadsheet.imagePrefix+'sc-wikiflag.gif" alt="Wikitext" title="Wikitext">' + result; | ||
| 677 | |||
| 678 | } | ||
| 679 | |||
| 680 | // Page link code | ||
| 681 | |||
| 682 | SocialCalc.Callbacks.MakePageLink = function(pagename, workspace, linktyle, valueformat) { | ||
| 683 | |||
| 684 | var result = ""; | ||
| 685 | |||
| 686 | if (workspace) { | ||
| 687 | result = "?&workspace=" + encodeURI(workspace) + "&pagename=" + encodeURI(pagename); | ||
| 688 | } | ||
| 689 | else { | ||
| 690 | result = "?&pagename=" + encodeURI(pagename); | ||
| 691 | } | ||
| 692 | |||
| 693 | return result; | ||
| 694 | |||
| 695 | } | ||
| 696 | |||
| 697 | // Additional formula functions | ||
| 698 | |||
| 699 | var funccache = {}; | ||
| 700 | var functimer = null; | ||
| 701 | var funcquery = ""; | ||
| 702 | |||
| 703 | SocialCalc.Formula.SocialtextFunction = function(fname, operand, foperand, sheet) { | ||
| 704 | |||
| 705 | var value1, t; | ||
| 706 | var scf = SocialCalc.Formula; | ||
| 707 | |||
| 708 | var query = "a="+foperand.length; | ||
| 709 | var num = 0; | ||
| 710 | |||
| 711 | while (foperand.length > 0) { | ||
| 712 | value1 = scf.OperandValueAndType(sheet, foperand); | ||
| 713 | t = encodeURI(value1.type); | ||
| 714 | num++; | ||
| 715 | query += "&a"+num+"="+t+":"+encodeURI(value1.value); | ||
| 716 | } | ||
| 717 | |||
| 718 | if (funccache[query]) { // got this already | ||
| 719 | t = funccache[query].indexOf(":"); | ||
| 720 | if (t) { | ||
| 721 | scf.PushOperand(operand, funccache[query].substring(0,t), funccache[query].substring(t+1)); | ||
| 722 | } | ||
| 723 | else { | ||
| 724 | scf.PushOperand(operand, "t", "Server Error? "+funccache[query]); | ||
| 725 | } | ||
| 726 | return null; | ||
| 727 | } | ||
| 728 | |||
| 729 | |||
| 730 | scf.RemoteFunctionInfo.waitingForServer = "SOCIALTEXT"; // say what waiting for | ||
| 731 | funcquery = query; // remember for setting when get it | ||
| 732 | ajaxrequest2("", "&rpc=socialtext&"+query); | ||
| 733 | return "Waiting for server"; // return an error for function | ||
| 734 | } | ||
| 735 | |||
| 736 | // Add to function list | ||
| 737 | SocialCalc.Formula.FunctionList["SOCIALTEXT"] = [SocialCalc.Formula.SocialtextFunction, -1]; | ||
| 738 | |||
| 739 | |||
| 740 | // define functions | ||
| 741 | |||
| 742 | function loadsheet(sheetname) { | ||
| 743 | addmsg("loadsheet:"+sheetname); | ||
| 744 | return ajaxrequest("", "&loadsheet="+encodeURIComponent(sheetname)); | ||
| 745 | } | ||
| 746 | |||
| 747 | SocialCalc.RecalcInfo.LoadSheet = loadsheet; | ||
| 748 | |||
| 749 | // function | ||
| 750 | |||
| 751 | var http_request; | ||
| 752 | |||
| 753 | function ajaxrequest(url, contents) { | ||
| 754 | |||
| 755 | http_request = null; | ||
| 756 | |||
| 757 | if (window.XMLHttpRequest) { // Mozilla, Safari,... | ||
| 758 | http_request = new XMLHttpRequest(); | ||
| 759 | } | ||
| 760 | else if (window.ActiveXObject) { // IE | ||
| 761 | try { | ||
| 762 | http_request = new ActiveXObject("Msxml2.XMLHTTP"); | ||
| 763 | } | ||
| 764 | catch (e) { | ||
| 765 | try { | ||
| 766 | http_request = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| 767 | } | ||
| 768 | catch (e) {} | ||
| 769 | } | ||
| 770 | } | ||
| 771 | if (!http_request) { | ||
| 772 | alert('Giving up :( Cannot create an XMLHTTP instance'); | ||
| 773 | return false; | ||
| 774 | } | ||
| 775 | |||
| 776 | // Make the actual request | ||
| 777 | |||
| 778 | http_request.onreadystatechange = alertContents; | ||
| 779 | http_request.open('POST', document.URL, true); // async | ||
| 780 | http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | ||
| 781 | http_request.send(contents); | ||
| 782 | |||
| 783 | return true; | ||
| 784 | |||
| 785 | } | ||
| 786 | |||
| 787 | function alertContents() { | ||
| 788 | |||
| 789 | var loadedstr = ""; | ||
| 790 | |||
| 791 | if (http_request.readyState == 4) { | ||
| 792 | addmsg("received:"+http_request.responseText.length+" chars"); | ||
| 793 | try { | ||
| 794 | if (http_request.status == 200) { | ||
| 795 | loadedstr = http_request.responseText || ""; | ||
| 796 | http_request = null; | ||
| 797 | } | ||
| 798 | else { | ||
| 799 | ; | ||
| 800 | } | ||
| 801 | } | ||
| 802 | catch (e) { | ||
| 803 | } | ||
| 804 | parts = spreadsheet.DecodeSpreadsheetSave(loadedstr); | ||
| 805 | if (parts) { | ||
| 806 | if (parts.sheet) { | ||
| 807 | SocialCalc.RecalcLoadedSheet(null, loadedstr.substring(parts.sheet.start, parts.sheet.end), true); // notify recalc loop | ||
| 808 | } | ||
| 809 | } | ||
| 810 | if (loadedstr=="") { | ||
| 811 | SocialCalc.RecalcLoadedSheet(null, "", true); // notify recalc loop that it's not available, but that we tried | ||
| 812 | } | ||
| 813 | } | ||
| 814 | } | ||
| 815 | |||
| 816 | |||
| 817 | function dosave() { | ||
| 818 | var sheetstr = spreadsheet.CreateSpreadsheetSave(); | ||
| 819 | // var htmlstr = spreadsheet.CreateSheetHTML(); | ||
| 820 | var htmlstr = "<div>No HTML Data</div>"; | ||
| 821 | document.getElementById("newdata").value = sheetstr + "\\nHTML:\\n" + htmlstr; | ||
| 822 | } | ||
| 823 | |||
| 824 | var http_request2; | ||
| 825 | |||
| 826 | function ajaxrequest2(url, contents) { | ||
| 827 | |||
| 828 | http_request2 = null; | ||
| 829 | |||
| 830 | if (window.XMLHttpRequest) { // Mozilla, Safari,... | ||
| 831 | http_request2 = new XMLHttpRequest(); | ||
| 832 | } | ||
| 833 | else if (window.ActiveXObject) { // IE | ||
| 834 | try { | ||
| 835 | http_request2 = new ActiveXObject("Msxml2.XMLHTTP"); | ||
| 836 | } | ||
| 837 | catch (e) { | ||
| 838 | try { | ||
| 839 | http_request2 = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| 840 | } | ||
| 841 | catch (e) {} | ||
| 842 | } | ||
| 843 | } | ||
| 844 | if (!http_request2) { | ||
| 845 | alert('Giving up :( Cannot create an XMLHTTP instance'); | ||
| 846 | return false; | ||
| 847 | } | ||
| 848 | |||
| 849 | // Make the actual request | ||
| 850 | |||
| 851 | http_request2.onreadystatechange = alertContents2; | ||
| 852 | http_request2.open('POST', document.URL, true); // async | ||
| 853 | http_request2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | ||
| 854 | http_request2.send(contents); | ||
| 855 | |||
| 856 | return true; | ||
| 857 | |||
| 858 | } | ||
| 859 | |||
| 860 | function alertContents2() { | ||
| 861 | |||
| 862 | var loadedstr = ""; | ||
| 863 | var parts; | ||
| 864 | |||
| 865 | if (http_request2.readyState == 4) { | ||
| 866 | try { | ||
| 867 | if (http_request2.status == 200) { | ||
| 868 | loadedstr = http_request2.responseText || ""; | ||
| 869 | http_request2 = null; | ||
| 870 | } | ||
| 871 | else { | ||
| 872 | ; | ||
| 873 | } | ||
| 874 | } | ||
| 875 | catch (e) { | ||
| 876 | } | ||
| 877 | funccache[funcquery] = loadedstr; // remember for next time | ||
| 878 | SocialCalc.Formula.RemoteFunctionInfo.waitingForServer = null; | ||
| 879 | SocialCalc.RecalcSetTimeout(); | ||
| 880 | } | ||
| 881 | } | ||
| 882 | |||
| 883 | // start everything | ||
| 884 | |||
| 885 | SocialCalc.Constants.defaultImagePrefix = "/sgi/scjstest/images/sc-"; | ||
| 886 | SocialCalc.Popup.imagePrefix = SocialCalc.Constants.defaultImagePrefix; | ||
| 887 | |||
| 888 | var spreadsheet = new SocialCalc.SpreadsheetControl(); | ||
| 889 | spreadsheet.InitializeSpreadsheetControl("tableeditor", 0, 0, 0); | ||
| 890 | |||
| 891 | var savestr = document.getElementById("sheetdata").value; | ||
| 892 | var parts = spreadsheet.DecodeSpreadsheetSave(savestr); | ||
| 893 | if (parts) { | ||
| 894 | if (parts.sheet) { | ||
| 895 | spreadsheet.sheet.ResetSheet(); | ||
| 896 | spreadsheet.ParseSheetSave(savestr.substring(parts.sheet.start, parts.sheet.end)); | ||
| 897 | } | ||
| 898 | if (parts.edit) { | ||
| 899 | spreadsheet.editor.LoadEditorSettings(savestr.substring(parts.edit.start, parts.edit.end)); | ||
| 900 | } | ||
| 901 | } | ||
| 902 | if (spreadsheet.sheet.attribs.recalc=="off") { | ||
| 903 | spreadsheet.sheet.attribs.needsrecalc = "yes"; // default turn it on | ||
| 904 | spreadsheet.ExecuteCommand('redisplay', ''); | ||
| 905 | } | ||
| 906 | else { | ||
| 907 | spreadsheet.ExecuteCommand('recalc', ''); | ||
| 908 | } | ||
| 909 | |||
| 910 | </script> | ||
| 911 | </body> | ||
| 912 | </html> | ||
| 913 | EOF | ||
| 914 | |||
| 915 | return $response; | ||
| 916 | |||
| 917 | } | ||
| 918 | |||
| 919 | |||
| 920 | # | ||
| 921 | # start_editdrawing($pagename, $sheetname, $q, $statusmessage) | ||
| 922 | # - render initial editing display | ||
| 923 | # | ||
| 924 | |||
| 925 | sub start_editdrawing { | ||
| 926 | |||
| 927 | my ($pagename, $sheetname, $q, $statusmessage) = @_; | ||
| 928 | |||
| 929 | my ($response, $sheetstr); | ||
| 930 | |||
| 931 | my $page = {}; | ||
| 932 | load_page($q, $pagename, $page); | ||
| 933 | |||
| 934 | $sheetstr = $page->{items}{$sheetname}{text}; | ||
| 935 | |||
| 936 | $response = <<"EOF"; # output page with edit JS code | ||
| 937 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 938 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 939 | <html> | ||
| 940 | <head> | ||
| 941 | <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| 942 | <title>Simple Page Editor With Spreadsheets $versionstr</title> | ||
| 943 | <script type="text/javascript" src="${jsdir}socialcalc-3.js"></script> | ||
| 944 | <script type="text/javascript" src="${jsdir}drawlib3.js"></script> | ||
| 945 | <style> | ||
| 946 | body, td, input, texarea | ||
| 947 | {font-family:verdana,helvetica,sans-serif;font-size:small;} | ||
| 948 | </style> | ||
| 949 | </head> | ||
| 950 | <body> | ||
| 951 | <form name="f0" action="" method="POST"> | ||
| 952 | <div style="padding:6px;background-color:#80A9F3;"> | ||
| 953 | <div style="font-weight:bold;color:white;">SIMPLE SYSTEM FOR EDITING PAGES WITH SPREADSHEETS AND MORE</div> | ||
| 954 | <div style="color:#FDD;font-weight:bold;">$statusmessage </div> | ||
| 955 | <div style="margin-bottom:6px;">Editing page: <span style="font-style:italic;font-weight:bold;">$pagename</span></div> | ||
| 956 | <input type="submit" name="savespreadsheet" value="Save" onclick="dosave();"> | ||
| 957 | <input type="submit" name="cancelspreadsheet" value="Cancel"> | ||
| 958 | <textarea name="savestr" id="sheetdata" style="display:none;">$sheetstr</textarea> | ||
| 959 | <input type="hidden" name="newstr" id="newdata" value=""> | ||
| 960 | <input type="hidden" name="pagename" value="$pagename"> | ||
| 961 | <input type="hidden" name="sheetname" value="$sheetname"> | ||
| 962 | </div> | ||
| 963 | </form> | ||
| 964 | <div id="drawingeditor" style="margin:8px 0px 10px 0px;"></div> | ||
| 965 | <script> | ||
| 966 | var de = document.getElementById("drawingeditor"); | ||
| 967 | var sheet = new SocialDraw.Sheet(de, true, document.getElementById("sheetdata").value); | ||
| 968 | sheet.Display(); | ||
| 969 | |||
| 970 | function dosave() { | ||
| 971 | document.getElementById("newdata").value = sheet.Save(); | ||
| 972 | } | ||
| 973 | |||
| 974 | </script> | ||
| 975 | </body> | ||
| 976 | </html> | ||
| 977 | EOF | ||
| 978 | |||
| 979 | return $response; | ||
| 980 | |||
| 981 | } | ||
| 982 | |||
| 983 | |||
| 984 | # # # # # # # # # # | ||
| 985 | # special_chars($string) | ||
| 986 | # | ||
| 987 | # Returns $estring where &, <, >, " are HTML escaped | ||
| 988 | # | ||
| 989 | |||
| 990 | sub special_chars { | ||
| 991 | my $string = shift @_; | ||
| 992 | |||
| 993 | $string =~ s/&/&/g; | ||
| 994 | $string =~ s/</</g; | ||
| 995 | $string =~ s/>/>/g; | ||
| 996 | $string =~ s/"/"/g; | ||
| 997 | |||
| 998 | return $string; | ||
| 999 | } | ||
| 1000 | |||
| 1001 | |||
| 1002 | # | ||
| 1003 | # decode_from_ajax($string) - Returns a string with | ||
| 1004 | # \n, \b, and \c escaped to \n, \, and : | ||
| 1005 | # | ||
| 1006 | |||
| 1007 | sub decode_from_ajax { | ||
| 1008 | my $string = shift @_; | ||
| 1009 | |||
| 1010 | $string =~ s/\\n/\n/g; | ||
| 1011 | $string =~ s/\\c/:/g; | ||
| 1012 | $string =~ s/\\b/\\/g; | ||
| 1013 | |||
| 1014 | return $string; | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | |||
| 1018 | # | ||
| 1019 | # encode_for_ajax($string) - Returns a string with | ||
| 1020 | # \n, \, :, and ]]> escaped to \n, \b, \c, and \e | ||
| 1021 | # | ||
| 1022 | |||
| 1023 | sub encode_for_ajax { | ||
| 1024 | my $string = shift @_; | ||
| 1025 | |||
| 1026 | $string =~ s/\\/\\b/g; | ||
| 1027 | $string =~ s/\n/\\n/g; | ||
| 1028 | $string =~ s/\r//g; | ||
| 1029 | $string =~ s/:/\\c/g; | ||
| 1030 | $string =~ s/]]>/\\e/g; | ||
| 1031 | |||
| 1032 | return $string; | ||
| 1033 | } | ||
| 1034 | |||
| 1035 | |||
| 1036 | # | ||
| 1037 | # expand_wikitext($string) - Returns $string doing wiki-style formatting | ||
| 1038 | # | ||
| 1039 | |||
| 1040 | sub expand_wikitext { | ||
| 1041 | my $string = shift @_; | ||
| 1042 | |||
| 1043 | # Process forms that use URL encoding first | ||
| 1044 | |||
| 1045 | # [page:pagename text] to link to other pages on this site | ||
| 1046 | $string =~ s!\[page:(.+?)\s+(.+?)?]!'{{lt}}a href={{quot}}?pagename=' . | ||
| 1047 | $1 . "{{quot}}{{gt}}$2\{{lt}}/a{{gt}}"!xegs; | ||
| 1048 | |||
| 1049 | # [url:url text] to link to other pages on other sites | ||
| 1050 | $string =~ s!\[url:(.+?)\s+(.+?)?]!'{{lt}}a href={{quot}}' . | ||
| 1051 | $1 . "{{quot}} target={{quot}}_blank{{quot}}{{gt}}$2\{{lt}}/a{{gt}}"!xegs; | ||
| 1052 | |||
| 1053 | # Convert &, <, >, " | ||
| 1054 | |||
| 1055 | $string = special_chars($string); | ||
| 1056 | |||
| 1057 | $string =~ s/^\= (.*) \=$/<span style="font-size:150%;font-weight:bold;">$1<\/span>/gs; | ||
| 1058 | $string =~ s/\n/<br>/g; # Line breaks are preserved | ||
| 1059 | $string =~ s/('*)'''(.*?)'''/$1<b>$2<\/b>/gs; # Wiki-style bold/italics | ||
| 1060 | $string =~ s/''(.*?)''/<i>$1<\/i>/gs; | ||
| 1061 | $string =~ s/\{\{amp}}/&/gs; # {{amp}} for ampersand | ||
| 1062 | $string =~ s/\{\{lt}}/</gs; # {{lt}} for less than | ||
| 1063 | $string =~ s/\{\{gt}}/>/gs; # {{gt}} for greater than | ||
| 1064 | $string =~ s/\{\{quot}}/"/gs; # {{quot}} for quote | ||
| 1065 | $string =~ s/\{\{lbracket}}/[/gs; # {{lbracket}} for left bracket | ||
| 1066 | $string =~ s/\{\{rbracket}}/]/gs; # {{rbracket}} for right bracket | ||
| 1067 | $string =~ s/\{\{lbrace}}/{/gs; # {{lbrace}} for brace | ||
| 1068 | |||
| 1069 | return $string; | ||
| 1070 | } | ||
| 1071 |