Exemple #1
0
    /**
     * Controller action for user album
     *
     * @param array $params
     * @throws Redirect404Exception
     */
    public function userAlbum(array $params)
    {
        if (!isset($params['user']) || !strlen($user = trim($params['user']))) {
            throw new Redirect404Exception();
        }
        if (!isset($params['album']) || !($albumId = (int) $params['album'])) {
            throw new Redirect404Exception();
        }
        // is owner
        $userDto = BOL_UserService::getInstance()->findByUsername($user);
        if ($userDto) {
            $ownerMode = $userDto->id == OW::getUser()->getId();
        } else {
            $ownerMode = false;
        }
        // is moderator
        $modPermissions = OW::getUser()->isAuthorized('photo');
        if (!OW::getUser()->isAuthorized('photo', 'view') && !$modPermissions && !$ownerMode) {
            $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
            return;
        }
        $page = !empty($_GET['page']) && (int) $_GET['page'] ? abs((int) $_GET['page']) : 1;
        $config = OW::getConfig();
        $photoPerPage = $config->getValue('photo', 'photos_per_page');
        $album = $this->photoAlbumService->findAlbumById($albumId);
        if (!$album) {
            throw new Redirect404Exception();
        }
        $this->assign('album', $album);
        // permissions check
        if (!$ownerMode && !$modPermissions) {
            $privacyParams = array('action' => 'photo_view_album', 'ownerId' => $album->userId, 'viewerId' => OW::getUser()->getId());
            $event = new OW_Event('privacy_check_permission', $privacyParams);
            OW::getEventManager()->trigger($event);
        }
        $this->assign('userName', BOL_UserService::getInstance()->getUserName($album->userId));
        $displayName = BOL_UserService::getInstance()->getDisplayName($album->userId);
        $this->assign('displayName', $displayName);
        $photos = $this->photoService->getAlbumPhotos($albumId, $page, $photoPerPage);
        $this->assign('photos', $photos);
        $total = $this->photoAlbumService->countAlbumPhotos($albumId);
        $this->assign('total', $total);
        $lastUpdated = $this->photoAlbumService->getAlbumUpdateTime($albumId);
        $this->assign('lastUpdate', $lastUpdated);
        $this->assign('widthConfig', $config->getValue('photo', 'preview_image_width'));
        $this->assign('heightConfig', $config->getValue('photo', 'preview_image_height'));
        // Paging
        $pages = (int) ceil($total / $photoPerPage);
        $paging = new BASE_CMP_Paging($page, $pages, $photoPerPage);
        $this->assign('paging', $paging->render());
        OW::getDocument()->setHeading($album->name . ' <span class="ow_small">' . OW::getLanguage()->text('photo', 'photos_in_album', array('total' => $total)) . '</span>');
        OW::getDocument()->setHeadingIconClass('ow_ic_picture');
        // check permissions
        $canEdit = OW::getUser()->isAuthorized('photo', 'upload', $album->userId);
        $canModerate = OW::getUser()->isAuthorized('photo');
        $authorized = $canEdit || $canModerate;
        $this->assign('authorized', $canEdit || $canModerate);
        $this->assign('canUpload', $canEdit);
        $lang = OW::getLanguage();
        if ($authorized) {
            $albumEditForm = new albumEditForm();
            $albumEditForm->getElement('albumName')->setValue($album->name);
            $albumEditForm->getElement('id')->setValue($album->id);
            $this->addForm($albumEditForm);
            OW::getDocument()->addScript($this->pluginJsUrl . 'album.js');
            if (OW::getRequest()->isPost() && $albumEditForm->isValid($_POST)) {
                $res = $albumEditForm->process();
                if ($res['result']) {
                    OW::getFeedback()->info($lang->text('photo', 'photo_album_updated'));
                    $this->redirect();
                }
            }
            $lang->addKeyForJs('photo', 'confirm_delete_album');
            $lang->addKeyForJs('photo', 'edit_album');
            $objParams = array('ajaxResponder' => $this->ajaxResponder, 'albumId' => $albumId, 'uploadUrl' => OW::getRouter()->urlForRoute('photo_upload_album', array('album' => $album->id)));
            $script = "\$(document).ready(function(){\n                    var album = new photoAlbum( " . json_encode($objParams) . ");\n                }); ";
            OW::getDocument()->addOnloadScript($script);
        }
        OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('base')->getStaticJsUrl() . 'jquery.bbq.min.js');
        OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('photo')->getStaticJsUrl() . 'photo.js');
        OW::getLanguage()->addKeyForJs('photo', 'tb_edit_photo');
        OW::getLanguage()->addKeyForJs('photo', 'confirm_delete');
        OW::getLanguage()->addKeyForJs('photo', 'mark_featured');
        OW::getLanguage()->addKeyForJs('photo', 'remove_from_featured');
        $objParams = array('ajaxResponder' => OW::getRouter()->urlFor('PHOTO_CTRL_Photo', 'ajaxResponder'), 'fbResponder' => OW::getRouter()->urlForRoute('photo.floatbox'));
        $script = '$("div.ow_photo_list_item_thumb a").on("click", function(e){
            e.preventDefault();
            var photo_id = $(this).attr("rel");

            if ( !window.photoViewObj ) {
                window.photoViewObj = new photoView(' . json_encode($objParams) . ');
            }
            
            window.photoViewObj.setId(photo_id);
        });
        
        $(window).bind( "hashchange", function(e) {
            var photo_id = $.bbq.getState("view-photo");
            if ( photo_id != undefined )
            {
                if ( window.photoFBLoading ) { return; }
                window.photoViewObj.showPhotoCmp(photo_id);
            }
        });';
        OW::getDocument()->addOnloadScript($script);
        OW::getDocument()->setTitle($lang->text('photo', 'meta_title_photo_useralbum', array('displayName' => $displayName, 'albumName' => $album->name)));
        OW::getDocument()->setDescription($lang->text('photo', 'meta_description_photo_useralbum', array('displayName' => $displayName, 'number' => $total)));
    }