Example #1
0
 public function __construct($listType, $count, $exclude = null, $albumId = null)
 {
     parent::__construct();
     $this->photoService = PHOTO_BOL_PhotoService::getInstance();
     $this->photoAlbumService = PHOTO_BOL_PhotoAlbumService::getInstance();
     $checkPrivacy = !OW::getUser()->isAuthorized('photo');
     if ($albumId) {
         $photos = $this->photoService->getAlbumPhotos($albumId, 1, $count, $exclude);
     } else {
         $photos = $this->photoService->findPhotoList($listType, 1, $count, $checkPrivacy, $exclude);
     }
     $this->assign('photos', $photos);
     foreach ($photos as $photo) {
         array_push($exclude, $photo['id']);
     }
     if ($albumId) {
         $loadMore = $this->photoAlbumService->countAlbumPhotos($albumId, $exclude);
     } else {
         $loadMore = $this->photoService->countPhotos($listType, $checkPrivacy, $exclude);
     }
     if (!$loadMore) {
         $script = "OWM.trigger('photo.hide_load_more', {});";
         OW::getDocument()->addOnloadScript($script);
     }
 }
Example #2
0
 /**
  * Method acts as ajax responder. Calls methods using ajax
  * 
  * @return JSON encoded string
  *
  */
 public function getPhotosContent()
 {
     if (empty($_GET['photo_id']) || !$_GET['photo_id']) {
         throw new Redirect404Exception();
         exit;
     }
     $userId = OW::getUser()->getId();
     $photoId = (int) $_GET['photo_id'];
     $photo = $this->photoService->findPhotoById($photoId);
     if (!$photo) {
         exit(json_encode(array('result' => 'error')));
     }
     // is moderator
     $moderatorMode = OW::getUser()->isAuthorized('photo');
     $userId = OW::getUser()->getId();
     $contentOwner = $this->photoService->findPhotoOwner($photoId);
     $ownerMode = $contentOwner == $userId;
     $canView = true;
     $message = '';
     if (!$ownerMode && !OW::getUser()->isAuthorized('photo', 'view')) {
         $canView = false;
         $message = OW::getLanguage()->text('base', 'authorization_failed_feedback');
     }
     $album = $this->photoAlbumService->findAlbumById($photo->albumId);
     $ownerName = BOL_UserService::getInstance()->getUserName($album->userId);
     $photoCount = $this->photoAlbumService->countAlbumPhotos($photo->albumId);
     $photos = $this->photoService->getAlbumPhotos($photo->albumId, 1, $photoCount);
     foreach ($photos as $item) {
         $photosList[] = array('photo_id' => $item['id'], 'thumb' => $item['url'], 'src' => $this->photoService->getPhotoUrl($item['id']), 'active' => $item['id'] == $_GET['photo_id'], 'title' => '', 'description' => '');
     }
     //var_dump($photos);die;
     exit(json_encode(array('photos' => $photosList, 'count' => $photoCount, 'album_title' => $album->name, 'album_href' => OW::getRouter()->urlForRoute('photo_user_album', array('user' => $ownerName, 'album' => $photo->albumId)), 'owner_title' => BOL_UserService::getInstance()->getDisplayName($album->userId), 'owner_href' => BOL_UserService::getInstance()->getUserUrl($album->userId), 'authorized' => $ownerMode || $moderatorMode || OW::getUser()->isAuthorized('photo', 'view'), 'message' => $message)));
 }
Example #3
0
 public function collectAlbumPhotosForAvatar(BASE_CLASS_EventCollector $e)
 {
     if (!OW::getUser()->isAuthenticated()) {
         return;
     }
     $params = $e->getParams();
     if ($params['entityType'] != 'photo_album') {
         return;
     }
     $albumId = $params['entityId'];
     $page = floor($params['offset'] / $params['limit']) + 1;
     $photos = $this->photoService->getAlbumPhotos($albumId, $page, $params['limit']);
     if (!$photos) {
         return;
     }
     $list = array();
     foreach ($photos as $photo) {
         $list[] = array('id' => $photo['id'], 'url' => $photo['url'], 'bigUrl' => $this->photoService->getPhotoUrlByType($photo['id'], PHOTO_BOL_PhotoService::TYPE_MAIN, $photo['dto']->hash, $photo['dto']->dimension));
     }
     $section = array('count' => $this->photoService->countAlbumPhotos($albumId, array()), 'list' => $list);
     $e->add($section);
 }
Example #4
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)));
    }