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));
65 if(! function_exists('datesel')) {
66 function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
69 $o .= "<select name=\"{$pre}year\" class=\"{$pre}year\" size=\"1\">";
71 $sel = (($y == '') ? " selected=\"selected\" " : "");
72 $o .= "<option value=\"\" $sel></option>";
75 for($x = $ymin; $x <= $ymax; $x ++) {
76 $sel = (($x == $y) ? " selected=\"selected\" " : "");
77 $o .= "<option value=\"$x\" $sel>$x</option>";
80 $o .= "</select>-<select name=\"{$pre}month\" class=\"{$pre}month\" size=\"1\">";
81 for($x = 1; $x <= 12; $x ++) {
82 $sel = (($x == $m) ? " selected=\"selected\" " : "");
83 $o .= "<option value=\"$x\" $sel>$x</option>";
86 $o .= "</select>-<select name=\"{$pre}day\" class=\"{$pre}day\" size=\"1\">";
87 for($x = 1; $x <= 31; $x ++) {
88 $sel = (($x == $d) ? " selected=\"selected\" " : "");
89 $o .= "<option value=\"$x\" $sel>$x</option>";
97 // TODO rewrite this buggy sucker
98 function relative_date($posted_date) {
100 $localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date);
102 $in_seconds = strtotime($localtime);
104 $diff = time() - $in_seconds;
106 $months = floor($diff/2592000);
107 $diff -= $months*2419200;
108 $weeks = floor($diff/604800);
109 $diff -= $weeks*604800;
110 $days = floor($diff/86400);
111 $diff -= $days*86400;
112 $hours = floor($diff/3600);
113 $diff -= $hours*3600;
114 $minutes = floor($diff/60);
115 $diff -= $minutes*60;
121 return 'over a month ago';
125 $relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks!=1 ?'s':'');
129 $relative_date .= ($relative_date?', ':'').$days.' day'.($days!=1?'s':'');
131 } elseif ($hours>0) {
133 $relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours!=1?'s':'');
135 } elseif ($minutes>0) {
137 $relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes!=1?'s':'');
140 $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds!=1?'s':'');
143 // show relative date and add proper verbiage
144 return $relative_date.' ago';