1: <?php
2: 3: 4: 5: 6: 7: 8:
9: class Ansel_Widget_Tags extends Ansel_Widget_Base
10: {
11: protected $_resourceType;
12:
13: public function __construct($params)
14: {
15: parent::__construct($params);
16: $this->_resourceType = $params['view'];
17: $this->_title = _("Tags");
18: }
19:
20: 21: 22: 23: 24:
25: public function html()
26: {
27: if ($this->_resourceType == 'image') {
28: $image_id = $this->_view->resource->id;
29: } else {
30: $image_id = null;
31: }
32:
33:
34: $html = $this->_htmlBegin();
35: try {
36: $html .= '<div id="tags">' . $this->_getTagHTML() . '</div>';
37: } catch (Ansel_Exception $e) {
38: return $html . sprintf(_("There was an error fetching tags: %s"), $e->getMessage()) . $this->_htmlEnd();
39: }
40: if ($this->_view->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
41: Horde::startBuffer();
42:
43: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('ansel', 'TagActions'), array(
44: 'bindTo' => array('add' => 'tagbutton'),
45: 'gallery' => $this->_view->gallery->id,
46: 'image' => $image_id
47: ));
48: $html .= Horde::endBuffer();
49:
50: $actionUrl = Horde::url('image.php')->add(
51: array('image' => $this->_view->resource->id,
52: 'gallery' => $this->_view->gallery->id));
53:
54: $html .= '<form name="tagform" action="' . $actionUrl . '" onsubmit="return !addTag();" method="post">';
55: $html .= '<input id="addtag" name="addtag" type="text" size="15" /> <input name="tagbutton" id="tagbutton" class="button" value="' . _("Add") . '" type="submit" />';
56: $html .= '</form>';
57: }
58: $html .= $this->_htmlEnd();
59:
60: return $html;
61: }
62:
63:
64: 65: 66: 67: 68:
69: protected function _getTagHTML()
70: {
71: global $registry;
72:
73:
74: if (Horde_Util::getFormData('havesearch', 0) == 0) {
75: Ansel_Search_Tag::clearSearch();
76: }
77:
78: $tagger = $GLOBALS['injector']->getInstance('Ansel_Tagger');
79: $hasEdit = $this->_view->gallery->hasPermission($GLOBALS['registry']->getAuth(),
80: Horde_Perms::EDIT);
81: $owner = $this->_view->gallery->get('owner');
82: $tags = $tagger->getTags((int)$this->_view->resource->id, $this->_resourceType);
83: if (count($tags)) {
84: $tags = $tagger->getTagInfo(array_keys($tags), 500, $this->_resourceType);
85: }
86:
87: $links = Ansel::getTagLinks($tags, 'add', $owner);
88: $html = '<ul>';
89: foreach ($tags as $taginfo) {
90: $tag_id = $taginfo['tag_id'];
91: $html .= '<li>' . $links[$tag_id]->link(array('title' => sprintf(ngettext("%d photo", "%d photos", $taginfo['count']), $taginfo['count']))) . htmlspecialchars($taginfo['tag_name']) . '</a>' . ($hasEdit ? '<a href="#" onclick="removeTag(' . $tag_id . ');">' . Horde::img('delete-small.png', _("Remove Tag")) . '</a>' : '') . '</li>';
92: }
93: $html .= '</ul>';
94:
95: return $html;
96: }
97:
98: }
99: