/[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.6 - (hide annotations)
Sun Feb 9 17:49:53 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.5: +13 -15 lines
- removed old code

1 joko 1.1 <?
2     // -----------------------------------------------------------------------------
3 joko 1.6 // $Id: helper.php,v 1.5 2003/02/04 08:22:34 joko Exp $
4 joko 1.1 // -----------------------------------------------------------------------------
5     // $Log: helper.php,v $
6 joko 1.6 // Revision 1.5 2003/02/04 08:22:34 joko
7     // + function is_hash
8     // + function array_join_merge
9     //
10 joko 1.5 // Revision 1.4 2002/12/22 13:29:54 jonen
11     // + added number format helper functions:
12     // + number_format_locale()
13     // + is_amount()
14     //
15 jonen 1.4 // Revision 1.3 2002/12/11 01:00:22 joko
16     // + renamed function 'sai' to 'array_init'
17     //
18 joko 1.3 // Revision 1.2 2002/12/01 04:49:54 joko
19     // + function Dumper (from function dumpVar)
20     //
21 joko 1.2 // Revision 1.1 2002/11/12 05:42:31 joko
22     // + initial checkin
23     //
24 joko 1.1 // Revision 1.1 2002/10/29 19:15:57 cvsjoko
25     // + new checkin
26     //
27     // Revision 1.4 2002/10/26 18:24:54 cvsmax
28     // + add note to care about UTC!
29     //
30     // Revision 1.3 2002/10/25 12:05:30 cvsmax
31     // + bugfix: some db related functions wasn`t updated to new structure, done.
32     // + bugfix: reworked function validate_idle()
33     //
34     // Revision 1.2 2002/10/17 03:37:40 cvsmax
35     // - removed unused function cont_auth()
36     //
37     // Revision 1.1 2002/10/10 02:53:55 cvsmax
38     // + create new partly from old 'func_main.inc'
39     //
40     //
41     // -----------------------------------------------------------------------------
42    
43    
44     function get_date_forDisplay($arg_date) {
45     $date = new Date($arg_date);
46     // TODO:
47     // - determine this constant by asking $site->user->country, i believe we'll need some kind of mapping here
48     // - or can it be integrated with TimeZone? no, it's a locale setting (localization/preferences), isn't it?
49     return $date->getDate( DATE_FORMAT_GERMAN_SHORT );
50     }
51    
52     function get_date_forStorage($arg_date) {
53    
54     // was:
55     //$unixtime = mktime(0, 0, 0, $arg_date[1], $arg_date[0], $arg_date[2]);
56     //return date("Y-m-d", $unixtime); // english format
57    
58     // if $arg_date is an array, it is in "german"-format (really in locale format, isn't it?)
59     // TODO: check this! (do a generic reverse-map!)
60     if (is_array($arg_date)) {
61     $arg_date = join('.', $arg_date);
62     }
63     $date = new Date($arg_date);
64     $date_res = $date->getDate( DATE_FORMAT_ENGLISH_SHORT );
65     return $date_res;
66     }
67    
68     // -------------------------------------------------
69 joko 1.3 // array initializer
70 joko 1.1 // initializes passed variable (taken by reference) with an empty array
71     // does this only if it doesn't exist yet or initialization is explicitely requested ($clear = 1)
72 joko 1.3 function array_init(&$var, $clear = 0) {
73 joko 1.1 if (!is_array($var) || $clear) { $var = array(); }
74     }
75    
76    
77     // format functions
78     function isvalidemailaddress($mail) {
79 jonen 1.4 // TODO: review for regex process load
80 joko 1.1 //return ((($string = trim($string)) != '') && (($atpos = strpos($string, '@' , 1)) > 1) && (($rdotpos = strrpos($string, '.')) > ($atpos + 2)) && (strlen($string) > $rdotpos + 2));
81     if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$mail, $regs) ) {
82     return "format";
83     }
84     elseif( gethostbyname($regs[2]) == $regs[2] ) {
85     return "host";
86     }
87     return "valid";
88     }
89    
90 joko 1.6 function Dumper() {
91 joko 1.1 ob_start();
92 joko 1.6 $arg_list = func_get_args();
93     $count = 1;
94     foreach ($arg_list as $arg) {
95     print "<hr/>";
96     print_r($arg);
97     $count++;
98     }
99 joko 1.1 $var_dump = ob_get_contents();
100     ob_end_clean();
101     $var_dump = str_replace("\n", "<br>", $var_dump);
102     $var_dump = str_replace(" ", "&nbsp;", $var_dump);
103     return $var_dump;
104     }
105    
106     function session_register_safe($varname) {
107     if (!session_is_registered($varname)) {
108     session_register($varname);
109     return 1;
110     }
111     }
112    
113     //------------ getMonths ---------------------
114     // TODO: localize!
115     function getMonthNames() {
116     for ($i=1;$i<=12;$i++) {
117     $utime = strtotime("2001-$i-24 12:00:00");
118     $name = date("F",$utime);
119     $months[$i] = $name;
120     }
121     return $months;
122     }
123    
124     function null2nbsp_string($arg) {
125     if ($arg == '') {
126     $arg = '&nbsp;';
127     }
128     return $arg;
129     }
130    
131     function null2nbsp_arraywalker(&$item, $key) {
132     $item = null2nbsp_string($item);
133     }
134    
135     function null2nbsp($arg) {
136     if (is_array($arg)) {
137     array_walk($arg, 'null2nbsp_arraywalker');
138     $result = $arg;
139     } else {
140     $result = null2nbsp_string($arg);
141     }
142     return $result;
143     }
144    
145     //------------ en- and decode Birthdate -----------
146     function getEncodedBirthdate($birthdate) {
147     print "birthday: $birthdate<br>";
148     if($birthdate) {
149     $utime = strtotime($birthdate);
150     print "utime: $utime<br>";
151     $birthday = array ( date("d",$utime), date("m",$utime), date("Y",$utime) );
152     }
153     else {
154     $birthday = array('', '', '1960');
155     }
156     return $birthday;
157     }
158 jonen 1.4
159     function number_format_storage($string) {
160     $locale_info = localeconv();
161     $string = str_replace($locale_info["decimal_point"], ".", $string);
162     return $string;
163     }
164    
165     function number_format_locale1($string) {
166     $locale_info = localeconv();
167     $string = str_replace(".", $locale_info["decimal_point"], $string);
168     return $string;
169     }
170    
171    
172     function number_format_locale ($num, $decimals = null) {
173     $locale = localeconv();
174     if(!isset($decimals)) $decimals = $locale['frac_digits'];
175     return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']);
176     }
177    
178    
179     function is_amount($amount) {
180     //if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) {
181     if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) {
182     return 1;
183     }
184     }
185 joko 1.5
186    
187     // from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php
188     function is_hash( $var ) {
189     if( is_array( $var ) ) {
190     $keys = array_keys( $var );
191     $all_num = true;
192     for( $i=0; $i<count($keys); $i++ )
193     if( is_string($keys[$i] ) ) return true;
194     }
195     return false;
196     }
197    
198     // from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php
199     function array_join_merge( $arr1, $arr2 ) {
200     if( is_array( $arr1 ) and is_array( $arr2 ) ) {
201     // the same -> merge
202     $new_array = array();
203    
204     if( is_hash( $arr1 ) and is_hash( $arr2 ) ) {
205     // hashes -> merge based on keys
206     $keys = array_merge( array_keys( $arr1 ), array_keys( $arr2 ) );
207     foreach( $keys as $key ) {
208     $new_array[$key] = array_join_merge( $arr1[$key], $arr2[$key] );
209     }
210     } else {
211     // two real arrays -> merge
212     $new_array =
213     array_reverse(array_unique(array_reverse(array_merge($arr1,$arr2))));
214     }
215    
216     return $new_array;
217     } else {
218     // not the same ... take new one if defined, else the old one stays
219     return $arr2 ? $arr2 : $arr1;
220     }
221     }
222 joko 1.1
223     ?>

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