diff --git a/php/edit_place.inc.php b/php/edit_place.inc.php index 7417921..3b762b1 100644 --- a/php/edit_place.inc.php +++ b/php/edit_place.inc.php @@ -110,7 +110,7 @@ ?> - get("timezone"), $user); ?> + get("timezone"), $user); ?> diff --git a/php/photo.inc.php b/php/photo.inc.php index a8a6365..cc2140a 100644 --- a/php/photo.inc.php +++ b/php/photo.inc.php @@ -1124,16 +1124,16 @@ public function getEditArray(user $user = null) { function get_time($timezone=null, $date_format=DATE_FORMAT, $time_format=TIME_FORMAT) { if(minimum_version("5.1.0")) { - if(valid_tz($timezone)) { + if(TimeZone::validate($timezone)) { $place_tz=new TimeZone($timezone); } else { $this->lookup_location(); $loc=$this->location; - if($loc && valid_tz($loc->get("timezone"))) { + if($loc && TimeZone::validate($loc->get("timezone"))) { $place_tz=new TimeZone($loc->get("timezone")); } } - if(valid_tz(CAMERA_TZ)) { + if(TimeZone::validate(CAMERA_TZ)) { $camera_tz=new TimeZone(CAMERA_TZ); } @@ -1174,7 +1174,7 @@ function get_time($timezone=null, $date_format=DATE_FORMAT, $time_format=TIME_FO function get_time_details() { $tz=null; - if(valid_tz(CAMERA_TZ)) { + if(TimeZone::validate(CAMERA_TZ)) { $tz=CAMERA_TZ; } @@ -1612,7 +1612,7 @@ public static function removePhotosWithNoValidTZ(array $photos) { $loc=$photo->location; if(get_class($loc)=="place") { $tz=$loc->get("timezone"); - if(valid_tz($tz)) { + if(TimeZone::validate($tz)) { $gphotos[]=$photo; } } @@ -1778,7 +1778,7 @@ function create_rating_graph($user) { * Function to rotate an image */ function goodrotate($src_img, $degrees = 90) { - // angles = 0° + // angles = 0deg $degrees %= 360; if($degrees == 0) { $dst_img = $src_image; diff --git a/php/place.inc.php b/php/place.inc.php index dc472ac..b90a03a 100644 --- a/php/place.inc.php +++ b/php/place.inc.php @@ -104,7 +104,7 @@ function getChildren($user=null,$order=null) { function tzid_to_timezone() { $tzkey=$this->get("timezone_id"); if($tzkey>0) { - $tzarray=get_tz_select_array(); + $tzarray=TimeZone::getSelectArray(); $tz=$tzarray[$tzkey]; $this->set("timezone", $tz); } else { @@ -472,7 +472,7 @@ function guess_tz() { $lon=$this->get("lon"); $timezone=$this->get("timezone"); if((!$timezone && $lat && $lon) && minimum_version("5.1.0")) { - $tz=guess_tz($lat, $lon); + $tz=TimeZone::guess($lat, $lon); if($tz) { $html="" . "appendChild($rootnode); return $xml->saveXML(); } + public static function getSelectArray() { + $zones=self::listIdentifiers(); + array_unshift($zones, ""); + return $zones; + } + + public static function getKey($tz) { + return array_search($tz,self::getSelectArray()); + } + + public static function createPulldown($name, $value=null, $user=null) { + $id=preg_replace("/^_+/", "", $name); + if($value) { + $text=$value; + } else { + $text=""; + } + + if(AUTOCOMPLETE && JAVASCRIPT) { + $html=""; + $html.=""; + } else { + $html=create_pulldown("timezone_id", self::getKey($value), self::getSelectArray()); + } + return $html; + } + + + public static function validate($tz) { + // Checks if $tz contains a valid timezone string + $tzones=DateTimeZone::listIdentifiers(); + return array_search($tz, $tzones); + } + + public static function guess($lat, $lon) { + if(minimum_version("5.1.2") && class_exists("XMLReader")) { + $xml=new XMLReader(); + @$xml->open("http://ws.geonames.org/timezone?lat=" . + $lat . "&lng=" . $lon) or $failed=true; + + if (!$failed) { + while($xml->read() && !$tz) { + if($xml->name=="timezoneId") { + $xml->read(); + $tz=$xml->value; + } + } + return $tz; + } else { + $error=error_get_last(); + log::msg("Could not connect to Geonames site: " . + $error["message"], log::ERROR, log::GENERAL); + return null; + } + } else { + return null; + } + + } } class Time extends DateTime { function __construct($datetime, $tz=null) { try { - if(valid_tz($tz->getName())) { + if(TimeZone::validate($tz->getName())) { parent::__construct($datetime,$tz); } else { parent::__construct($datetime); @@ -59,64 +120,6 @@ function __construct($datetime, $tz=null) { } } -function get_tz_select_array() { - $zones=DateTimeZone::listIdentifiers(); - array_unshift($zones, ""); - return $zones; -} - -function get_tz_key($tz) { - return array_search($tz,get_tz_select_array()); -} - -function guess_tz($lat, $lon) { - if(minimum_version("5.1.2") && class_exists("XMLReader")) { - $xml=new XMLReader(); - @$xml->open("http://ws.geonames.org/timezone?lat=" . - $lat . "&lng=" . $lon) or $failed=true; - - if (!$failed) { - while($xml->read() && !$tz) { - if($xml->name=="timezoneId") { - $xml->read(); - $tz=$xml->value; - } - } - return $tz; - } else { - $error=error_get_last(); - log::msg("Could not connect to Geonames site: " . - $error["message"], log::ERROR, log::GENERAL); - return null; - } - } else { - return null; - } -} -function create_timezone_pulldown($name, $value=null, $user=null) { - $id=preg_replace("/^_+/", "", $name); - if($value) { - $text=$value; - } else { - $text=""; - } - - if(AUTOCOMPLETE && JAVASCRIPT) { - $html=""; - $html.=""; - } else { - $html=create_pulldown("timezone_id", get_tz_key($value), get_tz_select_array()); - } - return $html; -} -function valid_tz($tz) { - // Checks if $tz contains a valid timezone string - $tzones=DateTimeZone::listIdentifiers(); - return array_search($tz, $tzones); -} - ?>