1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Ansel_Ajax_Imple_ImageSaveGeotag extends Horde_Core_Ajax_Imple
15: {
16:
17: public function attach() {}
18:
19: public function getUrl()
20: {
21: return $this->_getUrl('ImageSaveGeotag', 'ansel');
22: }
23:
24: public function handle($args, $post)
25: {
26: $type = $args['action'];
27: $location = empty($post['location']) ? null : $post['location'];
28: $lat = empty($post['lat']) ? null : $post['lat'];
29: $lng = empty($post['lng']) ? null : $post['lng'];
30: $img = $post['img'];
31:
32: if (empty($img) ||
33: ($type == 'location' && empty($location)) ||
34: ((empty($type) || $type == 'all') &&
35: ($type == 'all' && empty($lat)))) {
36:
37: return array('response' => 0);
38: }
39:
40:
41: try {
42: $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage((int)$img);
43: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
44: } catch (Ansel_Exception $e) {
45: return array('response' => 0);
46: }
47:
48:
49: if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
50: return array('response' => 0);
51: }
52: switch ($type) {
53: case 'geotag':
54: $image->geotag($lat, $lng, !empty($location) ? $location : '');
55: return array('response' => 1);
56:
57: case 'location':
58: $image->location = !empty($location) ? urldecode($location) : '';
59: $image->save();
60: return array('response' => 1, 'message' => htmlentities($image->location));
61:
62: case 'untag':
63: $image->geotag('', '', '');
64:
65: $addurl = Horde::url('map_edit.php')->add('image', $img);
66: $addLink = $addurl->link(array('onclick' => Horde::popupJs(Horde::url('map_edit.php'), array('params' => array('image' => $img), 'urlencode' => true, 'width' => '750', 'height' => '600')) . 'return false;'));
67: $imgs = $GLOBALS['injector']->getInstance('Ansel_Storage')->getRecentImagesGeodata($GLOBALS['registry']->getAuth());
68: if (count($imgs) > 0) {
69: $imgsrc = '<div class="ansel_location_sameas">';
70: foreach ($imgs as $id => $data) {
71: if (!empty($data['image_location'])) {
72: $title = $data['image_location'];
73: } else {
74: $title = $this->_point2Deg($data['image_latitude'], true) . ' ' . $this->_point2Deg($data['image_longitude']);
75: }
76: $imgsrc .= $addurl->link(
77: array('title' => $title,
78: 'onclick' => "Ansel.widgets.geotag.setLocation('" . $data['image_latitude'] . "', '" . $data['image_longitude'] . "');return false"))
79: . '<img src="' . Ansel::getImageUrl($id, 'mini', true) . '" alt="[image]" /></a>';
80: }
81: $imgsrc .= '</div>';
82: $content = sprintf(_("No location data present. Place using %smap%s or click on image to place at the same location."), $addLink, '</a>') . $imgsrc;
83: } else {
84: $content = sprintf(_("No location data present. You may add some %s."), $addLink . _("here") . '</a>');
85: }
86:
87: return array('response' => 1, 'message' => $content);
88: }
89: }
90:
91: protected function _point2Deg($value, $lat = false)
92: {
93: $letter = $lat ? ($value > 0 ? "N" : "S") : ($value > 0 ? "E" : "W");
94: $value = abs($value);
95: $deg = floor($value);
96: $min = floor(($value - $deg) * 60);
97: $sec = ($value - $deg - $min / 60) * 3600;
98: return $deg . "° " . $min . '\' ' . round($sec, 2) . '" ' . $letter;
99: }
100:
101: }
102: