package Foorum::Utils; use strict; use warnings; our $VERSION = '1.001000'; use base 'Exporter'; use vars qw/@EXPORT_OK/; @EXPORT_OK = qw/ encodeHTML decodeHTML is_color generate_random_word get_page_from_url truncate_text be_url_part get_server_timezone_diff /; use Encode (); sub encodeHTML { my $text = shift; for ($text) { s/&/&/g; s//>/g; s/"/"/g; } return $text; } sub decodeHTML { my $text = shift; for ($text) { s/\&/\&/g; s/\>/>/g; s/\</ $lmt[5] || $gmt[7] > $lmt[7] ) { $diff += 24; } elsif ( $gmt[5] < $lmt[5] || $gmt[7] < $lmt[7] ) { $diff -= 24; } return $diff; } 1; __END__ =pod =head1 NAME Foorum::Utils - some common functions =head1 FUNCTIONS =over 4 =item encodeHTML/decodeHTML Convert any '<', '>' or '&' characters to the HTML equivalents, '<', '>' and '&', respectively. encodeHTML is the same as TT filter 'html' =item is_color($color) make sure color is ^\#[0-9a-zA-Z]{6}$ =item generate_random_word($len) return a random word (length is $len), char is random ('A' .. 'Z', 'a' .. 'z', 0 .. 9) !#@!$#$^%$ bad English =item get_page_from_url since we always use /page=(\d+)/ as in sub/pager.html =item truncate_text truncate text using Encode utf8 =item be_url_part convert (title) string to be an acceptable URL part =back =head1 AUTHOR Fayland Lam =cut