Example #1
0
 /**
  * Return the HTML representing this widget.
  *
  * @return string  The HTML for this widget.
  */
 public function html()
 {
     if (!$GLOBALS['conf']['faces']['driver']) {
         return '';
     }
     $this->_faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
     $this->_owner = $this->_view->gallery->get('owner');
     try {
         $this->_count = $this->_faces->countOwnerFaces($this->_owner);
     } catch (Ansel_Exception $e) {
         Horde::log($e->getMessage(), 'ERR');
         $this->_count = 0;
     }
     if (empty($this->_count)) {
         return null;
     }
     $this->_title = Horde::url('faces/search/owner.php')->add('owner', $this->_owner)->link() . sprintf(_("People in galleries owned by %s (%d of %d)"), $this->_owner, min(12, $this->_count), number_format($this->_count)) . '</a>';
     $html = $this->_htmlBegin();
     $results = $this->_faces->ownerFaces($this->_owner, 0, 12, true);
     $html .= '<div style="display: block' . ';background:' . $this->_style->background . ';width:100%;max-height:300px;overflow:auto;" id="faces_widget_content" >';
     foreach ($results as $face) {
         $facename = htmlspecialchars($face['face_name']);
         $html .= '<a href="' . Ansel_Faces::getLink($face) . '" title="' . $facename . '">' . '<img src="' . $this->_faces->getFaceUrl($face['image_id'], $face['face_id'], 'mini') . '" style="padding-bottom: 5px; padding-left: 5px" alt="' . $facename . '" /></a>';
     }
     return $html . '</div>' . $this->_htmlEnd();
 }
Example #2
0
 /**
  */
 protected function _content()
 {
     $faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
     $results = $faces->allFaces(0, $this->_params['limit']);
     $html = '';
     foreach ($results as $face) {
         $facename = htmlspecialchars($face['face_name']);
         $html .= '<a href="' . Ansel_Faces::getLink($face) . '" title="' . $facename . '">' . '<img src="' . $faces->getFaceUrl($face['image_id'], $face['face_id']) . '" style="padding-bottom: 5px; padding-left: 5px" alt="' . $facename . '" /></a>';
     }
     return $html;
 }
Example #3
0
 /**
  * Helper function for getting faces for this gallery.
  *
  * @return string  The HTML
  */
 protected function _getFaceNames()
 {
     if ($this->_view->resource->get('faces') <= 0) {
         return '<div id="faces_widget_content"><br /><em>' . _("No faces found") . '</em></div>';
     }
     $faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
     // Check for existing faces for this gallery.
     $html = '<div style="display: block' . ';background:' . $this->_style->background . ';width:100%;max-height:300px;overflow:auto;" id="faces_widget_content" >';
     $images = $faces->getGalleryFaces($this->_view->resource->id);
     if ($this->_view->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
         $link_text = empty($images) ? _("Find faces") : _("Edit faces");
         $html .= Horde::url('faces/gallery.php')->add('gallery', $this->_view->gallery->id)->link(array('id' => 'edit_faces', 'class' => 'widget')) . $link_text . '</a>';
     }
     $faces_html = '<div id="faces-on-gallery">';
     // Iterate over all the found faces and build the tiles.
     shuffle($images);
     foreach ($images as $face) {
         // Get the tile for this face
         $html .= Ansel_Faces::getFaceTile($face);
     }
     // Close up the nodes
     $html .= '</div></div></div></div>';
     return $html;
 }
Example #4
0
 /**
  * Get face signature from an existing face image.
  *
  * @param integer $image_id Image ID face belongs to
  * @param integer $face_id Face ID to check
  *
  * @throws Ansel_Exception
  */
 function saveSignature($image_id, $face_id)
 {
     // can we get it?
     if (empty($GLOBALS['conf']['faces']['search']) || Horde_Util::loadExtension('libpuzzle') === false) {
         return;
     }
     // Ensure we have an on-disk file to read the signature from.
     $path = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->readFile(Ansel_Faces::getVFSPath($image_id) . '/faces', $face_id . Ansel_Faces::getExtension());
     $signature = puzzle_fill_cvec_from_file($path);
     if (empty($signature)) {
         return;
     }
     // save compressed signature
     $sql = 'UPDATE ansel_faces SET face_signature = ? WHERE face_id = ?';
     $params = array(new Horde_Db_Value_Binary(puzzle_compress_cvec($signature)), $face_id);
     try {
         $GLOBALS['ansel_db']->update($sql, $params);
     } catch (Horde_Db_Exception $e) {
         throw new Ansel_Exception($result);
     }
     // create index
     $word_len = $GLOBALS['conf']['faces']['search'];
     $str_len = strlen($signature);
     $GLOBALS['ansel_db']->delete('DELETE FROM ansel_faces_index WHERE face_id = ' . $face_id);
     $q = 'INSERT INTO ansel_faces_index (face_id, index_position, index_part) VALUES (?, ?, ?)';
     $c = $str_len - $word_len;
     for ($i = 0; $i <= $c; $i++) {
         $data = array($face_id, $i, new Horde_Db_Value_Binary(substr($signature, $i, $word_len)));
         try {
             $GLOBALS['ansel_db']->insert($q, $data);
         } catch (Horde_Db_Exception $e) {
             throw new Ansel_Exception($e);
         }
     }
 }
