/** * Generate module */ protected function compile() { global $objPage; // process request variables $this->getUrlParams(); if (!is_array(deserialize($this->gc_publish_albums)) && !$this->gc_publish_all_albums) { return; } if ($this->gc_publish_all_albums) { // if all albums should be shown $arrSelectedAlb = $this->listAllAlbums(); } else { // if only selected albums should be shown $arrSelectedAlb = deserialize($this->gc_publish_albums); } // clean array from unpublished or empty or protected albums foreach ($arrSelectedAlb as $key => $albumId) { $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=? AND published=?')->execute($albumId, '1'); $objPics = $this->Database->prepare('SELECT id FROM tl_gallery_creator_pictures WHERE pid = ? AND published=?')->execute($albumId, '1'); // if the album doesn't exist if (!$objAlbum->numRows) { unset($arrSelectedAlb[$key]); continue; } // if the album doesn't contain any pictures if (!$objPics->numRows) { unset($arrSelectedAlb[$key]); continue; } // remove id from $arrSelectedAlb if user is not allowed if (TL_MODE == 'FE' && $objAlbum->protected == true) { $blnAllowed = null; $this->import('FrontendUser', 'User'); // remove id from $arrSelectedAlb if user is not allowed if (FE_USER_LOGGED_IN && is_array(unserialize($this->User->allGroups))) { // check for accordance if (array_intersect(unserialize($this->User->allGroups), unserialize($objAlbum->groups))) { $blnAllowed = true; } } if (!$blnAllowed) { unset($arrSelectedAlb[$key]); continue; } } } // build up the new array $arrAllowedAlbums = array_values($arrSelectedAlb); $switch = strlen(\Input::get('items')) ? 'detailview' : 'albumlisting'; $switch = strlen(\Input::get('jw_imagerotator')) ? 'jw_imagerotator' : $switch; $switch = strlen(\Input::get('img')) ? 'single_image' : $switch; switch ($switch) { case 'albumlisting': // abort if no album is selected if (count($arrAllowedAlbums) < 1) { return; } // pagination settings $limit = $this->gc_AlbumsPerPage; if ($limit > 0) { $page = \Input::get('page') ? \Input::get('page') : 1; $offset = ($page - 1) * $limit; // count albums $itemsTotal = count($arrAllowedAlbums); // create pagination menu $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks; $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks); $this->Template->pagination = $objPagination->generate("\n "); } if ($limit == '0') { $limit = count($arrAllowedAlbums); $offset = 0; } $arrAlbums = array(); for ($i = $offset; $i < $offset + $limit; $i++) { if (!$arrAllowedAlbums[$i]) { continue; } $currAlbumId = $arrAllowedAlbums[$i]; $objAlbum = $this->Database->prepare('SELECT id, alias FROM tl_gallery_creator_albums WHERE id=?')->execute($currAlbumId); if (false === $this->authenticate($objAlbum->alias)) { continue; } $arrAlbums[$objAlbum->id] = GcHelpers::getAlbumInformationArray($objAlbum->id, $this); } $this->Template->imagemargin = $this->generateMargin(unserialize($this->gc_imagemargin_albumlisting)); $this->Template->arrAlbums = $arrAlbums; $this->getAlbumTemplateVars($objAlbum->id); // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this); break; case 'detailview': $objAlbum = \GalleryCreatorAlbumsModel::findByAlias($this->strAlbumalias); $published = $objAlbum->published ? true : false; // for security reasons... if (!$published || !$this->gc_publish_all_albums && !in_array($this->intAlbumId, $arrAllowedAlbums)) { die("Gallery with alias " . $this->strAlbumalias . " is either not published or not available or you haven't got enough permission to watch it!!!"); } // pagination settings $limit = $this->gc_ThumbsPerPage; if ($limit > 0) { $page = \Input::get('page') ? \Input::get('page') : 1; $offset = ($page - 1) * $limit; // count albums $objTotal = $this->Database->prepare('SELECT COUNT(id) as itemsTotal FROM tl_gallery_creator_pictures WHERE published=? AND pid=? GROUP BY ?')->execute('1', $this->intAlbumId, 'id'); $itemsTotal = $objTotal->itemsTotal; // create the pagination menu $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks; $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks); $this->Template->pagination = $objPagination->generate("\n "); } // picture sorting $str_sorting = $this->gc_picture_sorting == '' || $this->gc_picture_sorting_direction == '' ? 'sorting ASC' : $this->gc_picture_sorting . ' ' . $this->gc_picture_sorting_direction; // sort by name is done below $str_sorting = str_replace('name', 'id', $str_sorting); $objPictures = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY ' . $str_sorting); if ($limit > 0) { $objPictures->limit($limit, $offset); } $objPictures = $objPictures->execute('1', $this->intAlbumId); // build up $arrPictures $arrPictures = array(); $auxBasename = array(); while ($objPictures->next()) { $objFilesModel = \FilesModel::findByUuid($objPictures->uuid); $basename = 'undefined'; if ($objFilesModel !== null) { $basename = $objFilesModel->name; } $auxBasename[] = $basename; $arrPictures[$objPictures->id] = GcHelpers::getPictureInformationArray($objPictures->id, $this); } // sort by basename if ($this->gc_picture_sorting == 'name') { if ($this->gc_picture_sorting_direction == 'ASC') { array_multisort($arrPictures, SORT_STRING, $auxBasename, SORT_ASC); } else { array_multisort($arrPictures, SORT_STRING, $auxBasename, SORT_DESC); } } $arrPictures = array_values($arrPictures); // store $arrPictures in the template variable $this->Template->arrPictures = $arrPictures; // generate other template variables $this->getAlbumTemplateVars($this->intAlbumId); // init the counter $this->initCounter($this->intAlbumId); // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this, $objAlbum); break; case 'single_image': $objAlbum = \GalleryCreatorAlbumsModel::findByAlias(\Input::get('items')); if ($objAlbum === null) { die('Invalid album alias: ' . \Input::get('items')); } $objPic = \Database::getInstance()->prepare("SELECT * FROM tl_gallery_creator_pictures WHERE pid=? AND name LIKE '" . \Input::get('img') . ".%'")->execute($objAlbum->id); if (!$objPic->numRows) { die(sprintf('File with filename "%s" does not exist in album with alias "%s".', \Input::get('img'), \Input::get('items'))); } $picId = $objPic->id; $published = $objPic->published ? true : false; $published = $objAlbum->published ? $published : false; // for security reasons... if (!$published || !$this->gc_publish_all_albums && !in_array($this->intAlbumId, $arrAllowedAlbums)) { die("Picture with id " . $picId . " is either not published or not available or you haven't got enough permission to watch it!!!"); } // picture sorting $str_sorting = $this->gc_picture_sorting == '' || $this->gc_picture_sorting_direction == '' ? 'sorting ASC' : $this->gc_picture_sorting . ' ' . $this->gc_picture_sorting_direction; $objPictures = $this->Database->prepare('SELECT id FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY ' . $str_sorting); $objPictures = $objPictures->execute('1', $this->intAlbumId); // build up $arrPictures $arrIDS = array(); $i = 0; $currentIndex = null; while ($objPictures->next()) { if ($picId == $objPictures->id) { $currentIndex = $i; } $arrIDS[] = $objPictures->id; $i++; } $arrPictures = array(); if (count($arrIDS)) { // store $arrPictures in the template variable $arrPictures['prev'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex - 1], $this); $arrPictures['current'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex], $this); $arrPictures['next'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex + 1], $this); // add navigation href's to the template $this->Template->prevHref = $arrPictures['prev']['single_image_url']; $this->Template->nextHref = $arrPictures['next']['single_image_url']; if ($currentIndex == 0) { $arrPictures['prev'] = null; $this->Template->prevHref = null; } if ($currentIndex == count($arrIDS) - 1) { $arrPictures['next'] = null; $this->Template->nextHref = null; } if (count($arrIDS) == 1) { $arrPictures['next'] = null; $arrPictures['prev'] = null; $this->Template->nextHref = null; $this->Template->prevItem = null; } } // Get the page model $objPageModel = \PageModel::findByPk($objPage->id); $this->Template->returnHref = $objPageModel->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . \Input::get('items'), $objPage->language); $this->Template->arrPictures = $arrPictures; // generate other template variables $this->getAlbumTemplateVars($this->intAlbumId); // init the counter $this->initCounter($this->intAlbumId); // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this, $objAlbum); break; case 'jw_imagerotator': header("content-type:text/xml;charset=utf-8"); echo $this->getJwImagerotatorXml($this->strAlbumalias); exit; break; } // end switch }
/** * Generate module */ protected function compile() { // use a private template if (TL_MODE == 'FE' && $this->gc_template != '') { $this->Template->style = count($this->arrStyle) ? implode(' ', $this->arrStyle) : ''; $this->Template->cssID = strlen($this->cssID[0]) ? ' id="' . $this->cssID[0] . '"' : ''; $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]); } // check for excluded albums in the module settings $arrExcludedAlbums = deserialize($this->gc_excludedAlbums); $strExcludedAlbums = is_array($arrExcludedAlbums) && !empty($arrExcludedAlbums) ? implode(',', $arrExcludedAlbums) : '0'; // redirect to the detailview if there is only 1 album if (!\Input::get('items') && $this->gc_redirectSingleAlb) { $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1'); if ($objAlbum->numRows === 1) { \Input::setGet('items', $objAlbum->alias); } } if (\Input::get('items')) { $this->strAlbumalias = \Input::get('items'); // authenticate user if album is protected $this->authenticate($this->strAlbumalias); // get the album id from the album alias $objAlbum = $this->Database->prepare('SELECT id FROM tl_gallery_creator_albums WHERE alias=?')->execute($this->strAlbumalias); $this->intAlbumId = $objAlbum->id; } $switch = strlen(\Input::get('items')) ? 'detailview' : 'albumlisting'; $switch = strlen(\Input::get('jw_imagerotator')) ? 'jw_imagerotator' : $switch; switch ($switch) { case 'albumlisting': // get all published albums $arrAllowedAlbums = array(); if ($this->gc_hierarchicalOutput) { $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND pid=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1', '0'); } else { $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1'); } while ($objAlbum->next()) { if (TL_MODE == 'FE' && $objAlbum->protected == true) { $this->import('FrontendUser', 'User'); // check if the frontend user is allowed if (FE_USER_LOGGED_IN && is_array(unserialize($this->User->allGroups))) { if (array_intersect(unserialize($this->User->allGroups), unserialize($objAlbum->groups))) { // user is allowed $arrAllowedAlbums[] = $objAlbum->id; } } continue; } // album is not protected $arrAllowedAlbums[] = $objAlbum->id; } // pagination settings $limit = $this->gc_AlbumsPerPage; if ($limit > 0) { $page = \Input::get('page') ? \Input::get('page') : 1; $offset = ($page - 1) * $limit; $itemsTotal = count($arrAllowedAlbums); // add pagination menu $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks; $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks); $this->Template->pagination = $objPagination->generate("\n "); } // get all published albums $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id IN(' . implode(",", $arrAllowedAlbums) . ') ORDER BY sorting ASC'); if ($limit > 0) { $objAlbum->limit($limit, $offset); } $objAlbum = $objAlbum->execute('1', '0'); // album array $arrAlbums = array(); while ($objAlbum->next()) { $arrAlbums[$objAlbum->id] = GcHelpers::getAlbumInformationArray($objAlbum->id, $this); } $this->Template->imagemargin = $this->generateMargin(unserialize($this->gc_imagemargin_albumlisting)); $this->Template->arrAlbums = $arrAlbums; $this->getAlbumTemplateVars($objAlbum->id); // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this); break; case 'detailview': $objAlbum = \GalleryCreatorAlbumsModel::findByPk($this->intAlbumId); $published = $objAlbum->published ? true : false; if ($published) { $published = in_array($this->intAlbumId, explode(',', $strExcludedAlbums)) ? false : true; } // for security reasons... if (!$published) { die("Gallery with alias " . \Input::get('items') . " is either not published or not available!!!"); } // generate the subalbum array if ($this->gc_hierarchicalOutput) { $arrSubalbums = GcHelpers::getSubalbumsInformationArray($this->intAlbumId, $this); $this->Template->subalbums = count($arrSubalbums) ? $arrSubalbums : null; } // pagination settings $limit = $this->gc_ThumbsPerPage; if ($limit > 0) { $page = \Input::get('page') ? \Input::get('page') : 1; $offset = ($page - 1) * $limit; // count albums $objTotal = $this->Database->prepare('SELECT COUNT(id) as itemsTotal FROM tl_gallery_creator_pictures WHERE published=? AND pid=?')->execute('1', $this->intAlbumId); $itemsTotal = $objTotal->itemsTotal; // add pagination menu $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks; $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks); $this->Template->pagination = $objPagination->generate("\n "); } $objPictures = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY sorting'); if ($limit > 0) { $objPictures->limit($limit, $offset); } $objPictures = $objPictures->execute('1', $this->intAlbumId); $arrPictures = array(); while ($objPictures->next()) { // picture array $arrPictures[$objPictures->id] = GcHelpers::getPictureInformationArray($objPictures->id, $this); } // add picture array to the template $this->Template->arrPictures = $arrPictures; // add some other useful template vars $this->getAlbumTemplateVars($this->intAlbumId); // init the counter $this->initCounter($this->intAlbumId); // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this); break; case 'jw_imagerotator': header("content-type:text/xml;charset=utf-8"); echo $this->getJwImagerotatorXml($this->strAlbumalias); exit; break; } //end switch }
/** * Generate module */ protected function compile() { global $objPage; switch ($this->viewMode) { case 'list_view': // pagination settings $limit = $this->gc_AlbumsPerPage; $offset = 0; if ($limit > 0) { // Get the current page $id = 'page_g' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; $offset = ($page - 1) * $limit; // count albums $itemsTotal = count($this->arrSelectedAlbums); // create pagination menu $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks; $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks, $id); $this->Template->pagination = $objPagination->generate("\n "); } if ($limit == 0 || $limit > count($this->arrSelectedAlbums)) { $limit = count($this->arrSelectedAlbums); } $arrAlbums = array(); for ($i = $offset; $i < $offset + $limit; $i++) { if (isset($this->arrSelectedAlbums[$i])) { $arrAlbums[] = GcHelpers::getAlbumInformationArray($this->arrSelectedAlbums[$i], $this); } } // Add css classes if (count($arrAlbums) > 0) { $arrAlbums[0]['cssClass'] .= ' first'; $arrAlbums[count($arrAlbums) - 1]['cssClass'] .= ' last'; } $this->Template->imagemargin = $this->generateMargin(unserialize($this->gc_imagemargin_albumlisting)); $this->Template->arrAlbums = $arrAlbums; // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this); break; case 'detail_view': // generate the subalbum array if ($this->gc_hierarchicalOutput) { $arrSubalbums = GcHelpers::getSubalbumsInformationArray($this->intAlbumId, $this); $this->Template->subalbums = count($arrSubalbums) ? $arrSubalbums : null; } // count pictures $objTotal = $this->Database->prepare('SELECT id FROM tl_gallery_creator_pictures WHERE published=? AND pid=?')->execute('1', $this->intAlbumId); $total = $objTotal->numRows; // pagination settings $limit = $this->gc_ThumbsPerPage; $offset = 0; if ($limit > 0) { // Get the current page $id = 'page_g' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $limit), 1)) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } $offset = ($page - 1) * $limit; // create the pagination menu $numberOfLinks = $this->gc_PaginationNumberOfLinks ? $this->gc_PaginationNumberOfLinks : 7; $objPagination = new \Pagination($total, $limit, $numberOfLinks, $id); $this->Template->pagination = $objPagination->generate("\n "); } // picture sorting $str_sorting = $this->gc_picture_sorting == '' || $this->gc_picture_sorting_direction == '' ? 'sorting ASC' : $this->gc_picture_sorting . ' ' . $this->gc_picture_sorting_direction; // sort by name is done below $str_sorting = str_replace('name', 'id', $str_sorting); $objPictures = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY ' . $str_sorting); if ($limit > 0) { $objPictures->limit($limit, $offset); } $objPictures = $objPictures->execute(1, $this->intAlbumId); // build up $arrPictures $arrPictures = array(); $auxBasename = array(); while ($objPictures->next()) { $objFilesModel = \FilesModel::findByUuid($objPictures->uuid); $basename = 'undefined'; if ($objFilesModel !== null) { $basename = $objFilesModel->name; } $auxBasename[] = $basename; $arrPictures[$objPictures->id] = GcHelpers::getPictureInformationArray($objPictures->id, $this); } // sort by basename if ($this->gc_picture_sorting == 'name') { if ($this->gc_picture_sorting_direction == 'ASC') { array_multisort($arrPictures, SORT_STRING, $auxBasename, SORT_ASC); } else { array_multisort($arrPictures, SORT_STRING, $auxBasename, SORT_DESC); } } $arrPictures = array_values($arrPictures); // store $arrPictures in the template variable $this->Template->arrPictures = $arrPictures; // generate other template variables $this->getAlbumTemplateVars($this->intAlbumId); // init the counter $this->initCounter($this->intAlbumId); // Call gcGenerateFrontendTemplateHook $objAlbum = \GalleryCreatorAlbumsModel::findByAlias($this->strAlbumalias); $this->Template = $this->callGcGenerateFrontendTemplateHook($this, $objAlbum); break; case 'single_image': $objAlbum = \GalleryCreatorAlbumsModel::findByAlias(\Input::get('items')); if ($objAlbum === null) { die('Invalid album alias: ' . \Input::get('items')); } $objPic = \Database::getInstance()->prepare("SELECT * FROM tl_gallery_creator_pictures WHERE pid=? AND name LIKE '" . \Input::get('img') . ".%'")->execute($objAlbum->id); if (!$objPic->numRows) { die(sprintf('File with filename "%s" does not exist in album with alias "%s".', \Input::get('img'), \Input::get('items'))); } $picId = $objPic->id; $published = $objPic->published ? true : false; $published = $objAlbum->published ? $published : false; // for security reasons... if (!$published || !$this->gc_publish_all_albums && !in_array($this->intAlbumId, $this->arrSelectedAlbums)) { die("Picture with id " . $picId . " is either not published or not available or you haven't got enough permission to watch it!!!"); } // picture sorting $str_sorting = $this->gc_picture_sorting == '' || $this->gc_picture_sorting_direction == '' ? 'sorting ASC' : $this->gc_picture_sorting . ' ' . $this->gc_picture_sorting_direction; $objPictures = $this->Database->prepare('SELECT id FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY ' . $str_sorting); $objPictures = $objPictures->execute('1', $this->intAlbumId); // build up $arrPictures $arrIDS = array(); $i = 0; $currentIndex = null; while ($objPictures->next()) { if ($picId == $objPictures->id) { $currentIndex = $i; } $arrIDS[] = $objPictures->id; $i++; } $arrPictures = array(); if (count($arrIDS)) { // store $arrPictures in the template variable $arrPictures['prev'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex - 1], $this); $arrPictures['current'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex], $this); $arrPictures['next'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex + 1], $this); // add navigation href's to the template $this->Template->prevHref = $arrPictures['prev']['single_image_url']; $this->Template->nextHref = $arrPictures['next']['single_image_url']; if ($currentIndex == 0) { $arrPictures['prev'] = null; $this->Template->prevHref = null; } if ($currentIndex == count($arrIDS) - 1) { $arrPictures['next'] = null; $this->Template->nextHref = null; } if (count($arrIDS) == 1) { $arrPictures['next'] = null; $arrPictures['prev'] = null; $this->Template->nextHref = null; $this->Template->prevItem = null; } } // Get the page model $objPageModel = \PageModel::findByPk($objPage->id); $this->Template->returnHref = $objPageModel->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . \Input::get('items'), $objPage->language); $this->Template->arrPictures = $arrPictures; // generate other template variables $this->getAlbumTemplateVars($this->intAlbumId); // init the counter $this->initCounter($this->intAlbumId); // Call gcGenerateFrontendTemplateHook $this->Template = $this->callGcGenerateFrontendTemplateHook($this, $objAlbum); break; } // end switch }