/[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.3 - (hide annotations)
Wed Dec 11 01:00:22 2002 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.2: +6 -3 lines
+ renamed function 'sai' to 'array_init'

1 joko 1.1 <?
2     // -----------------------------------------------------------------------------
3 joko 1.3 // $Id: helper.php,v 1.2 2002/12/01 04:49:54 joko Exp $
4 joko 1.1 // -----------------------------------------------------------------------------
5     // $Log: helper.php,v $
6 joko 1.3 // Revision 1.2 2002/12/01 04:49:54 joko
7     // + function Dumper (from function dumpVar)
8     //
9 joko 1.2 // Revision 1.1 2002/11/12 05:42:31 joko
10     // + initial checkin
11     //
12 joko 1.1 // Revision 1.1 2002/10/29 19:15:57 cvsjoko
13     // + new checkin
14     //
15     // Revision 1.4 2002/10/26 18:24:54 cvsmax
16     // + add note to care about UTC!
17     //
18     // Revision 1.3 2002/10/25 12:05:30 cvsmax
19     // + bugfix: some db related functions wasn`t updated to new structure, done.
20     // + bugfix: reworked function validate_idle()
21     //
22     // Revision 1.2 2002/10/17 03:37:40 cvsmax
23     // - removed unused function cont_auth()
24     //
25     // Revision 1.1 2002/10/10 02:53:55 cvsmax
26     // + create new partly from old 'func_main.inc'
27     //
28     //
29     // -----------------------------------------------------------------------------
30    
31    
32     function get_date_forDisplay($arg_date) {
33     $date = new Date($arg_date);
34     // TODO:
35     // - determine this constant by asking $site->user->country, i believe we'll need some kind of mapping here
36     // - or can it be integrated with TimeZone? no, it's a locale setting (localization/preferences), isn't it?
37     return $date->getDate( DATE_FORMAT_GERMAN_SHORT );
38     }
39    
40     function get_date_forStorage($arg_date) {
41    
42     // was:
43     //$unixtime = mktime(0, 0, 0, $arg_date[1], $arg_date[0], $arg_date[2]);
44     //return date("Y-m-d", $unixtime); // english format
45    
46     // if $arg_date is an array, it is in "german"-format (really in locale format, isn't it?)
47     // TODO: check this! (do a generic reverse-map!)
48     if (is_array($arg_date)) {
49     $arg_date = join('.', $arg_date);
50     }
51     $date = new Date($arg_date);
52     $date_res = $date->getDate( DATE_FORMAT_ENGLISH_SHORT );
53     return $date_res;
54     }
55    
56     // -------------------------------------------------
57 joko 1.3 // array initializer
58 joko 1.1 // initializes passed variable (taken by reference) with an empty array
59     // does this only if it doesn't exist yet or initialization is explicitely requested ($clear = 1)
60 joko 1.3 function array_init(&$var, $clear = 0) {
61 joko 1.1 if (!is_array($var) || $clear) { $var = array(); }
62     }
63    
64    
65     // format functions
66     function isvalidemailaddress($mail) {
67     //return ((($string = trim($string)) != '') && (($atpos = strpos($string, '@' , 1)) > 1) && (($rdotpos = strrpos($string, '.')) > ($atpos + 2)) && (strlen($string) > $rdotpos + 2));
68     if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$mail, $regs) ) {
69     return "format";
70     }
71     elseif( gethostbyname($regs[2]) == $regs[2] ) {
72     return "host";
73     }
74     return "valid";
75     }
76    
77     function dumpVar($var) {
78 joko 1.2 return Dumper($var);
79     }
80    
81     function Dumper($var) {
82 joko 1.1 ob_start();
83     print_r($var);
84     $var_dump = ob_get_contents();
85     ob_end_clean();
86     $var_dump = str_replace("\n", "<br>", $var_dump);
87     $var_dump = str_replace(" ", "&nbsp;", $var_dump);
88     return $var_dump;
89     }
90    
91     function session_register_safe($varname) {
92     if (!session_is_registered($varname)) {
93     session_register($varname);
94     return 1;
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     function null2nbsp_string($arg) {
110     if ($arg == '') {
111     $arg = '&nbsp;';
112     }
113     return $arg;
114     }
115    
116     function null2nbsp_arraywalker(&$item, $key) {
117     $item = null2nbsp_string($item);
118     }
119    
120     function null2nbsp($arg) {
121     if (is_array($arg)) {
122     array_walk($arg, 'null2nbsp_arraywalker');
123     $result = $arg;
124     } else {
125     $result = null2nbsp_string($arg);
126     }
127     return $result;
128     }
129    
130     //------------ en- and decode Birthdate -----------
131     function getEncodedBirthdate($birthdate) {
132     print "birthday: $birthdate<br>";
133     if($birthdate) {
134     $utime = strtotime($birthdate);
135     print "utime: $utime<br>";
136     $birthday = array ( date("d",$utime), date("m",$utime), date("Y",$utime) );
137     }
138     else {
139     $birthday = array('', '', '1960');
140     }
141     return $birthday;
142     }
143    
144     /*
145     function dprint($message) {
146     print '<span style="font-family:Verdana,Helvetica;font-size:7pt;">';
147     print $message;
148     print '</span><br>';
149     }
150     */
151    
152     ?>

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