Example #5
0
<?php

/**
 * Process an single image (to be called by ajax)
 *
 * Copyright 2008-2015 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author Duck <*****@*****.**>
 */
require_once 'tabs.php';
/* check if image exists */
$tmp = Horde::getTempDir();
$path = $tmp . '/search_face_' . $registry->getAuth() . Ansel_Faces::getExtension();
if (file_exists($path) !== true) {
    $notification->push(_("You must upload the search photo first"));
    Horde::url('faces/search/image.php')->redirect();
}
$title = _("Create a new face");
$x1 = 0;
$y1 = 0;
$x2 = 0;
$y2 = 0;
try {
    $faces = $faces->getFaces($path);
} catch (Ansel_Exception $e) {
    exit;
}
if (count($faces) > 1) {
Example #6
0
}
$title = _("Tell us who is in this photo");
$vars = Horde_Variables::getDefaultVariables();
$form = new Horde_Form($vars, $title);
$form->addHidden('', 'face', 'int', true);
$form->addVariable(_("Person"), 'person', 'text', true);
$form->setButtons($title);
if ($form->validate()) {
    if (Horde_Util::getFormData('submitbutton') == _("Cancel")) {
        $notification->push(_("Action was cancelled."), 'horde.warning');
    } else {
        $report = Ansel_Report::factory();
        $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($face['gallery_id']);
        $face_link = Horde::url('faces/custom.php', true)->add(array('name' => $vars->get('person'), 'face' => $face_id, 'image' => $face['image_id']))->setRaw(true);
        $title = _("I know who is on one of your photos");
        $body = _("Gallery Name") . ': ' . $gallery->get('name') . "\n" . _("Gallery Description") . ': ' . $gallery->get('desc') . "\n\n" . $title . "\n" . _("Person") . ': ' . $vars->get('person') . "\n" . _("Face") . ': ' . $face_link;
        $report->setTitle($title);
        try {
            $result = $report->report($body, $gallery->get('owner'));
            $notification->push(_("The owner of the photo, who will delegate the face name, was notified."), 'horde.success');
        } catch (Ansel_Exception $e) {
            $notification->push(_("Face name was not reported.") . ' ' . $e->getMessage(), 'horde.error');
        }
    }
    Ansel_Faces::getLink($face)->redirect();
    exit;
}
$page_output->header(array('title' => $title));
$notification->notify(array('listeners' => 'status'));
$form->renderActive(null, null, null, 'post');
$page_output->footer();
Example #7
0
 /**
  * Sets a name in an image.
  */
 public function setFaceName()
 {
     global $injector, $registry;
     $face_id = intval($this->vars->face_id);
     $image_id = intval($this->vars->image_id);
     $name = $this->vars->face_name;
     $storage = $injector->getInstance('Ansel_Storage');
     $image = $storage->getImage($image_id);
     $gallery = $storage->getGallery($image->gallery);
     if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
         throw new Ansel_Exception('You are not allowed to edit this photo');
     }
     $injector->getInstance('Ansel_Faces')->setName($face_id, $name);
     $results = new stdClass();
     $results->results = Ansel_Faces::getFaceTile($face_id);
     return new Horde_Core_Ajax_Response($results);
 }
Example #8
0
  <?php 
if (empty($this->images)) {
    ?>
    <br /><em><?php 
    echo _("No faces found");
    ?>
</em>
  <?php 
}
?>
  <div id="faces-on-image">
    <?php 
