1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Ansel_Widget_ImageFaces extends Ansel_Widget_Base
14: {
15: 16: 17: 18: 19:
20: private $_supported_views = array('Image');
21:
22: 23: 24: 25: 26: 27:
28: public function __construct($params)
29: {
30: parent::__construct($params);
31: $this->_title = _("People in this photo");
32: }
33:
34: 35: 36: 37: 38:
39: public function html()
40: {
41: if ($GLOBALS['conf']['faces']['driver']) {
42: $html = $this->_getFaceNames();
43: return $this->_htmlBegin() . $html . $this->_htmlEnd();
44: } else {
45: return '';
46: }
47: }
48:
49: 50: 51: 52: 53:
54: protected function _getFaceNames()
55: {
56: $faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
57:
58:
59: $html = '';
60: $images = $faces->getImageFacesData($this->_view->resource->id, true);
61:
62:
63:
64:
65: if ($this->_view->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
66: $link_text = (empty($images) ? _("Find faces") : _("Edit faces"));
67: $html .= Horde::url('faces/gallery.php')->add('gallery', $this->_view->gallery->id)->link(
68: array('id' => 'edit_faces',
69: 'class' => 'widget'))
70: . $link_text . '</a> | '
71: . Horde::url('faces/custom.php')->add(
72: array('image' => $this->_view->resource->id,
73: 'url' => $this->_params['selfUrl']))->link(array('class' => 'widget'))
74: . _("Manual face selection") . '</a>';
75:
76:
77: Horde::startBuffer();
78: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('ansel', 'EditFaces'), array(
79: 'domid' => 'edit_faces',
80: 'image_id' => $this->_view->resource->id,
81: 'selfUrl' => $this->_params['selfUrl']
82: ));
83: $html .= Horde::endBuffer();
84: }
85:
86:
87: $html .= '<div id="faces_widget_content">';
88: if (empty($images)) {
89: return $html .= '<br /><em>' . _("No faces found") . '</em></div>';
90: }
91:
92:
93: $faces_html = '<div id="faces-on-image">';
94:
95:
96: foreach ($images as $face) {
97:
98:
99: $html .= Ansel_Faces::getFaceTile($face);
100:
101:
102: $faces_html .= '<div id="facediv' . $face['face_id'] . '" class="face-div" style="'
103: . 'width: ' . ($face['face_x2'] - $face['face_x1']) . 'px;'
104: . ' margin-left: ' . $face['face_x1'] . 'px; '
105: . ' height: ' . ($face['face_y2'] - $face['face_y1']) . 'px;'
106: . ' margin-top: ' . $face['face_y1'] . 'px;" >'
107: . '<div id="facedivname' . $face['face_id'] . '" class="face-div-name" style="display:none;">'
108: . $face['face_name'] . '</div></div>' . "\n";
109:
110:
111: $faces_html .= '<script type = "text/javascript">';
112: $faces_html .= '$(\'facediv' . $face['face_id'] . '\').observe(\'mouseover\', function() {showFace(' . $face['face_id'] . ')});'
113: . '$(\'facediv' . $face['face_id'] . '\').observe(\'mouseout\', function() {hideFace(' . $face['face_id'] . ')});'
114: . '$(\'face' . $face['face_id'] . '\').firstDescendant().observe(\'mouseover\', function() {showFace(' . $face['face_id'] . ')});'
115: . '$(\'face' . $face['face_id'] . '\').firstDescendant().observe(\'mouseout\', function() {hideFace(' . $face['face_id'] . ')});'
116: . "\n</script>\n";
117: }
118:
119:
120: $html .= $faces_html . '</div></div>';
121:
122:
123: Horde::addScriptFile('imagefaces.js', 'ansel');
124:
125: return $html;
126: }
127:
128: }
129: