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 ($a == $b) return 0;
12 return ($a < $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=\"$continent\">";
35 $city = substr($value,strpos($value,'/')+1);
41 if($continent != 'Miscellaneous') {
43 $continent = 'Miscellaneous';
44 $o .= "<optgroup label=\"$continent\">";
47 $city = str_replace('_', ' ', $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") {
58 $d = new DateTime($s, new DateTimeZone($from));
59 $d->setTimeZone(new DateTimeZone($to));
60 return($d->format($fmt));
64 list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d');
65 $y = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
66 $o = datesel('',1920,$y,true,$year,$month,$day);
70 if(! function_exists('datesel')) {
71 function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
74 $o .= "<select name=\"{$pre}year\" class=\"{$pre}year\" size=\"1\">";
76 $sel = (($y == '0000') ? " selected=\"selected\" " : "");
77 $o .= "<option value=\"0000\" $sel ></option>";
80 for($x = $ymax; $x >= $ymin; $x --) {
81 $sel = (($x == $y) ? " selected=\"selected\" " : "");
82 $o .= "<option value=\"$x\" $sel>$x</option>";
85 $o .= "</select> <select name=\"{$pre}month\" class=\"{$pre}month\" size=\"1\">";
86 for($x = 0; $x <= 12; $x ++) {
87 $sel = (($x == $m) ? " selected=\"selected\" " : "");
88 $y = (($x) ? $x : '');
89 $o .= "<option value=\"$x\" $sel>$y</option>";
92 $o .= "</select> <select name=\"{$pre}day\" class=\"{$pre}day\" size=\"1\">";
93 for($x = 0; $x <= 31; $x ++) {
94 $sel = (($x == $d) ? " selected=\"selected\" " : "");
95 $y = (($x) ? $x : '');
96 $o .= "<option value=\"$x\" $sel>$y</option>";
104 // TODO rewrite this buggy sucker
105 function relative_date($posted_date) {
107 $localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date);
109 $in_seconds = strtotime($localtime);
111 $diff = time() - $in_seconds;
113 $months = floor($diff/2592000);
114 $diff -= $months*2419200;
115 $weeks = floor($diff/604800);
116 $diff -= $weeks*604800;
117 $days = floor($diff/86400);
118 $diff -= $days*86400;
119 $hours = floor($diff/3600);
120 $diff -= $hours*3600;
121 $minutes = floor($diff/60);
122 $diff -= $minutes*60;
126 return(datetime_convert('UTC',date_default_timezone_get(),$posted_date,'\o\n Y-m-d \a\t H:i:s'));
129 return 'over a month ago';
133 $relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks!=1 ?'s':'');
137 $relative_date .= ($relative_date?', ':'').$days.' day'.($days!=1?'s':'');
139 } elseif ($hours>0) {
141 $relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours!=1?'s':'');
143 } elseif ($minutes>0) {
145 $relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes!=1?'s':'');
148 $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds!=1?'s':'');
151 // show relative date and add proper verbiage
152 return $relative_date.' ago';
155 function age($dob,$owner_tz = '',$viewer_tz = '') {
159 $owner_tz = date_default_timezone_get();
161 $viewer_tz = date_default_timezone_get();
163 $birthdate = datetime_convert('UTC',$owner_tz,$dob . ' 00:00:00+00:00','Y-m-d');
164 list($year,$month,$day) = explode("-",$birthdate);
165 $year_diff = datetime_convert('UTC',$viewer_tz,'now','Y') - $year;
166 $curr_month = datetime_convert('UTC',$viewer_tz,'now','m');
167 $curr_day = datetime_convert('UTC',$viewer_tz,'now','d');
169 if(($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day)))