Esempio n. 1
0
 /**
  * Deletes photo
  *
  * @param array $params
  * @throws Redirect404Exception
  * @return array
  */
 public function ajaxDeletePhoto(array $params)
 {
     $photoId = $params['photoId'];
     $photo = $this->photoService->findPhotoById($photoId);
     $return = array();
     if ($photo) {
         $ownerId = $this->photoService->findPhotoOwner($photoId);
         $isOwner = OW::getUser()->isAuthorized('photo', 'upload', $ownerId);
         $isModerator = OW::getUser()->isAuthorized('photo');
         if (!$isOwner && !$isModerator) {
             throw new Redirect404Exception();
         }
         $album = $this->photoAlbumService->findAlbumById($photo->albumId);
         $delResult = $this->photoService->deletePhoto($photoId);
         if ($delResult) {
             $photosInAlbum = (int) $this->photoAlbumService->countAlbumPhotos($photo->albumId);
             if ($photosInAlbum == 0) {
                 $url = OW_Router::getInstance()->urlForRoute('photo_user_albums', array('user' => BOL_UserService::getInstance()->getUserName($album->userId)));
                 $this->photoAlbumService->deleteAlbum($photo->albumId);
             } else {
                 $url = OW_Router::getInstance()->urlForRoute('photo_user_album', array('user' => BOL_UserService::getInstance()->getUserName($album->userId), 'album' => $photo->albumId));
             }
             $return = array('result' => true, 'msg' => OW::getLanguage()->text('photo', 'photo_deleted'), 'url' => $url);
         } else {
             $return = array('result' => false, 'error' => OW::getLanguage()->text('photo', 'photo_not_deleted'));
         }
     }
     return $return;
 }
Esempio n. 2
0
 public function view(array $params)
 {
     if (!isset($params['id']) || !($photoId = (int) $params['id'])) {
         throw new Redirect404Exception();
     }
     $lang = OW::getLanguage();
     $photo = $this->photoService->findPhotoById($photoId);
     if (!$photo) {
         throw new Redirect404Exception();
     }
     $album = $this->photoAlbumService->findAlbumById($photo->albumId);
     $this->assign('album', $album);
     $ownerName = BOL_UserService::getInstance()->getUserName($album->userId);
     $albumUrl = OW::getRouter()->urlForRoute('photo_user_album', array('album' => $album->id, 'user' => $ownerName));
     $this->assign('albumUrl', $albumUrl);
     // is owner
     $contentOwner = $this->photoService->findPhotoOwner($photo->id);
     $userId = OW::getUser()->getId();
     $ownerMode = $contentOwner == $userId;
     $this->assign('ownerMode', $ownerMode);
     // is moderator
     $modPermissions = OW::getUser()->isAuthorized('photo');
     $this->assign('moderatorMode', $modPermissions);
     $this->assign('url', $this->photoService->getPhotoUrl($photo->id, false, $photo->hash));
     if (!$ownerMode && !$modPermissions && !OW::getUser()->isAuthorized('photo', 'view')) {
         $status = BOL_AuthorizationService::getInstance()->getActionStatus('photo', 'view');
         $this->assign('authError', $status['msg']);
         return;
     }
     // permissions check
     if (!$ownerMode && !$modPermissions) {
         $privacyParams = array('action' => 'photo_view_album', 'ownerId' => $contentOwner, 'viewerId' => $userId);
         $event = new OW_Event('privacy_check_permission', $privacyParams);
         OW::getEventManager()->trigger($event);
     }
     $photo->description = UTIL_HtmlTag::autoLink($photo->description);
     $this->assign('photo', $photo);
     $fullsizeUrl = (int) OW::getConfig()->getValue('photo', 'store_fullsize') && $photo->hasFullsize ? $this->photoService->getPhotoFullsizeUrl($photo->id, $photo->hash) : null;
     $this->assign('fullsizeUrl', $fullsizeUrl);
     $this->assign('nextPhoto', $this->photoService->getNextPhotoId($photo->albumId, $photo->id));
     $this->assign('previousPhoto', $this->photoService->getPreviousPhotoId($photo->albumId, $photo->id));
     $photoCount = $this->photoAlbumService->countAlbumPhotos($photo->albumId);
     $this->assign('photoCount', $photoCount);
     $photoIndex = $this->photoService->getPhotoIndex($photo->albumId, $photo->id);
     $this->assign('photoIndex', $photoIndex);
     $avatar = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($contentOwner), true, true, true, false);
     $this->assign('avatar', $avatar[$contentOwner]);
     $cmtParams = new BASE_CommentsParams('photo', 'photo_comments');
     $cmtParams->setEntityId($photo->id);
     $cmtParams->setOwnerId($contentOwner);
     $cmtParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_BOTTOM_FORM_WITH_FULL_LIST);
     $photoCmts = new BASE_MCMP_Comments($cmtParams);
     $this->addComponent('comments', $photoCmts);
     OW::getDocument()->setHeading($album->name);
     $description = strip_tags($photo->description);
     $description = mb_strlen($description) ? $description : $photo->id;
     OW::getDocument()->setTitle($lang->text('photo', 'meta_title_photo_view', array('title' => $description)));
 }
Esempio n. 3
0
 public function onBeforePhotoDelete(OW_Event $event)
 {
     $params = $event->getParams();
     $photoId = $params['id'];
     if ($photoId) {
         $photo = $this->photoService->findPhotoById($photoId);
         $album = $this->albumService->findAlbumById($photo->albumId);
         if ($photo->uploadKey) {
             $remainingList = $this->photoService->getPhotoListByUploadKey($photo->uploadKey, array($photo->id));
             $this->photoService->triggerNewsfeedEventOnMultiplePhotosAdd($remainingList, $album->userId, $album);
         }
     }
 }
Esempio n. 4
0
 public function download(array $params)
 {
     $config = OW::getConfig();
     $canDownload = $config->getValue('gphotoviewer', 'can_users_to_download_photos');
     if (!$canDownload) {
         throw new Redirect404Exception();
     }
     if (!isset($params['id']) || !($photoId = (int) $params['id'])) {
         throw new Redirect404Exception();
     }
     $photo = $this->photoService->findPhotoById($photoId);
     if (!$photo) {
         throw new Redirect404Exception();
     }
     $canView = true;
     if (!$ownerMode && !$modPermissions && !OW::getUser()->isAuthorized('photo', 'view')) {
         $canView = false;
         throw new Redirect404Exception();
     }
     if ((int) BOL_PluginService::getInstance()->findPluginByKey('photo')->build > 6272) {
         $url = $this->photoService->getPhotoPath($photo->id, $photo->hash);
     } else {
         $url = $this->photoService->getPhotoPath($photo->id);
     }
     if (file_exists($url) && is_readable($url)) {
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename=' . basename($url));
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . filesize($url));
         ob_clean();
         flush();
         readfile($url);
         exit;
     } else {
         throw new Redirect404Exception();
     }
     exit;
 }