foreach ($this->images as $face) {
    ?>
      <?php 
    echo Ansel_Faces::getFaceTile($face);
    ?>
      <div id="facediv<?php 
    echo $face['face_id'];
    ?>
" class="face-div" style="width:<?php 
    echo $face['face_x2'] - $face['face_x1'];
    ?>
px;margin-left:<?php 
    echo $face['face_x1'];
    ?>
px;height:<?php 
    echo $face['face_y2'] - $face['face_y1'];
    ?>
px;margin-top:<?php 
    echo $face['face_y1'];
Example #9
0
<?php

/**
 * Process an single image (to be called by ajax)
 *
 * Copyright 2008-2014 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author Duck <*****@*****.**>
 */
require_once __DIR__ . '/../../lib/Application.php';
Horde_Registry::appInit('ansel');
$thumb = Horde_Util::getGet('thumb');
$tmp = Horde::getTempDir();
$path = $tmp . '/search_face_' . ($thumb ? 'thumb_' : '') . $registry->getAuth() . Ansel_Faces::getExtension();
header('Content-type: image/' . $conf['image']['type']);
readfile($path);
Example #10
0
File: Date.php Project: horde/horde
 /**
  * Remove an image from this gallery. Note that the image might actually
  * belong to a subgallery of this gallery since we are viewing by date.
  * Need to take care of updating correct subgallery's image count etc...
  *
  * @param mixed $image      An image_id or Ansel_Image object to delete.
  * @param boolean $isStack  Image is a stack image (doesn't update count).
  *
  * @return boolean
  * @throws Horde_Exception_NotFound, Ansel_Exception
  */
 public function removeImage($image, $isStack)
 {
     // Make sure $image is an Ansel_Image; if not, try loading it.
     if (!$image instanceof Ansel_Image) {
         $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image);
     }
     // If image is a stack image, $gallery will be negative.
     $image_gallery = abs($image->gallery);
     // Make sure the image is in this gallery.
     if ($image_gallery != $this->_gallery->id) {
         $this->_loadSubGalleries();
         if (!in_array($image_gallery, $this->_subGalleries)) {
             throw new Horde_Exception_NotFound(_("Image not found in gallery."));
         }
     }
     /* Change gallery info. */
     if ($this->_gallery->get('default') == $image->id) {
         $this->_gallery->set('default', null);
         $this->_gallery->set('default_type', 'auto');
     }
     /* Delete cached files from VFS. */
     $image->deleteCache();
     /* Delete original image from VFS. */
     try {
         $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->deleteFile($image->getVFSPath('full'), $image->getVFSName('full'));
     } catch (Horde_Vfs_Exception $e) {
     }
     /* Delete from storage */
     $GLOBALS['injector']->getInstance('Ansel_Storage')->removeImage($image->id);
     if (!$isStack) {
         $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image_gallery)->updateImageCount(1, false);
     }
     /* Update the modified flag if we are not a stack image */
     if (!$isStack) {
         $this->_gallery->set('last_modified', time());
     }
     /* Save all gallery changes */
     $this->_gallery->save();
     /* Clear the image's tags */
     $image->setTags(array());
     /* Clear the image's faces */
     if ($image->facesCount) {
         Ansel_Faces::delete($image);
     }
     /* Clear any comments */
     if (($GLOBALS['conf']['comments']['allow'] == 'all' || $GLOBALS['conf']['comments']['allow'] == 'authenticated' && $GLOBALS['registry']->getAuth()) && $GLOBALS['registry']->hasMethod('forums/deleteForum')) {
         try {
             $GLOBALS['registry']->call('forums/deleteForum', array('ansel', $image->id));
         } catch (Horde_Exception $e) {
             Horde::log($e, 'ERR');
             return false;
         }
     }
     return true;
 }
Example #11
0
 * @author Duck <*****@*****.**>
 */
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('ansel');
$face_id = Horde_Util::getFormData('face');
$faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
// Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file
// header
if ($conf['vfs']['src'] == 'sendfile') {
    $face = $faces->getFaceById($face_id);
    // Make sure the view exists
    if (!$faces->viewExists($face['image_id'], $face_id, true)) {
        Horde::log(sprintf('Unable to locate or create face_id %u.', $face_id));
        exit;
    }
    // We definitely have an image for the face.
    try {
        $filename = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->readFile(Ansel_Faces::getVFSPath($face['image_id']) . 'faces', $face_id . Ansel_Faces::getExtension());
    } catch (Horde_Vfs_Exception $e) {
        Horde::log($e, 'ERR');
        exit;
    }
    header('Content-type: image/' . $GLOBALS['conf']['image']['type']);
    header('X-LIGHTTPD-send-file: ' . $filename);
    header('X-Sendfile: ' . $filename);
    exit;
}
// Run it through PHP
$img = $faces->getFaceImageObject($face_id);
header('Content-type: image/' . $GLOBALS['conf']['image']['type']);
echo $img->raw();