<<

NAME

MT::Util - Movable Type utility functions

SYNOPSIS

    use MT::Util qw( functions );

DESCRIPTION

MT::Util provides a variety of utility functions used by the Movable Type libraries.

USAGE

start_end_day($ts)

Given $ts, a timestamp in form YYYYMMDDHHMMSS, calculates the timestamp corresponding to the start of the same day, and, if called in list context, the end of the day. If called in scalar context, returns one timestamp corresponding to the start of the day; if called in list context, returns two timestamps, for the start and end of the day.

For example, given 20020410160406, returns 20020410000000 in scalar context, and 20020410000000 and 20020410235959 in list context.

start_end_week($ts)

Given $ts, a timestamp in form YYYYMMDDHHMMSS, calculates the timestamp corresponding to the start of the week, and, if called in list context, the end of the week. If called in scalar context, returns one timestamp corresponding to the start of the week; if called in list context, returns two timestamps, for the start and end of the week.

A week is defined as starting on Sunday.

For example, given 20020410160406, returns 20020407000000 in scalar context, and 20020407000000 and 20020413235959 in list context.

start_end_month($ts)

Given $ts, a timestamp in form YYYYMMDDHHMMSS, calculates the timestamp corresponding to the start of the month, and, if called in list context, the end of the month. If called in scalar context, returns one timestamp corresponding to the start of the month; if called in list context, returns two timestamps, for the start and end of the month.

For example, given 20020410160406, returns 20020401000000 in scalar context, and 20020401000000 and 20020430235959 in list context.

offset_time_list($unix_ts, $blog [, $direction ])

Given $unix_ts, a timestamp in Unix epoch format (seconds since 1970), applies the timezone offset specified in the blog $blog (either an MT::Blog object or a numeric blog ID). If daylight saving time is in effect in the local time zone (determined using the return value from localtime()), the offset is automatically adjusted.

Returns the return value of gmtime() given the adjusted Unix timestamp.

format_ts($format, $ts, $blog)

Given a timestamp $ts in form YYYYMMDDHHMMSS, applies the format specified in $format and returns the formatted string.

If specified, $blog should be an MT::Blog object, from which the date/time formatting language preference is taken (e.g. English, French, etc.). If unspecified, English formatting is used.

If $format is undef, and $blog is specified, format_ts will use a language-specific default format; if a language-specific format is not defined, or if $blog is unspecified, the default format used is %B %e, %Y %I:%M %p.

days_in($month, $year)

Returns the number of days in the month $month in the year $year. $month should be numeric, starting at 1 for January. $year should be a 4-digit year. The number of days is automatically adjusted in a leap year.

wday_from_ts($year, $month, $day)

Returns the numeric day of the week, in the range 0-6, where 0 is Sunday, for the date specified in $year, $month, and $day. $year should be a 4-digit year; $month a numeric value in the range 1-12; and $day the numeric day of the month.

first_n_words($str, $n)

Given a string $str, returns the first $n words in the string, after removing any HTML tags.

dirify($str)

Munges a string $str so that it is suitable for use as a file/directory name. HTML is removed; HTML-entities are removed; non-word/space characters are removed; spaces are changed to underscores; the entire string is converted to lower-case.

For example, the string Foo <b>Bar</b> &quot;Baz&quot; would be transformed into foo_bar_baz.

encode_html($str)

Encodes any special characters in $str into HTML entities and returns the transformed string.

If HTML::Entities is available, and if the configuration setting NoHTMLEntities is not set, uses HTML::Entities for entity-encoding. Otherwise, very simple encoding is done to catch the most common characters that need encoding.

decode_html($str)

Decodes any HTML entities in $str into the corresponding characters and returns the transformed string.

If HTML::Entities is available, and if the configuration setting NoHTMLEntities is not set, uses HTML::Entities for entity-decoding. Otherwise, very simple decoding is done to catch the most common entities that need decoding.

remove_html($str)

Removes any HTML tags from $str and returns the result.

encode_js($str)

Escapes/encodes any special characters in $str so that the string can be used safely as the value in Javascript; returns the transformed string.

encode_php($str [, $type ])

Escapes/encodes any special characters in $str so that the string can be used safely as the value in PHP code; returns the transformed string.

$type can be either qq (double-quote interpolation), here (heredoc interpolation), or q (single-quote interpolation). q is the default.

spam_protect($email_address)

Given an email address $email_address, encodes any characters that will identify it as an email address (:, @, and .) into HTML entities, so that spam harvesters will not see the email address as easily. Returns the transformed address.

is_valid_email($email_address)

Checks the email address $email_address for syntax validity; if the address--or part of it--is valid, is_valid_email returns the valid (part of) the email address. Otherwise, it returns 0.

perl_sha1_digest($msg)

Returns a SHA1 digest of $msg. The result is the usual packed binary representation. Use perl_sha1_digest_hex to get a printable string.

perl_sha1_digest_hex($msg)

Returns a SHA1 digest of $msg. The result is an ASCII string of hex digits. Use perl_sha1_digest to get a binary representation.

dsa_verify(Key => $key, Signature => $sig, [ Message => $msg | $Digest => $dgst ])

Verifies that sig is a DSA signature of $msg (or $dgst) produced using the private half of the public key given in $key. Requires Math::BigInt but doesn't call for any non-perl libraries.

AUTHOR & COPYRIGHTS

Please see the MT manpage for author, copyright, and license information.

<<