/[cvs]/nfo/php/libs/org.netfrag.flib/utils/helper.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.flib/utils/helper.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations)
Wed Nov 3 14:13:45 2004 UTC (19 years, 8 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +5 -2 lines
 minor changes related to check mail-address

1 joko 1.1 <?
2     // -----------------------------------------------------------------------------
3 jonen 1.10 // $Id: helper.php,v 1.9 2004/09/07 18:52:01 jonen Exp $
4 joko 1.1 // -----------------------------------------------------------------------------
5     // $Log: helper.php,v $
6 jonen 1.10 // Revision 1.9 2004/09/07 18:52:01 jonen
7     // added function 'format_amount'
8     //
9 jonen 1.9 // Revision 1.8 2003/03/03 21:21:43 joko
10     // refactored most reusable code to org.netfrag.glib/php_extensions.php
11     //
12 joko 1.8 // Revision 1.7 2003/03/01 05:05:55 joko
13     // minor modification to 'Dumper'
14     //
15 joko 1.7 // Revision 1.6 2003/02/09 17:49:53 joko
16     // - removed old code
17     //
18 joko 1.6 // Revision 1.5 2003/02/04 08:22:34 joko
19     // + function is_hash
20     // + function array_join_merge
21     //
22 joko 1.5 // Revision 1.4 2002/12/22 13:29:54 jonen
23     // + added number format helper functions:
24     // + number_format_locale()
25     // + is_amount()
26     //
27 jonen 1.4 // Revision 1.3 2002/12/11 01:00:22 joko
28     // + renamed function 'sai' to 'array_init'
29     //
30 joko 1.3 // Revision 1.2 2002/12/01 04:49:54 joko
31     // + function Dumper (from function dumpVar)
32     //
33 joko 1.2 // Revision 1.1 2002/11/12 05:42:31 joko
34     // + initial checkin
35     //
36 joko 1.1 // Revision 1.1 2002/10/29 19:15:57 cvsjoko
37     // + new checkin
38     //
39     // Revision 1.4 2002/10/26 18:24:54 cvsmax
40     // + add note to care about UTC!
41     //
42     // Revision 1.3 2002/10/25 12:05:30 cvsmax
43     // + bugfix: some db related functions wasn`t updated to new structure, done.
44     // + bugfix: reworked function validate_idle()
45     //
46     // Revision 1.2 2002/10/17 03:37:40 cvsmax
47     // - removed unused function cont_auth()
48     //
49     // Revision 1.1 2002/10/10 02:53:55 cvsmax
50     // + create new partly from old 'func_main.inc'
51     //
52     //
53     // -----------------------------------------------------------------------------
54    
55    
56     function get_date_forDisplay($arg_date) {
57     $date = new Date($arg_date);
58     // TODO:
59     // - determine this constant by asking $site->user->country, i believe we'll need some kind of mapping here
60     // - or can it be integrated with TimeZone? no, it's a locale setting (localization/preferences), isn't it?
61     return $date->getDate( DATE_FORMAT_GERMAN_SHORT );
62     }
63    
64     function get_date_forStorage($arg_date) {
65    
66     // was:
67     //$unixtime = mktime(0, 0, 0, $arg_date[1], $arg_date[0], $arg_date[2]);
68     //return date("Y-m-d", $unixtime); // english format
69    
70     // if $arg_date is an array, it is in "german"-format (really in locale format, isn't it?)
71     // TODO: check this! (do a generic reverse-map!)
72     if (is_array($arg_date)) {
73     $arg_date = join('.', $arg_date);
74     }
75     $date = new Date($arg_date);
76     $date_res = $date->getDate( DATE_FORMAT_ENGLISH_SHORT );
77     return $date_res;
78     }
79    
80    
81    
82     // format functions
83 joko 1.8 // refactor to org.netfrag.glib::php???
84     // refactor to Data::Validator???
85 joko 1.1 function isvalidemailaddress($mail) {
86 jonen 1.4 // TODO: review for regex process load
87 joko 1.1 //return ((($string = trim($string)) != '') && (($atpos = strpos($string, '@' , 1)) > 1) && (($rdotpos = strrpos($string, '.')) > ($atpos + 2)) && (strlen($string) > $rdotpos + 2));
88     if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$mail, $regs) ) {
89     return "format";
90     }
91 jonen 1.10 elseif( gethostbyname($regs[2]) == $regs[2] ) {
92 joko 1.1 return "host";
93     }
94     return "valid";
95     }
96    
97    
98     //------------ getMonths ---------------------
99     // TODO: localize!
100     function getMonthNames() {
101     for ($i=1;$i<=12;$i++) {
102     $utime = strtotime("2001-$i-24 12:00:00");
103     $name = date("F",$utime);
104     $months[$i] = $name;
105     }
106     return $months;
107     }
108    
109 joko 1.8
110     // refactor to Data::Lift???
111 joko 1.1 function null2nbsp_string($arg) {
112     if ($arg == '') {
113     $arg = '&nbsp;';
114     }
115     return $arg;
116     }
117    
118 joko 1.8 // refactor to Data::Lift???
119 joko 1.1 function null2nbsp_arraywalker(&$item, $key) {
120     $item = null2nbsp_string($item);
121     }
122    
123 joko 1.8 // refactor to Data::Lift???
124 joko 1.1 function null2nbsp($arg) {
125     if (is_array($arg)) {
126     array_walk($arg, 'null2nbsp_arraywalker');
127     $result = $arg;
128     } else {
129     $result = null2nbsp_string($arg);
130     }
131     return $result;
132     }
133    
134     //------------ en- and decode Birthdate -----------
135     function getEncodedBirthdate($birthdate) {
136     print "birthday: $birthdate<br>";
137     if($birthdate) {
138     $utime = strtotime($birthdate);
139     print "utime: $utime<br>";
140     $birthday = array ( date("d",$utime), date("m",$utime), date("Y",$utime) );
141     }
142     else {
143     $birthday = array('', '', '1960');
144     }
145     return $birthday;
146     }
147 jonen 1.4
148     function number_format_storage($string) {
149     $locale_info = localeconv();
150     $string = str_replace($locale_info["decimal_point"], ".", $string);
151     return $string;
152     }
153    
154     function number_format_locale1($string) {
155     $locale_info = localeconv();
156     $string = str_replace(".", $locale_info["decimal_point"], $string);
157     return $string;
158     }
159    
160    
161     function number_format_locale ($num, $decimals = null) {
162     $locale = localeconv();
163 jonen 1.9 //if(!isset($decimals)) $decimals = $locale['frac_digits'];
164     if(!isset($decimals)) $decimals = 2;
165 jonen 1.4 return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']);
166     }
167    
168    
169 joko 1.8 // refactor to org.netfrag.glib::php???
170     // rename to 'check_amount'?
171     // move to Data::Validator???
172 jonen 1.4 function is_amount($amount) {
173     //if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) {
174     if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) {
175     return 1;
176     }
177     }
178 joko 1.5
179 jonen 1.9 function format_amount(&$amount) {
180     $amount = str_replace(array(".", ","), array("", "."), $amount);
181     //print "streplace amount: '$amount'<br>";
182     //return $amount;
183     }
184 joko 1.8
185 joko 1.1
186     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed