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