Esempio n. 5
0
 /**
  * Class constructor
  *
  * @param string $listType
  * @param int $count
  * @param string $tag
  */
 public function __construct(array $params)
 {
     parent::__construct();
     $photoId = $params['photoId'];
     $config = OW::getConfig();
     $lang = OW::getLanguage();
     $this->photoService = PHOTO_BOL_PhotoService::getInstance();
     $this->photoAlbumService = PHOTO_BOL_PhotoAlbumService::getInstance();
     $photo = $this->photoService->findPhotoById($photoId);
     $album = $this->photoAlbumService->findAlbumById($photo->albumId);
     $this->assign('album', $album);
     // is owner
     $contentOwner = $this->photoService->findPhotoOwner($photo->id);
     $userId = OW::getUser()->getId();
     $ownerMode = $contentOwner == $userId;
     $this->assign('ownerMode', $ownerMode);
     // is moderator
     $modPermissions = OW::getUser()->isAuthorized('photo');
     $this->assign('moderatorMode', $modPermissions);
     $canView = true;
     if (!$ownerMode && !$modPermissions && !OW::getUser()->isAuthorized('photo', 'view')) {
         $canView = false;
     }
     $this->assign('canView', $canView);
     $cmtParams = new BASE_CommentsParams('photo', 'photo_comments');
     $cmtParams->setEntityId($photo->id);
     $cmtParams->setOwnerId($contentOwner);
     $cmtParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_BOTTOM_FORM_WITH_FULL_LIST);
     $photoCmts = new BASE_CMP_Comments($cmtParams);
     $this->addComponent('comments', $photoCmts);
     $photoRates = new BASE_CMP_Rate('photo', 'photo_rates', $photo->id, $contentOwner);
     $this->addComponent('rate', $photoRates);
     $photoTags = new BASE_CMP_EntityTagCloud('photo');
     $photoTags->setEntityId($photo->id);
     $photoTags->setRouteName('view_tagged_photo_list');
     $this->addComponent('tags', $photoTags);
     $description = $photo->description;
     $photo->description = UTIL_HtmlTag::autoLink($photo->description);
     $this->assign('photo', $photo);
     $this->assign('url', $this->photoService->getPhotoUrl($photo->id, false, $photo->hash));
     $this->assign('ownerName', BOL_UserService::getInstance()->getUserName($album->userId));
     $is_featured = PHOTO_BOL_PhotoFeaturedService::getInstance()->isFeatured($photo->id);
     if ((int) $config->getValue('photo', 'store_fullsize') && $photo->hasFullsize) {
         $this->assign('fullsizeUrl', $this->photoService->getPhotoFullsizeUrl($photo->id, $photo->hash));
     } else {
         $this->assign('fullsizeUrl', null);
     }
     $action = new BASE_ContextAction();
     $action->setKey('photo-moderate');
     $context = new BASE_CMP_ContextAction();
     $context->addAction($action);
     $contextEvent = new BASE_CLASS_EventCollector('photo.collect_photo_context_actions', array('photoId' => $photoId, 'photoDto' => $photo));
     OW::getEventManager()->trigger($contextEvent);
     foreach ($contextEvent->getData() as $contextAction) {
         $action = new BASE_ContextAction();
         $action->setKey(empty($contextAction['key']) ? uniqid() : $contextAction['key']);
         $action->setParentKey('photo-moderate');
         $action->setLabel($contextAction['label']);
         if (!empty($contextAction['id'])) {
             $action->setId($contextAction['id']);
         }
         if (!empty($contextAction['order'])) {
             $action->setOrder($contextAction['order']);
         }
         if (!empty($contextAction['class'])) {
             $action->setClass($contextAction['class']);
         }
         if (!empty($contextAction['url'])) {
             $action->setUrl($contextAction['url']);
         }
         $attributes = empty($contextAction['attributes']) ? array() : $contextAction['attributes'];
         foreach ($attributes as $key => $value) {
             $action->addAttribute($key, $value);
         }
         $context->addAction($action);
     }
     if ($userId && !$ownerMode) {
         $action = new BASE_ContextAction();
         $action->setKey('flag');
         $action->setParentKey('photo-moderate');
         $action->setLabel($lang->text('base', 'flag'));
         $action->setId('btn-photo-flag');
         $action->addAttribute('rel', $photoId);
         $action->addAttribute('url', OW::getRouter()->urlForRoute('view_photo', array('id' => $photo->id)));
         $context->addAction($action);
     }
     if ($ownerMode || $modPermissions) {
         $action = new BASE_ContextAction();
         $action->setKey('edit');
         $action->setParentKey('photo-moderate');
         $action->setLabel($lang->text('base', 'edit'));
         $action->setId('btn-photo-edit');
         $action->addAttribute('rel', $photoId);
         $context->addAction($action);
         $action = new BASE_ContextAction();
         $action->setKey('delete');
         $action->setParentKey('photo-moderate');
         $action->setLabel($lang->text('base', 'delete'));
         $action->setId('photo-delete');
         $action->addAttribute('rel', $photoId);
         $context->addAction($action);
     }
     if ($modPermissions) {
         if ($is_featured) {
             $action = new BASE_ContextAction();
             $action->setKey('unmark-featured');
             $action->setParentKey('photo-moderate');
             $action->setLabel($lang->text('photo', 'remove_from_featured'));
             $action->setId('photo-mark-featured');
             $action->addAttribute('rel', 'remove_from_featured');
             $action->addAttribute('photo-id', $photoId);
             $context->addAction($action);
         } else {
             $action = new BASE_ContextAction();
             $action->setKey('mark-featured');
             $action->setParentKey('photo-moderate');
             $action->setLabel($lang->text('photo', 'mark_featured'));
             $action->setId('photo-mark-featured');
             $action->addAttribute('rel', 'mark_featured');
             $action->addAttribute('photo-id', $photoId);
             $context->addAction($action);
         }
     }
     $this->addComponent('contextAction', $context);
     $nextPhoto = $this->photoService->getNextPhoto($photo->albumId, $photo->id);
     $this->assign('nextPhoto', $nextPhoto);
     $previousPhoto = $this->photoService->getPreviousPhoto($photo->albumId, $photo->id);
     $this->assign('previousPhoto', $previousPhoto);
     $photoCount = $this->photoAlbumService->countAlbumPhotos($photo->albumId);
     $this->assign('photoCount', $photoCount);
     $photoIndex = $this->photoService->getPhotoIndex($photo->albumId, $photo->id);
     $this->assign('photoIndex', $photoIndex);
     $avatar = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($contentOwner), true, true, true, false);
     $this->assign('avatar', $avatar[$contentOwner]);
 }
