1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class extends Horde_Core_Block
13: {
14: 15: 16: 17: 18:
19: private $_gallery = null;
20:
21: 22:
23: public function __construct($app, $params = array())
24: {
25: parent::__construct($app, $params);
26:
27: $this->enabled = ($GLOBALS['registry']->images->hasComments() &&
28: $GLOBALS['registry']->hasMethod('forums/getThreadsBatch'));
29: $this->_name = _("Recent Photo Comments");
30: }
31:
32: 33: 34: 35:
36: protected function _params()
37: {
38: $params = array(
39: 'gallery' => array(
40: 'name' => _("Gallery"),
41: 'type' => 'enum',
42: 'default' => '__random',
43: 'values' => array('all' => 'All')
44: )
45: );
46: $storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
47: if (empty($GLOBALS['conf']['gallery']['listlimit']) ||
48: ($storage->countGalleries(
49: $GLOBALS['registry']->getAuth(),
50: array('perm' => Horde_Perms::READ)) < $GLOBALS['conf']['gallery']['listlimit'])) {
51:
52: foreach ($storage->listGalleries(array('perm' => Horde_Perms::READ)) as $gal) {
53: $params['gallery']['values'][$gal->id] = $gal->get('name');
54: }
55: }
56:
57: return $params;
58: }
59:
60: 61:
62: protected function _title()
63: {
64: if ($this->_params['gallery'] != 'all') {
65: try {
66: $gallery = $this->_getGallery();
67: } catch (Horde_Exception $e) {
68: return Ansel::getUrlFor('view', array('view' => 'List'), true)->link() . _("Gallery") . '</a>';
69: }
70:
71: if (isset($this->_params['gallery'])) {
72: $name = htmlspecialchars($gallery->get('name'));
73: }
74: $viewurl = Ansel::getUrlFor('view',
75: array('gallery' => $gallery->id,
76: 'view' => 'Gallery',
77: 'slug' => $gallery->get('slug')),
78: true);
79: } else {
80: $viewurl = Ansel::getUrlFor('view', array('view' => 'List'), true);
81: $name = _("All Galleries");
82: }
83:
84: return sprintf(_("Recent Comments In %s"), $viewurl->link() . $name . '</a>');
85: }
86:
87: 88:
89: protected function _content()
90: {
91: global $registry;
92:
93: if ($this->_params['gallery'] == 'all') {
94: $threads = $registry->call('forums/list', array(0, 'ansel'));
95: $image_ids = array();
96: foreach ($threads as $thread) {
97: $image_ids[] = $thread['forum_name'];
98: }
99: } else {
100: try {
101: $gallery = $this->_getGallery();
102: } catch (Horde_Exception $e) {
103: return $e->getMessage();
104: }
105: $results = array();
106: $image_ids = $gallery->listImages();
107: }
108: $results = array();
109: $threads = $registry->call('forums/getThreadsBatch', array($image_ids, 'message_timestamp', 1, false, 'ansel', null, 0, 10));
110: foreach ($threads as $image_id => $messages) {
111: foreach ($messages as $message) {
112: $message['image_id'] = $image_id;
113: $results[] = $message;
114: }
115: }
116:
117: $results = $this->_asortbyindex($results, 'message_timestamp');
118: $html = '<div id="ansel_preview"></div>'
119: . '<script type="text/javascript">'
120: . 'function previewImage(e, image_id) {$(\'ansel_preview\').style.left = Event.pointerX(e) + \'px\'; $(\'ansel_preview\').style.top = Event.pointerY(e) + \'px\';new Ajax.Updater({success:\'ansel_preview\'}, \'' . Horde::url('preview.php') . '\', {method: \'post\', parameters:\'?image=\' + image_id, onsuccess:$(\'ansel_preview\').show()});}'
121: . '</script>'
122: . '<table class="linedRow" cellspacing="0" style="width:100%"><thead><tr class="item nowrap"><th class="item leftAlign">' . _("Date") . '</th><th class="item leftAlign">' . _("Image") . '</th><th class="item leftAlign">' . _("Subject") . '</th><th class="item leftAlign">' . _("By") . '</th></tr></thead><tbody>';
123:
124: foreach ($results as $comment) {
125: try {
126: $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($comment['image_id']);
127: $url = Ansel::getUrlFor('view',
128: array('view' => 'Image',
129: 'gallery' => abs($image->gallery),
130: 'image' => $comment['image_id']),
131: true);
132: $caption = substr($image->caption, 0, 30);
133: if (strlen($image->caption) > 30) {
134: $caption .= '...';
135: }
136: $html .= '<tr><td>'
137: . strftime('%x', $comment['message_timestamp'])
138: . '</td><td class="nowrap">'
139: . $url->link(array('onmouseout' => '$("ansel_preview").hide();$("ansel_preview").update("");',
140: 'onmouseover' => 'previewImage(event, ' . $comment['image_id'] . ');'))
141: . ($image->caption == '' ? $image->filename : $caption)
142: . '</a></td><td class="nowrap">'
143: . $comment['message_subject'] . '</td><td class="nowrap">'
144: . $comment['message_author'] . '</td></tr>';
145: } catch (Horde_Exception $e) {}
146: }
147: $html .= '</tbody></table>';
148:
149: return $html;
150: }
151:
152: 153: 154: 155: 156:
157: private function _getGallery()
158: {
159:
160: if ($this->_gallery instanceof Ansel_Gallery) {
161: return $this->_gallery;
162: }
163:
164:
165: if (isset($this->_params['gallery']) &&
166: $this->_params['gallery'] != '__random') {
167: $this->_gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($this->_params['gallery']);
168: } else {
169: $this->_gallery =$GLOBALS['injector']->getInstance('Ansel_Storage')->getRandomGallery();
170: }
171:
172: if (empty($this->_gallery)) {
173: throw new Horde_Exception_NotFound(_("Gallery does not exist."));
174: } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
175: throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
176: }
177:
178:
179: return $this->_gallery;
180: }
181:
182: 183: 184: 185: 186: 187: 188: 189: 190: 191:
192: private function _asortbyindex ($sortarray, $index)
193: {
194: $lastindex = count ($sortarray) - 1;
195: for ($subindex = 0; $subindex < $lastindex; $subindex++) {
196: $lastiteration = $lastindex - $subindex;
197: for ($iteration = 0; $iteration < $lastiteration; $iteration++) {
198: $nextchar = 0;
199: if ($sortarray[$iteration][$index] < $sortarray[$iteration + 1][$index]) {
200: $temp = $sortarray[$iteration];
201: $sortarray[$iteration] = $sortarray[$iteration + 1];
202: $sortarray[$iteration + 1] = $temp;
203: }
204: }
205: }
206:
207: return ($sortarray);
208: }
209:
210: }
211: