1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Ansel_Block_RecentlyAddedGeodata extends Horde_Core_Block
13: {
14: 15:
16: public function __construct($app, $params = array())
17: {
18: parent::__construct($app, $params);
19:
20: $this->_name = _("Recently Geotagged Photos");
21: }
22:
23: 24:
25: protected function _params()
26: {
27: return array(
28: 'limit' => array(
29: 'name' => _("Maximum number of photos"),
30: 'type' => 'int',
31: 'default' => 10
32: ),
33: 'height' => array(
34: 'name' => _("Height of map (width automatically adjusts to block)"),
35: 'type' => 'int',
36: 'default' => 250
37: ),
38: );
39: }
40:
41: 42:
43: protected function _content()
44: {
45: Ansel::initHordeMap();
46: Horde::addScriptFile('blocks/geotag.js');
47: try {
48: $images = $GLOBALS['injector']
49: ->getInstance('Ansel_Storage')
50: ->getRecentImagesGeodata(null, 0, min($this->_params['limit'], 100));
51: } catch (Ansel_Exception $e) {
52: return $e->getMessage();
53: }
54: $images = array_reverse($images);
55: foreach ($images as $key => $image) {
56: $id = $image['image_id'];
57: $gallery = $GLOBALS['injector']
58: ->getInstance('Ansel_Storage')
59: ->getGallery($image['gallery_id']);
60:
61:
62: if (!$gallery->isOldEnough() || $gallery->hasPasswd()) {
63: continue;
64: }
65: $style = $gallery->getStyle();
66:
67:
68: $url = Ansel::getUrlFor(
69: 'view',
70: array('view' => 'Image',
71: 'slug' => $gallery->get('slug'),
72: 'gallery' => $gallery->id,
73: 'image' => $id,
74: 'gallery_view' => $style->gallery_view), true);
75: $images[$key]['icon'] = (string)Ansel::getImageUrl($images[$key]['image_id'], 'mini', true);
76: $images[$key]['link'] = (string)$url;
77: $images[$key]['markerOnly'] = false;
78: }
79:
80: $imple = $GLOBALS['injector']
81: ->getInstance('Horde_Core_Factory_Imple')
82: ->create(array('ansel', 'MapLayerSelect'));
83: $layerImpleUrl = $imple->getUrl();
84:
85:
86: $defaultLayer = $GLOBALS['prefs']->getValue('current_maplayer');
87:
88: $json = Horde_Serialize::serialize(array_values($images), Horde_Serialize::JSON);
89: $html = '<div id="ansel_map" style="height:' . $this->_params['height'] . 'px;"></div>';
90: $html .= <<<EOT
91: <script type="text/javascript">
92: var opts = {
93: 'layerUpdateEndpoint': '{$layerImpleUrl}',
94: 'defaultBaseLayer': '{$defaultLayer}'
95: }
96: document.observe('dom:loaded', function() { new AnselBlockGeoTag({$json}, opts); });
97: </script>
98: EOT;
99: return $html;
100: }
101:
102: }
103: