예제 #1
0
 /**
  * Delete a face from an image.
  */
 public function deleteFaces()
 {
     global $injector, $registry;
     $face_id = intval($this->vars->face_id);
     $image_id = intval($this->vars->image_id);
     $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('Access denied editing the photo.');
     }
     Ansel_Faces::delete($image, $face_id);
     return true;
 }
예제 #2
0
파일: Base.php 프로젝트: jubinpatel/horde
 /**
  * Look for and save faces in a picture, and optionally create the face
  * image.
  *
  * @param mixed $image Image Object/ID to check
  * @param boolen $create Create images or store data?
  *
  * @return array Faces found
  * @throws Horde_Exception_PermissionDenied
  * @throws Ansel_Exception
  */
 public function getFromPicture($image, $create = false)
 {
     // get image if ID is passed
     if (!$image instanceof Ansel_Image) {
         $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image);
         $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
         if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
             throw new Horde_Exception_PermissionDenied(_("Access denied editing the photo."));
         }
     }
     // Get the rectangles for any faces in this image.
     $faces = $this->getFaces($image);
     if (empty($faces)) {
         return array();
     }
     // Clean up any existing faces we may have had in this image.
     Ansel_Faces::delete($image);
     // Process faces
     $fids = array();
     foreach ($faces as $i => $rect) {
         // Store face id db
         $sql = 'INSERT INTO ansel_faces (image_id, gallery_id, face_x1, ' . ' face_y1, face_x2, face_y2)' . ' VALUES (?, ?, ?, ?, ?, ?)';
         $params = $this->_getParamsArray($image, $rect);
         try {
             $face_id = $GLOBALS['ansel_db']->insert($sql, $params);
         } catch (Horde_Db_Exception $e) {
             throw new Ansel_Exception($result);
         }
         if ($create) {
             $this->_createView($face_id, $image, $rect);
             // Clear any loaded views to save on memory usage.
             $image->reset();
             $this->saveSignature($image->id, $face_id);
         }
         $fids[$face_id] = '';
     }
     // Update gallery and image counts
     try {
         $GLOBALS['ansel_db']->update('UPDATE ansel_images SET image_faces = ' . count($fids) . ' WHERE image_id = ' . $image->id);
         $GLOBALS['ansel_db']->update('UPDATE ansel_shares ' . 'SET attribute_faces = attribute_faces + ' . count($fids) . ' WHERE share_id = ' . $image->gallery);
     } catch (Horde_Db_Exception $e) {
         throw new Ansel_Exception($e);
     }
     // Expire gallery cache
     if ($GLOBALS['conf']['ansel_cache']['usecache']) {
         $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
     }
     return $fids;
 }
예제 #3
0
파일: Date.php 프로젝트: 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;
 }