#!/usr/bin/perl -w ############################################################################### # HCCDate.pm - A custom API module for CPanel # Version 0.1.1 beta - 11/MAY/2005 # (c) 2002-2005 Juan R. Pozo # http://html.conclase.net/cp/scripts/ # mailto:jrpozo@conclase.net # Mailing-list: http://www.conclase.net/mailman/listinfo/cpanel_conclase.net ############################################################################### # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################### # For INSTALLATION and DOCUMENTATION please see: # http://html.conclase.net/cp/scripts/HCCApi.doc (plain text), or # http://html.conclase.net/cp/scripts/HCCApi.pdf (Acrobat) ############################################################################### # Please consider making a donation today. Visit my amazon.com wishlist at: # http://html.conclase.net/link/wishlist # Thank you :) ############################################################################### # Chagelog: # May 11, 2005: Fixed lang function # Sep 20, 2003: First public release ############################################################################### package Cpanel::HCCDate; use strict; use vars qw(@ISA @EXPORT $VERSION $prefix); require Exporter; @ISA = qw(Exporter); @EXPORT = qw( HCCDate_init HCCDate_Today HCCDate_StartDate ); $VERSION = '0.1.1'; $prefix = "HCCDate"; Cpanel::Lang::loadlang($Cpanel::CPDATA{LANG}); require 5.004; sub HCCDate_init { return(1); } sub HCCDate_Today { my $format = shift; if ($format =~ /^\s*['"]?([^'"]+)['"]?\s*$/) { $format = $1; print_date(time, $format); } else { print scalar localtime(time); } } sub HCCDate_StartDate { my $format = shift; if ($format =~ /^\s*['"]?([^'"]+)['"]?\s*$/) { $format = $1; print_date($Cpanel::CPDATA{'STARTDATE'}, $format); } else { print scalar localtime($Cpanel::CPDATA{'STARTDATE'}); } } sub print_date { my ($tstamp, $format) = @_; my @lt = localtime($tstamp); my $suffix; if ($lt[3]%10 == 1) { $suffix = lang("Ord1"); } elsif ($lt[3]%10 == 2) { $suffix = lang("Ord2"); } elsif ($lt[3]%10 == 3) { $suffix = lang("Ord3"); } else { $suffix = lang("OrdX"); } my %sub = ( "y" => substr($lt[5], -2), "Y" => 1900 + $lt[5], "m" => sprintf("%02d", $lt[4]+1), "f" => sprintf("%2d", $lt[4]+1), "b" => lang("MonthMid-".($lt[4]+1)), "h" => lang("MonthMid-".($lt[4]+1)), "B" => lang("MonthLong-".($lt[4]+1)),, "d" => sprintf("%02d", $lt[3]), "e" => sprintf("%2d", $lt[3]), "v" => lang("DayShort-".$lt[6]), "a" => lang("DayMid-".$lt[6]), "A" => lang("DayLong-".$lt[6]), "w" => ($lt[6]==0)?7:$lt[6], "E" => $lt[3].$suffix, "H" => sprintf("%02d", $lt[2]), "k" => sprintf("%2d", $lt[2]), "i" => sprintf("%2d", ($lt[2]%12==0)?12:$lt[2]%12), "I" => sprintf("%02d", ($lt[2]%12==0)?12:$lt[2]%12), "p" => ($lt[2]<12)?"am":"pm", "M" => sprintf("%02d", $lt[1]), "S" => sprintf("%02d", $lt[0]), "\\+" => ",", "\\%" => "\%" ); foreach my $elem (keys %sub) { $format =~ s/\%$elem/$sub{$elem}/g; } print $format; } sub lang { my ($key) = @_; return $Cpanel::Lang::LANG{$Cpanel::CPDATA{LANG}}{"${prefix}_${key}"}; } 1;