NAME

Slash::MODULE - SHORT DESCRIPTION for Slash


SYNOPSIS

        use Slash::Utility;
        # do not use this module directly


DESCRIPTION

LONG DESCRIPTION.


EXPORTED FUNCTIONS

root2abs()

Convert rootdir to its absolute equivalent. By default, rootdir is protocol-inspecific (such as ``//www.example.com'') and for redirects needs to be converted to its absolute form. There is an absolutedir var, but it is protocol-specific, and we want to inherit the protocol. So if $ENV{HTTPS} is true, we use HTTPS, else we use HTTP.

Return value
rootdir variable, converted to absolute with proper protocol.

url2abs(URL)

Take URL and make it absolute. It takes a URL, and adds rootdir to the beginning if necessary, and adds the protocol to the beginning if necessary, and then uses URI->new_abs() to get the correct string.

Parameters
URL
URL to make absolute.

Return value
Fixed URL.

formatDate(DATA [, COLUMN, AS, FORMAT])

Converts dates from the database; takes an arrayref of rows.

This example would take the 1th element of each arrayref in $data, format it, and put the result in the 2th element.

        formatDate($data, 1, 2);

This example would take the ``foo'' key of each hashref in $data, format it, and put the result in the ``bar'' key.

        formatDate($data, 'foo', 'bar');

The timeCalc function does the formatting.

Parameters
DATA
Data is either an arrayref of arrayrefs, or an arrayref of hashrefs. Which it is will be determined by whether COLUMN is numeric or not. If it is numeric, then DATA will be assumed to be an arrayref of arrayrefs.

COLUMN
The column to take the data from, to be translated. If numeric, then DATA will be taken to be an arrayref of arrayrefs. Otherwise, the value will be the hashref key. Default value is ``date''.

AS
The column where to put the newly formatted data. If COLUMN is numeric and AS is not defined, then AS will be the same value as COLUMN. Otherwise, the default value of AS is ``time''.

FORMAT
Optional Date::Format format string.

Return value
True if successful, false if not.

Side effects
Changes values in DATA.

Dependencies
The timeCalc function.

timeCalc(DATE [, FORMAT, OFFSET])

Format time strings using user's format preference.

Parameters
DATE
Raw date from database.

FORMAT
Optional format to override user's format.

OFFSET
Optional positive or negative integer for offset seconds from GMT, to override user's offset.

Return value
Formatted date string.

Dependencies
The 'atonish' and 'aton' template blocks.

changePassword()

Return new random 8-character password composed of 0..9, A..Z, a..z (but not including possibly hard-to-read characters [0O1Iil]).

Return value
Random password.

encryptPassword(PASSWD)

Encrypts given password. Currently uses MD5, but could change in the future, so do not depend on implementation.

Parameters
PASSWD
Password to be encrypted.

Return value
Encrypted password.

stripByMode(STRING [, MODE, NO_WHITESPACE_FIX])

Private function. Fixes up a string based on what the mode is. This function is no longer exported, use the strip_* functions instead.

[ Should this be somewhat templatized, so they can customize the little HTML bits? Same goes with related functions. -- pudge ]

Parameters
STRING
The string to be manipulated.

MODE
May be one of:

nohtml
The default. Just strips out HTML.

literal
Prints the text verbatim into HTML, which means just converting < and > and & to their HTML entities. Also turns on NO_WHITESPACE_FIX.

extrans
Similarly to 'literal', converts everything to its HTML entity, but then formatting is preserved by converting spaces to HTML space entities, and multiple newlines into BR tags.

code
Just like 'extrans' but wraps in CODE tags.

attribute
Attempts to format string to fit in as an HTML attribute, which means the same thing as 'literal', but `` marks are also converted to their HTML entity.

plaintext
Similar to 'extrans', but does not translate < and > and & first (so stripBadHtml is called first).

anchor
Removes ALL whitespace from inside the filter. It's is indented for use (but not limited to) the removal of white space from in side HREF anchor tags to prevent nasty browser artifacts from showing up in the display. (Note: the value of NO_WHITESPACE_FIX is ignored)

html (or anything else)
Just runs through stripBadHtml.

NO_WHITESPACE_FIX
A boolean that, if true, disables fixing of whitespace problems. A common exploit in these things is to run a lot of characters together so the page will stretch very wide. If NO_WHITESPACE_FIX is false, then space is inserted to prevent this (see breakHtml).

Return value
The manipulated string.

strip_anchor(STRING [, NO_WHITESPACE_FIX])

strip_attribute(STRING [, NO_WHITESPACE_FIX])

strip_code(STRING [, NO_WHITESPACE_FIX])

strip_extrans(STRING [, NO_WHITESPACE_FIX])

strip_html(STRING [, NO_WHITESPACE_FIX])

strip_literal(STRING [, NO_WHITESPACE_FIX])

strip_nohtml(STRING [, NO_WHITESPACE_FIX])

strip_notags(STRING [, NO_WHITESPACE_FIX])

strip_plaintext(STRING [, NO_WHITESPACE_FIX])

strip_mode(STRING [, MODE, NO_WHITESPACE_FIX])

Wrapper for stripByMode. strip_mode simply calls stripByMode and has the same arguments, but strip_mode will only allow modes with values greater than 0, that is, the user-supplied modes. strip_mode is only meant to be used for processing user-supplied modes, to prevent the user from accessing other mode types. For using specific modes instead of user-supplied modes, use the function with that mode's name.

See stripByMode for details.

stripBadHtml(STRING)

Private function. Strips out ``bad'' HTML by removing unbalanced HTML tags and sending balanced tags through approveTag. The ``unbalanced'' checker is primitive; no ``<'' or ``>'' tags will are allowed inside tag attributes (such as <A NAME=``>''>), that breaks the tag. Also, whitespace is inserted between adjacent tags, so ``<BR><BR>'' becomes ``<BR> <BR>''.

Parameters
STRING
String to be processed.

Return value
Processed string.

Dependencies
approveTag function.

breakHtml(TEXT, MAX_WORD_LENGTH)

Private function. Break up long words in some text. Will ignore the contents of HTML tags. Called from stripByMode functions.

Parameters
TEXT
The text to be fixed.

MAX_WORD_LENGTH
The maximum length of a word. Default is 50.

Return value
The text.

fixHref(URL [, ERROR])

Take a relative URL and fix it to some predefined set.

I don't really like this function much, it should be played with.

Parameters
URL
Relative URL to manipulate.

ERROR
Boolean whether or not to return error number.

Return value
Undef if URL is not handled. If it is handled and ERROR is false, new URL is returned. If it is handled and ERROR is true, URL and the error number are returned.

Dependencies
The fixhrefs section in the vars table, and some sort of table (like 404-main) for determining what the number means.

approveTag(TAG)

Private function. Checks to see if HTML tag is OK, and adjusts it as necessary.

Parameters
TAG
Tag to check.

Return value
Tag after processing.

Dependencies
Uses the ``approvetags'' variable in the vars table. Passes URLs in HREFs through fudgeurl.

fixparam(DATA)

Prepares data to be a parameter in a URL. Such as:

        my $url = 'http://example.com/foo.pl?bar=' . fixparam($data);
Parameters
DATA
The data to be escaped.

Return value
The escaped data.

fixurl(DATA)

Prepares data to be a URL or in part of a URL. Such as:

        my $url = 'http://example.com/~' . fixurl($data) . '/';
Parameters
DATA
The data to be escaped.

Return value
The escaped data.

fudgeurl(DATA)

Prepares data to be a URL. Such as:

        my $url = fixparam($someurl);
Parameters
DATA
The data to be escaped.

Return value
The escaped data.

chopEntity(STRING)

Chops a string to a specified length, without splitting in the middle of an HTML entity or HTML tag (so we will err on the short side).

Parameters
STRING
String to be chomped.

Return value
Chomped string.

balanceTags(HTML [, NO_DEEP_NESTING])

Balances HTML tags; if tags are not closed, close them; if they are not open, remove close tags; if they are in the wrong order, reorder them (order of open tags determines order of close tags).

Parameters
HTML
The HTML to balance.

NO_DEEP_NESTING
Boolean for allowing deep nesting (four deep) or not.

Return value
The balances HTML.

Dependencies
The 'approvedtags' and 'lonetags' entries in the vars table.

addDomainTags(HTML)

To be called only after balanceTags, or results are not guaranteed. Munges HTML </a> tags into </a foo.com> tags, where ``foo.com'' is the domain name of the link found in the opening <a> tag. Note that this is not proper HTML, and that dispComment knows how properly to convert it back to proper HTML.

Parameters
HTML
The HTML to tag with domains.

Return value
The tagged HTML.

Dependencies
Don't know, ask again later.

xmlencode_plain(TEXT)

Same as xmlencode(TEXT), but does not encode for use in HTML. This is currently ONLY for use for <link> elements.

Parameters
TEXT
Whatever text it is you want to encode.

Return value
The encoded string.

Dependencies
XML::Parser::Expat(3).

xmlencode(TEXT)

Encodes / escapes a string for putting into XML. The text goes through three phases: we first convert all ``&'' that are not part of an entity to ``&amp;''; then we convert all ``&'', ``<'', and ``>'' to their entities. Then all characters that are not printable ASCII characters (\040 to \176) are converted to their numeric entities (such as ``&#192;'').

Note that this is basically encoding a string into valid HTML, then escaping it for XML. When run through regular XML unescaping, a valid HTML string should remain (that is, the characters will be valid for HTML, while it may not be syntactically correct). You may use something like HTML::Entities::decode_entities if you wish to get the regular text.

Parameters
TEXT
Whatever text it is you want to encode.

Return value
The encoded string.

Dependencies
XML::Parser::Expat(3).

xmldecode(TEXT)

Decodes / unescapes an XML string. It basically just decodes the five entities used to encode ``<'', ``>'', '``', '''``, and ''&``. ''&`` is only decoded if it is not the start of an entity.

This will decode the named, decimal numeric, or hex numeric versions of the entities.

Note that while xmlencode will make sure the characters in the string are proper HTML characters, xmldecode will not take the extra step to get back the original non-HTML text; we want to leave the text as OK to put directly into HTML. You may use something like HTML::Entities::decode_entities if you wish to get the regular text.

Parameters
TEXT
Whatever text it is you want to decode.

Return value
The decoded string.

getArmoredEmail (UID)

Returns a Spam Armored email address for the user associated with the given UID.

This routine DOES NOT save its results back to the user record. This is the responsibility of the calling routine.

Parameters
UID
The user's ID whose email address you wish to randomize.

Return value
The email address, if successful.


SEE ALSO

Slash(3), Slash::Utility(3).


VERSION

$Id: Data.pm,v 1.1.2.30 2001/10/10 16:06:26 pudge Exp $