Overview

Packages

  • Ansel
  • None

Classes

  • Ansel
  • Ansel_Ajax_Application
  • Ansel_Ajax_Imple_EditCaption
  • Ansel_Ajax_Imple_EditFaces
  • Ansel_Ajax_Imple_EditGalleryFaces
  • Ansel_Ajax_Imple_Embed
  • Ansel_Ajax_Imple_GallerySlugCheck
  • Ansel_Ajax_Imple_ImageSaveGeotag
  • Ansel_Ajax_Imple_LocationAutoCompleter
  • Ansel_Ajax_Imple_MapLayerSelect
  • Ansel_Ajax_Imple_TagActions
  • Ansel_Ajax_Imple_ToggleGalleryActions
  • Ansel_Ajax_Imple_ToggleOtherGalleries
  • Ansel_Ajax_Imple_UploadNotification
  • Ansel_Api
  • Ansel_Exception
  • Ansel_Faces
  • Ansel_Faces_Base
  • Ansel_Faces_Facedetect
  • Ansel_Faces_User
  • Ansel_Factory_Faces
  • Ansel_Factory_Storage
  • Ansel_Factory_Styles
  • Ansel_Form_Ecard
  • Ansel_Form_Image
  • Ansel_Form_ImageDate
  • Ansel_Form_Upload
  • Ansel_Gallery
  • Ansel_Gallery_Decorator_Date
  • Ansel_GalleryMode_Base
  • Ansel_GalleryMode_Date
  • Ansel_GalleryMode_Normal
  • Ansel_Image
  • Ansel_ImageGenerator
  • Ansel_ImageGenerator_Mini
  • Ansel_ImageGenerator_PolaroidThumb
  • Ansel_ImageGenerator_PolaroidThumbStack
  • Ansel_ImageGenerator_RoundedThumb
  • Ansel_ImageGenerator_RoundedThumbStack
  • Ansel_ImageGenerator_Screen
  • Ansel_ImageGenerator_ShadowThumb
  • Ansel_ImageGenerator_ShadowThumbStack
  • Ansel_ImageGenerator_SquareThumb
  • Ansel_ImageGenerator_Thumb
  • Ansel_LoginTasks_SystemTask_Upgrade
  • Ansel_Report
  • Ansel_Report_letter
  • Ansel_Report_mail
  • Ansel_Report_tickets
  • Ansel_Search
  • Ansel_Search_exif
  • Ansel_Search_Tag
  • Ansel_Storage
  • Ansel_Style
  • Ansel_Tagger
  • Ansel_Test
  • Ansel_Tile_DateGallery
  • Ansel_Tile_Gallery
  • Ansel_Tile_Image
  • Ansel_View_Ansel
  • Ansel_View_Base
  • Ansel_View_EmbeddedRenderer_GalleryLink
  • Ansel_View_EmbeddedRenderer_Mini
  • Ansel_View_EmbeddedRenderer_Slideshow
  • Ansel_View_Gallery
  • Ansel_View_GalleryProperties
  • Ansel_View_GalleryRenderer_Base
  • Ansel_View_GalleryRenderer_Gallery
  • Ansel_View_GalleryRenderer_GalleryLightbox
  • Ansel_View_Image
  • Ansel_View_List
  • Ansel_View_Results
  • Ansel_View_Slideshow
  • Ansel_View_Upload
  • Ansel_Widget
  • Ansel_Widget_Actions
  • Ansel_Widget_Base
  • Ansel_Widget_GalleryFaces
  • Ansel_Widget_Geotag
  • Ansel_Widget_ImageFaces
  • Ansel_Widget_Links
  • Ansel_Widget_OtherGalleries
  • Ansel_Widget_OwnerFaces
  • Ansel_Widget_SimilarPhotos
  • Ansel_Widget_Tags
  • Ansel_XPPublisher
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Horde_Widget_ImageFaces:: class to display a widget containing mini
  4:  * thumbnails of faces in the image.
  5:  *
  6:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * @author Duck <duck@obala.net>
  9:  * @author Michael J. Rubinsky <mrubinsk@horde.org>
 10:  *
 11:  * @package Ansel
 12:  */
 13: class Ansel_Widget_ImageFaces extends Ansel_Widget_Base
 14: {
 15:     /**
 16:      * The views this Widget may appear in
 17:      *
 18:      * @var array
 19:      */
 20:     private $_supported_views = array('Image');
 21: 
 22:     /**
 23:      * Constructor
 24:      *
 25:      * @param array $params  Any parameters for this widget
 26:      * @return Ansel_Widget_ImageFaces
 27:      */
 28:     public function __construct($params)
 29:     {
 30:         parent::__construct($params);
 31:         $this->_title = _("People in this photo");
 32:     }
 33: 
 34:     /**
 35:      * Return the HTML representing this widget.
 36:      *
 37:      * @return string  The HTML for this widget.
 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:      * Helper function for getting faces for this image.
 51:      *
 52:      * @return string  The HTML
 53:      */
 54:     protected function _getFaceNames()
 55:     {
 56:         $faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
 57: 
 58:         // Check for existing faces for this image.
 59:         $html = '';
 60:         $images = $faces->getImageFacesData($this->_view->resource->id, true);
 61: 
 62:         // Generate the top ajax action links and attach the edit actions. Falls
 63:         // back on going to the find all faces in gallery page if no js...
 64:         // although, currently, *that* page requires js as well so...
 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:             // Attach the ajax edit actions
 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:         // Build the main content area of the widget
 87:         $html .= '<div id="faces_widget_content">';
 88:         if (empty($images)) {
 89:             return $html .= '<br /><em>' . _("No faces found") . '</em></div>';
 90:         }
 91: 
 92:         // Start the image overlay node to show the face rectangles
 93:         $faces_html = '<div id="faces-on-image">';
 94: 
 95:         // Iterate over all the found faces and build the tiles.
 96:         foreach ($images as $face) {
 97: 
 98:             // Get the tile for this face
 99:             $html .= Ansel_Faces::getFaceTile($face);
100: 
101:             // Build the overlay for the image
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:             // Attach events to the face tile for showing the overlay
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:         // Close up the nodes
120:         $html .= $faces_html . '</div></div>';
121: 
122:         // Include the needed javascript
123:         Horde::addScriptFile('imagefaces.js', 'ansel');
124: 
125:         return $html;
126:     }
127: 
128: }
129: 
API documentation generated by ApiGen