1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Ansel_Widget_Actions extends Ansel_Widget_Base
16: {
17: 18: 19:
20: protected $_supported_views = array('Gallery');
21:
22: 23: 24:
25: public function __construct($params)
26: {
27: $this->_title = _("Gallery Actions");
28: parent::__construct($params);
29: }
30:
31: 32: 33: 34:
35: public function html()
36: {
37: $html = $this->_htmlBegin();
38: $id = $this->_view->gallery->id;
39: $galleryurl = Horde::url('gallery.php')->add('gallery', $id);
40:
41: if ($this->_view->gallery->hasFeature('upload')) {
42: $uploadurl = Horde::url('img/upload.php')->add(
43: array('gallery' => $id,
44: 'page' => !empty($this->_view->_params['page']) ? $this->_view->_params['page'] : 0));
45: }
46:
47: $html .= '<ul style="list-style-type:none;">';
48: if (empty($this->_params['hide_slideshow']) &&
49: $this->_view->gallery->hasFeature('slideshow') &&
50: $this->_view->gallery->countImages()) {
51:
52:
53: if (!empty($this->_params['slideshow_link'])) {
54: $slideshow_url = str_replace(array('%i', '%g'),
55: array(array_pop($this->_view->gallery->listImages(0, 1)), $id),
56: urldecode($this->_params['slideshow_link']));
57: } else {
58:
59: $date = $this->_view->gallery->getDate();
60: $slideshow_url = Horde::url('view.php')->add(
61: array_merge(array('gallery' => $id,
62: 'image' => array_pop($this->_view->gallery->listImages(0, 1)),
63: 'view' => 'Slideshow'),
64: $date));
65: }
66: $html .= '<li>' . $slideshow_url->link(array('class' => 'widget')) . Horde::img('slideshow_play.png', _("Start Slideshow")) . ' ' . _("Start Slideshow") . '</a></li>';
67: }
68:
69:
70: if (!empty($uploadurl) && $this->_view->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
71: $html .= '<li>' . $uploadurl->link(array('class' => 'widget')) . Horde::img('image_add.png') . ' ' . _("Upload photos") . '</a></li>';
72:
73:
74: if ($this->_view->gallery->hasFeature('subgalleries')) {
75: $html .= '<li>' . $galleryurl->copy()->add('actionID', 'addchild')->link(array('class' => 'widget')) . Horde::img('add.png', '[icon]') . ' ' . _("Create a subgallery") . '</a></li>';
76: }
77: }
78: $html .= '</ul>';
79: $html .= $this->_getGalleryActions();
80:
81: $selfurl = Horde::selfUrl(true, true);
82: $html .= '<div class="control">'
83: . $selfurl->add('actionID', 'show_actions')->link(array('id' => 'gallery-actions-toggle', 'class' => ($GLOBALS['prefs']->getValue('show_actions') ? 'hide' : 'show')))
84: . ' </a></div>' . "\n";
85:
86: $html .= $this->_htmlEnd();
87: return $html;
88: }
89:
90: 91: 92: 93: 94:
95: protected function _getGalleryActions()
96: {
97: global $registry, $conf;
98:
99: $id = $this->_view->gallery->id;
100: $galleryurl = Horde::url('gallery.php')->add('gallery', $id);
101: $selfurl = Horde::selfUrl(true, false, true);
102: $count = $this->_view->gallery->countImages();
103: $date = $this->_view->gallery->getDate();
104:
105: $html = '<div style="display:' . (($GLOBALS['prefs']->getValue('show_actions')) ? 'block' : 'none') . ';" id="gallery-actions">';
106:
107:
108: Horde::startBuffer();
109: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('ansel', 'ToggleGalleryActions'), array(
110: 'bindTo' => 'gallery-actions'
111: ));
112: $html .= Horde::endBuffer();
113:
114:
115: $view_params = array(
116: 'gallery' => $this->_view->gallery->id,
117: 'view' => 'Gallery',
118: 'slug' => $this->_view->gallery->get('slug'),
119: 'page' => (!empty($this->_view->_params['page']) ? $this->_view->_params['page'] : 0));
120:
121:
122: $view_params = array_merge($view_params, $date);
123:
124: $html .= '<ul style="list-style-type:none;">';
125:
126:
127: if ($registry->hasMethod('bookmarks/getAddUrl')) {
128: $api_params = array(
129: 'url' => Ansel::getUrlFor('view', $view_params, true),
130: 'title' => $this->_view->gallery->get('name'));
131:
132: try {
133: $url = new Horde_Url($registry->bookmarks->getAddUrl($api_params));
134: $html .= '<li>' . $url->link(array('class' => 'widget')) . Horde::img('trean.png') . ' ' . _("Add to bookmarks") . '</a></li>';
135: } catch (Horde_Exception $e) {}
136: }
137:
138:
139: if (!empty($conf['gallery']['downloadzip']) &&
140: $this->_view->gallery->canDownload() &&
141: $count &&
142: $this->_view->gallery->hasFeature('zipdownload')) {
143:
144: $zip_params = array_merge(array('actionID' => 'downloadzip'), $date);
145: $html .= '<li>' . $galleryurl->copy()->add($zip_params)->link(array('class' => 'widget')) . Horde::img('mime/compressed.png') . ' ' . _("Download as zip file") . '</a></li>';
146: }
147:
148:
149: if ($this->_view->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
150:
151: $html .= '<li>' . $galleryurl->copy()->add(array('actionID' => 'modify', 'url' => $selfurl))->link(array('class' => 'widget')) . Horde::img('edit.png') . ' ' . _("Change properties") . '</a></li>';
152: if ($count) {
153:
154: if ($this->_view->gallery->hasFeature('image_captions')) {
155: $params = array_merge(array('gallery' => $id), $date);
156: $html .= '<li>' . Horde::url('gallery/captions.php')->add($params)->link(array('class' => 'widget')) . Horde::img('text.png') . ' ' . _("Set captions") . ' ' . '</a></li>';
157: }
158:
159:
160: if ($this->_view->gallery->hasFeature('sort_images')) {
161: $sorturl = Horde::url('gallery/sort.php')->add(array_merge(array('gallery' => $id), $date));
162: $html .= '<li>' . $sorturl->copy()->add('actionId' , 'getOrder')->link(array('class' => 'widget')) . Horde::img('arrow_switch.png') . ' ' . _("Sort photos") . '</a></li>';
163: }
164:
165:
166: $html .= '<li>' . $galleryurl->copy()->add(array('actionID' => 'generateThumbs'))->link(array('class' => 'widget')) . Horde::img('reload.png') . ' ' . _("Reset all thumbnails") . '</a></li>';
167:
168:
169: $html .= '<li>' . $galleryurl->copy()->add(array('actionID' => 'deleteCache'))->link(array('class' => 'widget')) . Horde::img('reload.png') . ' ' . _("Regenerate all photo views") . '</a></li>';
170:
171:
172: if ($conf['faces']['driver'] && $this->_view->gallery->hasFeature('faces')) {
173: $html .= '<li>' . Horde::url('faces/gallery.php')->add(
174: array_merge($date,
175: array('gallery' => $id, 'page' => (!empty($this->_view->_params['page']) ? $this->_view->_params['page'] : 0))))
176: ->link(array('class' => 'widget')) . Horde::img('user.png') . ' ' . _("Find faces") . '</a></li>';
177: }
178:
179: }
180:
181: if ($this->_view->gallery->hasFeature('stacks')) {
182: $html .= '<li>' . $galleryurl->copy()->add(array('actionID' => 'generateDefault', 'url' => $selfurl))->link(array('class' => 'widget')) . Horde::img('reload.png') . ' ' . _("Reset default photo") . '</a></li>';
183: }
184: }
185:
186: if ($GLOBALS['registry']->getAuth() &&
187: $this->_view->gallery->get('owner') == $GLOBALS['registry']->getAuth()) {
188: $url = new Horde_Url('#');
189: $html .= '<li>' . $url->link(array('class' => 'popup widget', 'onclick' => Horde::popupJs(Horde::url('perms.php'), array('params' => array('cid' => $this->_view->gallery->id), 'urlencode' => true)) . 'return false;')) . Horde::img('perms.png') . ' ' . _("Set permissions") . '</a></li>';
190: } elseif (!empty($conf['report_content']['driver']) &&
191: (($conf['report_content']['allow'] == 'authenticated' &&
192: $registry->isAuthenticated()) ||
193: $conf['report_content']['allow'] == 'all')) {
194:
195: $reporturl = Horde::url('report.php')->add('gallery', $id);
196: $html .= '<li>' . $reporturl->link(array('class' => 'widget')) . _("Report") . '</a></li>';
197: }
198:
199: if ($this->_view->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
200: $html .= '<li>' . $galleryurl->copy()->add('actionID', 'empty')->link(array('class' => 'widget')) . Horde::img('delete.png') . ' ' . _("Delete All Photos") . '</a></li>';
201: $html .= '<li>' . $galleryurl->copy()->add('actionID', 'delete')->link(array('class' => 'widget')) . Horde::img('delete.png', 'horde') . ' ' . _("Delete Entire Gallery") . '</a></li>';
202: }
203: $html .= '</ul></div>';
204:
205: return $html;
206: }
207: }
208: