3 if(! function_exists('timezone_cmp')) {
4 function timezone_cmp($a, $b) {
5 if(strstr($a,'/') && strstr($b,'/')) {
6 if ($a == $b) return 0;
7 return ($a < $b) ? -1 : 1;
9 if(strstr($a,'/')) return -1;
10 if(strstr($b,'/')) return 1;
11 if ( t($a) == t($b)) return 0;
12 return ( t($a) < t($b)) ? -1 : 1;
16 if(! function_exists('select_timezone')) {
17 function select_timezone($current = 'America/Los_Angeles') {
19 $timezone_identifiers = DateTimeZone::listIdentifiers();
21 $o ='<select id="timezone_select" name="timezone">';
23 usort($timezone_identifiers, 'timezone_cmp');
25 foreach($timezone_identifiers as $value) {
26 $ex = explode("/", $value);
28 if($ex[0] != $continent) {
32 $o .= '<optgroup label="' . t($continent) . '">';
35 $city = substr($value,strpos($value,'/')+1);
41 if($continent != 'Miscellaneous') {
43 $continent = 'Miscellaneous';
44 $o .= '<optgroup label="' . t($continent) . '">';
47 $city = str_replace('_', ' ', t($city));
48 $selected = (($value == $current) ? " selected=\"selected\" " : "");
49 $o .= "<option value=\"$value\" $selected >$city</option>";
51 $o .= '</optgroup></select>';
56 if(! function_exists('datetime_convert')) {
57 function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d H:i:s") {
59 // Slight hackish adjustment so that 'zero' datetime actually returns what is intended
60 // otherwise we end up with -0001-11-30 ...
61 // add 32 days so that we at least get year 00, and then hack around the fact that
62 // months and days always start with 1.
64 if(substr($s,0,10) == '0000-00-00') {
65 $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC'));
66 return str_replace('1','0',$d->format($fmt));
69 $d = new DateTime($s, new DateTimeZone($from));
70 $d->setTimeZone(new DateTimeZone($to));
71 return($d->format($fmt));
75 list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d');
76 $y = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
77 $o = datesel('',1920,$y,true,$year,$month,$day);
81 if(! function_exists('datesel')) {
82 function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
85 $o .= "<select name=\"{$pre}year\" class=\"{$pre}year\" size=\"1\">";
87 $sel = (($y == '0000') ? " selected=\"selected\" " : "");
88 $o .= "<option value=\"0000\" $sel ></option>";
91 for($x = $ymax; $x >= $ymin; $x --) {
92 $sel = (($x == $y) ? " selected=\"selected\" " : "");
93 $o .= "<option value=\"$x\" $sel>$x</option>";
96 $o .= "</select> <select name=\"{$pre}month\" class=\"{$pre}month\" size=\"1\">";
97 for($x = 0; $x <= 12; $x ++) {
98 $sel = (($x == $m) ? " selected=\"selected\" " : "");
99 $y = (($x) ? $x : '');
100 $o .= "<option value=\"$x\" $sel>$y</option>";
103 $o .= "</select> <select name=\"{$pre}day\" class=\"{$pre}day\" size=\"1\">";
104 for($x = 0; $x <= 31; $x ++) {
105 $sel = (($x == $d) ? " selected=\"selected\" " : "");
106 $y = (($x) ? $x : '');
107 $o .= "<option value=\"$x\" $sel>$y</option>";
115 if(! function_exists('relative_date')) {
116 function relative_date($posted_date) {
118 $localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date);
120 $abs = strtotime($localtime);
121 $etime = time() - $abs;
124 return t('less than a second ago');
127 $a = array( 12 * 30 * 24 * 60 * 60 => array( t('year'), t('years')),
128 30 * 24 * 60 * 60 => array( t('month'), t('months')),
129 7 * 24 * 60 * 60 => array( t('week'), t('weeks')),
130 24 * 60 * 60 => array( t('day'), t('days')),
131 60 * 60 => array( t('hour'), t('hours')),
132 60 => array( t('minute'), t('minutes')),
133 1 => array( t('second'), t('seconds'))
136 foreach ($a as $secs => $str) {
140 return $r . ' ' . (($r == 1) ? $str[0] : $str[1]) . t(' ago');
146 function age($dob,$owner_tz = '',$viewer_tz = '') {
150 $owner_tz = date_default_timezone_get();
152 $viewer_tz = date_default_timezone_get();
154 $birthdate = datetime_convert('UTC',$owner_tz,$dob . ' 00:00:00+00:00','Y-m-d');
155 list($year,$month,$day) = explode("-",$birthdate);
156 $year_diff = datetime_convert('UTC',$viewer_tz,'now','Y') - $year;
157 $curr_month = datetime_convert('UTC',$viewer_tz,'now','m');
158 $curr_day = datetime_convert('UTC',$viewer_tz,'now','d');
160 if(($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day)))