This package contains routines and functions that have no dependence on other ExSite code.
For purposes of decoding input, these tools are deprecated. See ExSite::Input for better input management. These tools may still be used for general-purpose hash encoding, however.
EncodeHash(%hash)
&EncodeHash
.
DecodeString($string)
Multiply-defined keys have their values appended to each other,
separated by the value of $multi_sep
(``; '' by default).
DecodeQuery()
DecodePost()
Decode the POST data. For URL-encoded form data, passes the data though &DecodeString(). Multipart-encoded data is more complex (and required for file uploads); in that case, the CGI:: package is used to parse the data.
DecodeInput()
Decodes the input to the page. Decodes either the POST or QUERY data, depending on the REQUEST_METHOD.
DecodeAttributes($string)
key1=val1 key2="quoted val2" key3='another quoted value' key4
Returns a hash or hashref of the keys => values. Only parses the key/value pairings and quotes; does not do any HTML escape handling.
columnwise($ref)
input: an array of hash references with identical keys.
output: a hash of arrays, indexed by the same keys. For instance,
( { a=>1, b=>2 }, { a=>3, b=>4 }, { a=>5, b=>6 } )
becomes ( a => [1,3,5], b => [2,4,6] )
keywise($key,$ref)
input: a hash key to index on, and an array of hash references
output: a hash of hashes, indexed by one of the keys. It is assumed that the value associated with this key is unique across all the hashes. If not, the last such key is used.
For example, taking ( { a=>1, b=>2 }, { a=>3, b=>4}, { a=>5, b=>6 } )
and indexing it by key ``a'', gives
{ 1=>{a=>1,b=>2}, 3=>{a=>3,b=>4 }
.
url_escape($text,$escape_chars)
$text
by escaping the
characters in $escape_chars
. If $escape_chars
is not given, escapes
these characters by default:
%+ &@"?#
url_unescape($text)
$text
, restoring the plaintext.
html_escape($text,$escape_chars,$use_wierd_amp_esc)
$text
by escaping the
characters in $escape_chars
. If $escape_chars
is not given,
the following characters are escaped by default:
&<>"
$use_wierd_amp_esc
is a flag, which if true, causes ``&'' to be
escaped with a non-standard escape code ``<!amp>''. This is sometimes
necessary to prevent the HTML editor from mangling our escape codes,
as some client browsers will rewrite the HTML against our wishes.
html_unescape($text,$escape_chars,$use_wierd_amp_esc)
html_escape()
.
safetext($text)
safe(er)
for use as
variable names or field IDs.
unsafetext($text)
safehtml($html,@tags)
Makes an untrusted HTML string safer to inline into a web page, by disabling all but a limited set of tags, and closing any tags that were left open. By default, it uses a set of allowed tags that are useful for minor text formatting and linking, but disallows everything else, including layout tags (divs, tables, frames, etc.), I/O tags (forms, inputs, etc.), script and style tags, and other advanced features. It allows some compound tags, such as ol/ul, li, but does not check for syntactic correctness in tag nesting. Disabled tags are rendered literally, ie. the angle brackets are shown. If the default tag list is not suitable, you can pass a list of allowed tag names.
substitute($text,$subhash,$startmark,$endmark)
Replaces marker tags such as ``[[tag]]'' with the value in $subhash{"tag"}
.
Does so for all such tags in the text. Tags may contain word
characters only (alphanumeric plus _).
html_to_plaintext($html)
latin1_to_ascii($text)
randtext($len,$src)
$len
, and composed of characters from $src
. Both parameters are
optional. Default length is 7-10 characters, and the default source string
includes most of the printable ASCII character set.
This is useful as a secure password or passkey generator.
array2text(@data)
[...]
. The array is not
guaranteed to be a perfect perl representation of the data -- the normal
usage is just to provide a unique linearization of the data for use as a
hash key. This is faster than linearizing using Storable or JSON, or hashing
using MD5.
hash2text(%data)
Converts a perl hash to a text string, similar to how the hash would
be represented in perl code if all the references were stripped out.
The hash is encoded using hashref notation {...}
. See notes under
array2text()
above.
MimeType($filename)
MimeToFile($mimetype)
ShowHash()
ShowList()
match_hash($pattern,$hash)
clean_filename($filename)
get_file($opt)
$opt
is a hash reference, which
presently only accepts one key:
adds this path value in front of any IMG SRC= attributes found in the file. (Presumably the file is HTML.)
relink(%param)
To set a new parameter, give the parameter a value in %param
. To clear
a parameter, set its value in %param
to undef
.
relink()
returns the new URL to link to.
To link back to the same URL, use &relink();
, not &relink;
.
See also Modules::BaseDCD::link(), which is better for relinking into a dynamic content module.
sizeof($dat,$max)
Sizeof()
stops counting at a size of $max, if given. This avoids
wasted cycles if you're just testing that the size is less than $max.