/[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.8 - (hide annotations)
Mon Mar 3 21:21:43 2003 UTC (21 years, 6 months ago) by joko
Branch: MAIN
Changes since 1.7: +14 -65 lines
refactored most reusable code to org.netfrag.glib/php_extensions.php

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

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