public function moveTemporaryPhoto($tmpId, $albumId, $desc, $tag) { $photoService = PHOTO_BOL_PhotoService::getInstance(); /** @var $tmp PHOTO_BOL_PhotoTemporary */ $tmp = $this->photoTemporaryDao->findById($tmpId); if (!$tmp) { return false; } $album = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($albumId); $privacy = OW::getEventManager()->call('plugin.privacy.get_privacy', array('ownerId' => $album->userId, 'action' => 'photo_view_album')); $photo = new PHOTO_BOL_Photo(); $photo->description = htmlspecialchars($desc); $photo->albumId = $albumId; $photo->addDatetime = time(); $photo->status = 'approved'; $photo->hasFullsize = $tmp->hasFullsize; $photo->privacy = mb_strlen($privacy) ? $privacy : 'everybody'; $photo->hash = uniqid(); $photo->uploadKey = $photoService->getPhotoUploadKey($albumId); if ($photoService->addPhoto($photo)) { $storage = OW::getStorage(); $main = $photoService->getPhotoPath($photo->id, $photo->hash); $mainTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmp->id, 2); $storage->copyFile($mainTmp, $main); @unlink($mainTmp); $preview = $photoService->getPhotoPath($photo->id, $photo->hash, 'preview'); $previewTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmp->id, 1); $storage->copyFile($previewTmp, $preview); @unlink($previewTmp); if ($photo->hasFullsize) { $original = $photoService->getPhotoPath($photo->id, $photo->hash, 'original'); $originalTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmp->id, 3); $storage->copyFile($originalTmp, $original); @unlink($originalTmp); } $this->photoTemporaryDao->deleteById($tmp->id); if (mb_strlen($tag)) { BOL_TagService::getInstance()->updateEntityTags($photo->id, 'photo', explode(',', $tag)); } return $photo; } return false; }
public function addTemporaryPhoto($source, $userId, $order = 0) { if (!file_exists($source) || !$userId) { return FALSE; } $tmpPhoto = new PHOTO_BOL_PhotoTemporary(); $tmpPhoto->userId = $userId; $tmpPhoto->addDatetime = time(); $tmpPhoto->hasFullsize = 0; $tmpPhoto->order = $order; $this->photoTemporaryDao->save($tmpPhoto); try { /* * Beter performance but less quolity - small size images is slightly clouded * $fullscreenTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 5); $originalTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 3); $mainTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 2); $previewTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 1); $smallTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 4); $image = new UTIL_Image($source); $storeFullSize = OW::getConfig()->getValue('photo', 'store_fullsize'); if ( $storeFullSize ) { $image->resizeImage(PHOTO_BOL_PhotoService::DIM_FULLSCREEN_WIDTH, PHOTO_BOL_PhotoService::DIM_FULLSCREEN_HEIGHT) ->orientateImage() ->saveImage($fullscreenTmp); $tmpPhoto->hasFullsize = 1; } $image->resizeImage(PHOTO_BOL_PhotoService::DIM_ORIGINAL_WIDTH, PHOTO_BOL_PhotoService::DIM_ORIGINAL_HEIGHT); if ( !$storeFullSize ) { $image->orientateImage(); } $image->saveImage($originalTmp) ->resizeImage(PHOTO_BOL_PhotoService::DIM_MAIN_WIDTH, PHOTO_BOL_PhotoService::DIM_MAIN_HEIGHT) ->saveImage($mainTmp) ->resizeImage(PHOTO_BOL_PhotoService::DIM_PREVIEW_WIDTH, PHOTO_BOL_PhotoService::DIM_PREVIEW_HEIGHT) ->saveImage($previewTmp) ->resizeImage(PHOTO_BOL_PhotoService::DIM_SMALL_WIDTH, PHOTO_BOL_PhotoService::DIM_SMALL_HEIGHT, TRUE) ->saveImage($smallTmp) ->destroy(); $this->photoTemporaryDao->save($tmpPhoto); */ $smallTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 4); $smallImg = new UTIL_Image($source); $smallImg->resizeImage(PHOTO_BOL_PhotoService::DIM_SMALL_WIDTH, PHOTO_BOL_PhotoService::DIM_SMALL_HEIGHT, TRUE)->orientateImage()->saveImage($smallTmp)->destroy(); $previewTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 1); $previewImage = new UTIL_Image($source); $previewImage->resizeImage(PHOTO_BOL_PhotoService::DIM_PREVIEW_WIDTH, PHOTO_BOL_PhotoService::DIM_PREVIEW_HEIGHT)->orientateImage()->saveImage($previewTmp)->destroy(); $mainTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 2); $main = new UTIL_Image($source); $mainImage = $main->resizeImage(PHOTO_BOL_PhotoService::DIM_MAIN_WIDTH, PHOTO_BOL_PhotoService::DIM_MAIN_HEIGHT)->orientateImage()->saveImage($mainTmp); $mainImageResized = $mainImage->imageResized(); $mainImage->destroy(); $originalTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 3); $originalImage = new UTIL_Image($source); $originalImage->resizeImage(PHOTO_BOL_PhotoService::DIM_ORIGINAL_WIDTH, PHOTO_BOL_PhotoService::DIM_ORIGINAL_HEIGHT)->orientateImage()->saveImage($originalTmp)->destroy(); if ($mainImageResized && (bool) OW::getConfig()->getValue('photo', 'store_fullsize')) { $fullscreenTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 5); $fullscreen = new UTIL_Image($source); $fullscreen->resizeImage(PHOTO_BOL_PhotoService::DIM_FULLSCREEN_WIDTH, PHOTO_BOL_PhotoService::DIM_FULLSCREEN_HEIGHT)->orientateImage()->saveImage($fullscreenTmp)->destroy(); $tmpPhoto->hasFullsize = 1; } $this->photoTemporaryDao->save($tmpPhoto); } catch (WideImage_Exception $e) { $this->photoTemporaryDao->deleteById($tmpPhoto->id); return FALSE; } return $tmpPhoto->id; }