App-SocialCalc-Multiplayer
view release on metacpan or search on metacpan
socialcalc/simpleedit14.pl view on Meta::CPAN
my ($pagename, $sheetname, $q, $statusmessage) = @_;
my ($response, $sheetstr);
my $page = {};
load_page($q, $pagename, $page);
$sheetstr = $page->{items}{$sheetname}{text};
$response = <<"EOF"; # output page with edit JS code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Simple Page Editor With Spreadsheets $versionstr</title>
<script type="text/javascript" src="${jsdir}socialcalc-3.js"></script>
<script type="text/javascript" src="${jsdir}drawlib3.js"></script>
<style>
body, td, input, texarea
{font-family:verdana,helvetica,sans-serif;font-size:small;}
</style>
</head>
<body>
<form name="f0" action="" method="POST">
<div style="padding:6px;background-color:#80A9F3;">
<div style="font-weight:bold;color:white;">SIMPLE SYSTEM FOR EDITING PAGES WITH SPREADSHEETS AND MORE</div>
<div style="color:#FDD;font-weight:bold;">$statusmessage </div>
<div style="margin-bottom:6px;">Editing page: <span style="font-style:italic;font-weight:bold;">$pagename</span></div>
<input type="submit" name="savespreadsheet" value="Save" onclick="dosave();">
<input type="submit" name="cancelspreadsheet" value="Cancel">
<textarea name="savestr" id="sheetdata" style="display:none;">$sheetstr</textarea>
<input type="hidden" name="newstr" id="newdata" value="">
<input type="hidden" name="pagename" value="$pagename">
<input type="hidden" name="sheetname" value="$sheetname">
</div>
</form>
<div id="drawingeditor" style="margin:8px 0px 10px 0px;"></div>
<script>
var de = document.getElementById("drawingeditor");
var sheet = new SocialDraw.Sheet(de, true, document.getElementById("sheetdata").value);
sheet.Display();
function dosave() {
document.getElementById("newdata").value = sheet.Save();
}
</script>
</body>
</html>
EOF
return $response;
}
# # # # # # # # # #
# special_chars($string)
#
# Returns $estring where &, <, >, " are HTML escaped
#
sub special_chars {
my $string = shift @_;
$string =~ s/&/&/g;
$string =~ s/</</g;
$string =~ s/>/>/g;
$string =~ s/"/"/g;
return $string;
}
#
# decode_from_ajax($string) - Returns a string with
# \n, \b, and \c escaped to \n, \, and :
#
sub decode_from_ajax {
my $string = shift @_;
$string =~ s/\\n/\n/g;
$string =~ s/\\c/:/g;
$string =~ s/\\b/\\/g;
return $string;
}
#
# encode_for_ajax($string) - Returns a string with
# \n, \, :, and ]]> escaped to \n, \b, \c, and \e
#
sub encode_for_ajax {
my $string = shift @_;
$string =~ s/\\/\\b/g;
$string =~ s/\n/\\n/g;
$string =~ s/\r//g;
$string =~ s/:/\\c/g;
$string =~ s/]]>/\\e/g;
return $string;
}
#
# expand_wikitext($string) - Returns $string doing wiki-style formatting
#
sub expand_wikitext {
my $string = shift @_;
# Process forms that use URL encoding first
# [page:pagename text] to link to other pages on this site
$string =~ s!\[page:(.+?)\s+(.+?)?]!'{{lt}}a href={{quot}}?pagename=' .
$1 . "{{quot}}{{gt}}$2\{{lt}}/a{{gt}}"!xegs;
# [url:url text] to link to other pages on other sites
$string =~ s!\[url:(.+?)\s+(.+?)?]!'{{lt}}a href={{quot}}' .
$1 . "{{quot}} target={{quot}}_blank{{quot}}{{gt}}$2\{{lt}}/a{{gt}}"!xegs;
# Convert &, <, >, "
$string = special_chars($string);
$string =~ s/^\= (.*) \=$/<span style="font-size:150%;font-weight:bold;">$1<\/span>/gs;
$string =~ s/\n/<br>/g; # Line breaks are preserved
$string =~ s/('*)'''(.*?)'''/$1<b>$2<\/b>/gs; # Wiki-style bold/italics
$string =~ s/''(.*?)''/<i>$1<\/i>/gs;
$string =~ s/\{\{amp}}/&/gs; # {{amp}} for ampersand
$string =~ s/\{\{lt}}/</gs; # {{lt}} for less than
$string =~ s/\{\{gt}}/>/gs; # {{gt}} for greater than
$string =~ s/\{\{quot}}/"/gs; # {{quot}} for quote
$string =~ s/\{\{lbracket}}/[/gs; # {{lbracket}} for left bracket
$string =~ s/\{\{rbracket}}/]/gs; # {{rbracket}} for right bracket
$string =~ s/\{\{lbrace}}/{/gs; # {{lbrace}} for brace
return $string;
}
( run in 2.253 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )