Ejemplo n.º 1
0
 /**
  * Deletes photo
  *
  * @param int $id
  * @return int
  */
 public function deletePhoto($id)
 {
     /** @var $photo PHOTO_BOL_Photo */
     if (!$id || !($photo = $this->photoDao->findById($id))) {
         return false;
     }
     $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_BEFORE_PHOTO_DELETE, array('id' => $id));
     OW::getEventManager()->trigger($event);
     if ($this->photoDao->deleteById($id)) {
         BOL_CommentService::getInstance()->deleteEntityComments('photo_comments', $id);
         BOL_RateService::getInstance()->deleteEntityRates($id, 'photo_rates');
         BOL_TagService::getInstance()->deleteEntityTags($id, 'photo');
         // remove files
         $this->photoDao->removePhotoFile($id, $photo->hash, 'main');
         $this->photoDao->removePhotoFile($id, $photo->hash, 'preview');
         $this->photoDao->removePhotoFile($id, $photo->hash, 'original');
         $this->photoFeaturedDao->markUnfeatured($id);
         BOL_FlagService::getInstance()->deleteByTypeAndEntityId('photo', $id);
         OW::getEventManager()->trigger(new OW_Event('feed.delete_item', array('entityType' => 'photo_comments', 'entityId' => $id)));
         $this->cleanListCache();
         $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_DELETE, array('id' => $id));
         OW::getEventManager()->trigger($event);
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Deletes photo
  *
  * @param int $id
  * @return int
  */
 public function deletePhoto($id, $totalAlbum = FALSE)
 {
     if (!$id || !($photo = $this->photoDao->findById($id))) {
         return false;
     }
     if ($totalAlbum === FALSE) {
         $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_BEFORE_PHOTO_DELETE, array('id' => $id));
         OW::getEventManager()->trigger($event);
     }
     if ($this->photoDao->deleteById($id)) {
         BOL_CommentService::getInstance()->deleteEntityComments('photo_comments', $id);
         BOL_RateService::getInstance()->deleteEntityRates($id, 'photo_rates');
         BOL_TagService::getInstance()->deleteEntityTags($id, 'photo');
         $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_SMALL);
         $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_PREVIEW);
         $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_MAIN);
         $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_FULLSCREEN);
         $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_ORIGINAL);
         $this->photoFeaturedDao->markUnfeatured($id);
         BOL_FlagService::getInstance()->deleteByTypeAndEntityId(PHOTO_CLASS_ContentProvider::ENTITY_TYPE, $id);
         BOL_TagService::getInstance()->deleteEntityTags($id, PHOTO_BOL_PhotoDao::PHOTO_ENTITY_TYPE);
         $this->cleanListCache();
         OW::getEventManager()->trigger(new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_DELETE, array('id' => $id)));
         return TRUE;
     }
     return FALSE;
 }
Ejemplo n.º 3
0
 public function cropAlbumCover(PHOTO_BOL_PhotoAlbum $album, $coords, $viewSize, $photoId = 0)
 {
     if (!empty($photoId) && ($photo = $this->photoDao->findById($photoId)) !== NULL) {
         $path = $this->photoDao->getPhotoPath($photo->id, $photo->hash, 'main');
     } else {
         $path = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathByAlbumId($album->id);
     }
     $storage = OW::getStorage();
     $tmpPath = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(time(), TRUE) . '.jpg';
     $storage->copyFileToLocalFS($path, $tmpPath);
     if (($coverDto = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->findByAlbumId($album->id)) === NULL) {
         $coverDto = new PHOTO_BOL_PhotoAlbumCover();
         $coverDto->albumId = $album->id;
         PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto);
     }
     $oldCover = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto);
     $oldCoverOrig = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto);
     $coverDto->hash = uniqid();
     $coverDto->auto = 0;
     try {
         $image = new UTIL_Image($tmpPath);
         if ($image->getWidth() >= $coords['w'] && $coords['w'] > 0 && $image->getHeight() >= $coords['h'] && $coords['h'] > 0) {
             $width = $image->getWidth();
             $k = $width / $viewSize;
             $image->cropImage($coords['x'] * $k, $coords['y'] * $k, $coords['w'] * $k, $coords['h'] * $k);
         }
         $saveImage = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(time(), TRUE) . '.jpg';
         $image->saveImage($saveImage);
         $image->destroy();
         $storage->copyFile($saveImage, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto));
         $storage->copyFile($tmpPath, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto));
         $storage->removeFile($oldCover);
         $storage->removeFile($oldCoverOrig);
         @unlink($saveImage);
         @unlink($tmpPath);
         PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto);
     } catch (Exception $e) {
         return FALSE;
     }
     return array('cover' => PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverUrlForCoverEntity($coverDto), 'coverOrig' => PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigUrlForCoverEntity($coverDto));
 }