public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
public function __construct($albumId, $photoId = NULL, $userId = NULL) { parent::__construct(); if (empty($userId)) { $userId = OW::getUser()->getId(); } if (empty($userId) || ($album = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($albumId)) === null || ($album->userId != $userId || !OW::getUser()->isAuthorized('photo', 'view'))) { $this->setVisible(FALSE); return; } if ($photoId === NULL && !PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->isAlbumCoverExist($albumId)) { $this->setVisible(FALSE); return; } $storage = OW::getStorage(); if (empty($photoId)) { if ($storage instanceof BASE_CLASS_FileStorage) { $photoPath = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathByAlbumId($albumId); } else { $photoPath = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverUrlByAlbumId($albumId, true); } $info = getimagesize($photoPath); if ($info['0'] < 330 || $info['1'] < 330) { $this->assign('imgError', OW::getLanguage()->text('photo', 'to_small_cover_img')); return; } $this->assign('coverUrl', PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverUrlByAlbumId($albumId, TRUE)); } else { $photo = PHOTO_BOL_PhotoDao::getInstance()->findById($photoId); $this->assign('coverUrl', PHOTO_BOL_PhotoDao::getInstance()->getPhotoUrl($photo->id, $photo->hash, FALSE)); if (!empty($photo->dimension)) { $info = json_decode($photo->dimension, true); if ($info[PHOTO_BOL_PhotoService::TYPE_ORIGINAL]['0'] < 330 || $info[PHOTO_BOL_PhotoService::TYPE_ORIGINAL]['1'] < 330) { $this->assign('imgError', OW::getLanguage()->text('photo', 'to_small_cover_img')); return; } } else { if ($storage instanceof BASE_CLASS_FileStorage) { $photoPath = PHOTO_BOL_PhotoDao::getInstance()->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_ORIGINAL); } else { $photoPath = PHOTO_BOL_PhotoDao::getInstance()->getPhotoUrl($photo->id, $photo->hash, FALSE); } $info = getimagesize($photoPath); if ($info['0'] < 330 || $info['1'] < 330) { $this->assign('imgError', OW::getLanguage()->text('photo', 'to_small_cover_img')); return; } } } OW::getDocument()->addStyleSheet(OW::getPluginManager()->getPlugin('base')->getStaticCssUrl() . 'jquery.Jcrop.css'); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('base')->getStaticJsUrl() . 'jquery.Jcrop.js'); $form = new PHOTO_CLASS_MakeAlbumCover(); $form->getElement('albumId')->setValue($albumId); $form->getElement('photoId')->setValue($photoId); $this->addForm($form); }
$BOL_AvatarService_inst = BOL_AvatarService::getInstance(); $SKAPI_BOL_Service_inst = SKAPI_BOL_Service::getInstance(); $PHOTO_BOL_PhotoService_inst = PHOTO_BOL_PhotoService::getInstance(); $PHOTO_BOL_PhotoAlbumService = PHOTO_BOL_PhotoAlbumService::getInstance(); $PHOTO_BOL_PhotoTemporaryService = PHOTO_BOL_PhotoTemporaryService::getInstance(); $UserResetPassword = BOL_UserResetPasswordDao::getInstance(); $QuestionService = BOL_QuestionService::getInstance(); $AccountTypeToGenderService = SKADATE_BOL_AccountTypeToGenderService::getInstance(); $BOL_AuthorizationService = BOL_AuthorizationService::getInstance(); $BOL_UserOnlineDao = BOL_UserOnlineDao::getInstance(); $USEARCH_BOL_Service = USEARCH_BOL_Service::getInstance(); $BOL_SearchService = BOL_SearchService::getInstance(); $getPluginManager = OW::getPluginManager(); $CONTACTUS_BOL_Service = CONTACTUS_BOL_Service::getInstance(); $PHOTO_BOL_PhotoService = PHOTO_BOL_PhotoService::getInstance(); $PHOTO_BOL_PhotoAlbumCoverDao = PHOTO_BOL_PhotoAlbumCoverDao::getInstance(); $PHOTO_BOL_PhotoDao = PHOTO_BOL_PhotoDao::getInstance(); $getRouter = OW::getRouter(); $language = OW::getLanguage(); $getMailer = OW::getMailer(); $getConfig = OW::getConfig(); $getFeedback = OW::getFeedback(); $getEventManager = OW::getEventManager(); $getMailer = OW::getMailer(); $ow = OW_DB_PREFIX; $LanguageService = BOL_LanguageService::getInstance(); $OW_Language = OW_Language::getInstance(); $QUESTION_PRESENTATION_DATE = BOL_QuestionService::QUESTION_PRESENTATION_DATE; $QUESTION_PRESENTATION_RANGE = BOL_QuestionService::QUESTION_PRESENTATION_RANGE; $QUESTION_PRESENTATION_BIRTHDATE = BOL_QuestionService::QUESTION_PRESENTATION_BIRTHDATE; $QUESTION_PRESENTATION_AGE = BOL_QuestionService::QUESTION_PRESENTATION_AGE;
public function onAfterPhotoMove(OW_Event $event) { $params = $event->getParams(); if (empty($params['fromAlbum']) || empty($params['toAlbum'])) { return; } $fromAlbumId = (int) $params['fromAlbum']; $toAlbumId = (int) $params['toAlbum']; $coverDao = PHOTO_BOL_PhotoAlbumCoverDao::getInstance(); $fromCover = $coverDao->findByAlbumId($fromAlbumId); if ($fromCover === NULL || (int) $fromCover->auto) { $coverDao->deleteCoverByAlbumId($fromAlbumId); $this->photoService->createAlbumCover($fromAlbumId, array_reverse(PHOTO_BOL_PhotoDao::getInstance()->getAlbumAllPhotos($fromAlbumId))); } $toCover = $coverDao->findByAlbumId($toAlbumId); if ($toCover === NULL || (int) $toCover->auto) { $coverDao->deleteCoverByAlbumId($toAlbumId); $this->photoService->createAlbumCover($toAlbumId, array_reverse(PHOTO_BOL_PhotoDao::getInstance()->getAlbumAllPhotos($toAlbumId))); } }
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)); }
public function ajaxMoveToAlbum($params) { if (!OW::getRequest()->isAjax()) { exit(json_encode(array('result' => FALSE))); } $form = new PHOTO_CLASS_AlbumAddForm(); if ($form->isValid($params) && $form->process()) { $values = $form->getValues(); $album = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($values['from-album']); $userDto = BOL_UserService::getInstance()->findUserById($album->userId); return array('result' => TRUE, 'albumNameList' => $this->photoAlbumService->findAlbumNameListByUserId($userDto->id, array($album->id)), 'coverUrl' => PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverUrlByAlbumId($album->id), 'isHasCover' => PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->isAlbumCoverExist($album->id)); } else { $result = array('result' => FALSE); $errors = array_filter($form->getErrors(), 'count'); if (!empty($errors[key($errors)][0])) { $result['msg'] = $errors[key($errors)][0]; } return $result; } }
public function createAlbumCover($albumId, array $photos) { if (empty($albumId) || count($photos) === 0 || PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->isAlbumCoverExist($albumId)) { return FALSE; } foreach ($photos as $photo) { $path = $this->getPhotoPath($photo->id, $photo->hash, 'main'); $storage = OW::getStorage(); if (!$storage->fileExists($path)) { continue; } $tmpPathCrop = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(uniqid(), TRUE) . '.jpg'; $tmpPathOrig = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(uniqid(), TRUE) . '.jpg'; if (!$storage->copyFileToLocalFS($path, $tmpPathOrig)) { continue; } $info = getimagesize($tmpPathOrig); if ($info['0'] < 330 || $info['1'] < 330) { @unlink($tmpPathOrig); continue; } $coverDto = new PHOTO_BOL_PhotoAlbumCover(); $coverDto->albumId = $albumId; $coverDto->hash = uniqid(); PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto); $image = new UTIL_Image($tmpPathOrig); $left = $image->getWidth() / 2 - 165; $top = $image->getHeight() / 2 - 165; $image->cropImage($left, $top, 330, 330); $image->saveImage($tmpPathCrop); $image->destroy(); $storage->copyFile($tmpPathCrop, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto)); $storage->copyFile($tmpPathOrig, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto)); @unlink($tmpPathCrop); @unlink($tmpPathOrig); return TRUE; } return FALSE; }
public function getAlbumCoverUrl(OW_Event $event) { $params = $event->getParams(); $albumId = $params['albumId']; $coverDao = PHOTO_BOL_PhotoAlbumCoverDao::getInstance(); if (($coverDto = $coverDao->findByAlbumId($albumId)) === null) { if (($photo = $this->albumService->getLastPhotoByAlbumId($albumId)) === null) { $coverUrl = $coverDao->getAlbumCoverDefaultUrl(); } else { $coverUrl = $this->photoService->getPhotoUrlByType($photo->id, PHOTO_BOL_PhotoService::TYPE_MAIN, $photo->hash, !empty($photo->dimension) ? $photo->dimension : false); } $coverUrlOrig = $coverUrl; } else { $coverUrl = $coverDao->getAlbumCoverUrlForCoverEntity($coverDto); $coverUrlOrig = $coverDao->getAlbumCoverOrigUrlForCoverEntity($coverDto); } $event->setData(array('coverUrl' => $coverUrl, 'coverUrlOrig' => $coverUrlOrig)); return $event->getData(); }