Esempio n. 6
0
 public function getPhotoForAvatar(OW_Event $e)
 {
     $params = $e->getParams();
     if ($params['entityType'] == 'photo_album') {
         $id = $params['id'];
         $photo = $this->photoService->findPhotoById($id);
         if ($photo) {
             $type = (bool) $photo->hasFullsize ? PHOTO_BOL_PhotoService::TYPE_ORIGINAL : PHOTO_BOL_PhotoService::TYPE_MAIN;
             $data = array('url' => $this->photoService->getPhotoUrlByType($photo->id, $type, $photo->hash, $photo->dimension), 'path' => $this->photoService->getPhotoPath($photo->id, $photo->hash, $type));
             $e->setData($data);
             return $data;
         }
     }
 }
Esempio n. 7
0
    public function photo(array $params = null)
    {
        if (!OW::getUser()->isAuthenticated()) {
            throw new AuthenticateException();
        }
        $language = OW::getLanguage();
        if (!OW::getUser()->isAuthorized('photo', 'upload')) {
            $status = BOL_AuthorizationService::getInstance()->getActionStatus('photo', 'upload');
            $this->assign('auth_msg', $status['msg']);
            return;
        }
        $config = OW::getConfig();
        $userQuota = (int) $config->getValue('photo', 'user_quota');
        $userId = OW::getUser()->getId();
        if (!($this->photoService->countUserPhotos($userId) <= $userQuota)) {
            $this->assign('auth_msg', $language->text('photo', 'quota_exceeded', array('limit' => $userQuota)));
        } else {
            $accepted = floatval($config->getValue('photo', 'accepted_filesize') * 1024 * 1024);
            $this->assign('auth_msg', null);
            $form = new PHOTO_MCLASS_UploadForm();
            $this->addForm($form);
            $photoAlbumService = PHOTO_BOL_PhotoAlbumService::getInstance();
            $albums = $photoAlbumService->findUserAlbumList($userId, 1, 100);
            $this->assign('albums', $albums);
            if (!empty($params['album']) && (int) $params['album']) {
                $albumId = (int) $params['album'];
                $uploadToAlbum = $photoAlbumService->findAlbumById($albumId);
                if (!$uploadToAlbum || $uploadToAlbum->userId != $userId) {
                    $this->redirect(OW::getRouter()->urlForRoute('photo_upload'));
                }
                $form->getElement('album')->setValue($uploadToAlbum->name);
            }
            if ($albums) {
                $script = '$("#album_select").change(function(event){
                    $("#album_input").val($(this).val());
                });';
                OW::getDocument()->addOnloadScript($script);
            }
            $script = '$("#upload-file-field").change(function(){
                var img = $("#photo-file-prevew");
                var name = $(".owm_upload_img_name_label span");

                img.hide();
                name.text("");

                if (!this.files || !this.files[0]) return;

                if ( window.FileReader ) {
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        img.show().attr("src", e.target.result);
                    }
                    reader.readAsDataURL(this.files[0]);
                } else {
                    name.text(this.files[0].name);
                }
                $(".owm_upload_photo_browse_wrap").addClass("owm_upload_photo_attach_wrap");
            });';
            OW::getDocument()->addOnloadScript($script);
            if (OW::getRequest()->isPost()) {
                $form->isValid($_POST);
                $values = $form->getValues();
                // Delete old temporary photos
                $tmpPhotoService = PHOTO_BOL_PhotoTemporaryService::getInstance();
                $photoService = PHOTO_BOL_PhotoService::getInstance();
                $file = $_FILES['photo'];
                $tmpPhotoService->deleteUserTemporaryPhotos($userId);
                if (strlen($file['tmp_name'])) {
                    if (!UTIL_File::validateImage($file['name']) || $file['size'] > $accepted) {
                        OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded'));
                        $this->redirect();
                    }
                    $tmpPhotoService->addTemporaryPhoto($file['tmp_name'], $userId, 1);
                    $tmpList = $tmpPhotoService->findUserTemporaryPhotos($userId, 'order');
                    $tmpList = array_reverse($tmpList);
                    // check album exists
                    if (!($album = $photoAlbumService->findAlbumByName($values['album'], $userId))) {
                        $album = new PHOTO_BOL_PhotoAlbum();
                        $album->name = $values['album'];
                        $album->userId = $userId;
                        $album->createDatetime = time();
                        $photoAlbumService->addAlbum($album);
                    }
                    foreach ($tmpList as $tmpPhoto) {
                        $photo = $tmpPhotoService->moveTemporaryPhoto($tmpPhoto['dto']->id, $album->id, $values['description']);
                        if ($photo) {
                            BOL_AuthorizationService::getInstance()->trackAction('photo', 'upload');
                            $photoService->createAlbumCover($album->id, array($photo));
                            $photoService->triggerNewsfeedEventOnSinglePhotoAdd($album, $photo);
                            $photoParams = array('addTimestamp' => $photo->addDatetime, 'photoId' => $photo->id, 'hash' => $photo->hash, 'description' => $photo->description);
                            $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_ADD, array($photoParams));
                            OW::getEventManager()->trigger($event);
                            $photo = $this->photoService->findPhotoById($photo->id);
                            if ($photo->status != PHOTO_BOL_PhotoDao::STATUS_APPROVED) {
                                OW::getFeedback()->info(OW::getLanguage()->text('photo', 'photo_uploaded_pending_approval'));
                                if (PHOTO_BOL_PhotoAlbumService::getInstance()->countAlbumPhotos($photo->albumId)) {
                                    $this->redirect(OW::getRouter()->urlForRoute('photo_user_album', array('user' => BOL_UserService::getInstance()->getUserName($userId), 'album' => $album->id)));
                                } else {
                                    $this->redirect(OW::getRouter()->urlForRoute('photo_user_albums', array('user' => BOL_UserService::getInstance()->getUserName($userId))));
                                }
                            } else {
                                OW::getFeedback()->info($language->text('photo', 'photos_uploaded', array('count' => 1)));
                                $this->redirect(OW::getRouter()->urlForRoute('view_photo', array('id' => $photo->id)));
                            }
                        }
                    }
                } else {
                    OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded'));
                    $this->redirect();
                }
            }
        }
        OW::getDocument()->setHeading($language->text('photo', 'upload_photos'));
        OW::getDocument()->setTitle($language->text('photo', 'meta_title_photo_upload'));
    }