/** * Set the template * @return string */ public function generate() { if (TL_MODE == 'BE') { $objTemplate = new \BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### ' . $GLOBALS['TL_LANG']['CTE']['gallery_creator_ce'][0] . ' ###'; $objTemplate->title = $this->headline; // for module use only $objTemplate->id = $this->id; $objTemplate->link = $this->name; $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; return $objTemplate->parse(); } // unset the Session unset($_SESSION['gallery_creator']['CURRENT_ALBUM']); if ($_SESSION['GcRedirectToAlbum']) { \Input::setGet('items', $_SESSION['GcRedirectToAlbum']); unset($_SESSION['GcRedirectToAlbum']); } // Ajax Requests if (TL_MODE == 'FE' && \Environment::get('isAjaxRequest')) { $this->generateAjax(); } // set the item from the auto_item parameter if ($GLOBALS['TL_CONFIG']['useAutoItem'] && isset($_GET['auto_item'])) { \Input::setGet('items', \Input::get('auto_item')); } if (strlen(\Input::get('items'))) { $this->viewMode = 'detail_view'; } // store the pagination variable page in the current session if (!\Input::get('items')) { unset($_SESSION['gallery_creator']['PAGINATION']); } if (\Input::get('page') && $this->viewMode != 'detail_view') { $_SESSION['gallery_creator']['PAGINATION'] = \Input::get('page'); } if ($this->gc_publish_all_albums) { // if all albums should be shown $this->arrSelectedAlbums = $this->listAllAlbums(); } else { // if only selected albums should be shown $this->arrSelectedAlbums = deserialize($this->gc_publish_albums, true); } // clean array from unpublished or empty or protected albums foreach ($this->arrSelectedAlbums as $key => $albumId) { // Get all not empty albums $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE (SELECT COUNT(id) FROM tl_gallery_creator_pictures WHERE pid = ? AND published=?) > 0 AND id=? AND published=?')->execute($albumId, 1, $albumId, 1); // if the album doesn't exist if (!$objAlbum->numRows && !\GalleryCreatorAlbumsModel::hasChildAlbums($objAlbum->id) && !$this->gc_hierarchicalOutput) { unset($this->arrSelectedAlbums[$key]); continue; } // remove id from $this->arrSelectedAlbums if user is not allowed if (TL_MODE == 'FE' && $objAlbum->protected == true) { if (!$this->authenticate($objAlbum->alias)) { unset($this->arrSelectedAlbums[$key]); continue; } } } // build up the new array $this->arrSelectedAlbums = array_values($this->arrSelectedAlbums); // abort if no album is selected if (empty($this->arrSelectedAlbums)) { return ''; } // Detail view: // Authenticate and get album alias and album id if (\Input::get('items')) { $objAlbum = \GalleryCreatorAlbumsModel::findByAlias(\Input::get('items')); if ($objAlbum !== null) { $this->intAlbumId = $objAlbum->id; $this->strAlbumalias = $objAlbum->alias; $this->viewMode = 'detail_view'; } else { return ''; } //Authentifizierung bei vor Zugriff geschuetzten Alben, dh. der Benutzer bekommt, wenn nicht berechtigt, nur das Albumvorschaubild zu sehen. if (!$this->authenticate($this->strAlbumalias)) { return ''; } } $this->viewMode = $this->viewMode ? $this->viewMode : 'list_view'; $this->viewMode = strlen(\Input::get('img')) ? 'single_image' : $this->viewMode; if ($this->viewMode == 'list_view') { // Redirect to detailview if there is only one album if (count($this->arrSelectedAlbums) == 1 && $this->gc_redirectSingleAlb) { $_SESSION['GcRedirectToAlbum'] = \GalleryCreatorAlbumsModel::findByPk($this->arrSelectedAlbums[0])->alias; $this->reload(); } //Hierarchische Ausgabe if ($this->gc_hierarchicalOutput) { foreach ($this->arrSelectedAlbums as $k => $albumId) { $objAlbum = \GalleryCreatorAlbumsModel::findByPk($albumId); if ($objAlbum->pid > 0) { unset($this->arrSelectedAlbums[$k]); } } $this->arrSelectedAlbums = array_values($this->arrSelectedAlbums); if (empty($this->arrSelectedAlbums)) { return ''; } } } if ($this->viewMode == 'detail_view') { // for security reasons... if (!$this->gc_publish_all_albums && !in_array($this->intAlbumId, $this->arrSelectedAlbums)) { return ''; } } //assigning the frontend template $this->strTemplate = $this->gc_template != "" ? $this->gc_template : $this->strTemplate; $this->Template = new \FrontendTemplate($this->strTemplate); return parent::generate(); }
/** * Returns the information-array about an album * * @param $intAlbumId * @param $objContentElement * @return array */ public static function getAlbumInformationArray($intAlbumId, $objContentElement) { global $objPage; // Get the page model $objPageModel = \PageModel::findByPk($objPage->id); $objAlbum = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=?')->execute($intAlbumId); //Anzahl Subalben ermitteln $objSubAlbums = \Database::getInstance()->prepare('SELECT thumb, count(id) AS countSubalbums FROM tl_gallery_creator_albums WHERE published=? AND pid=? GROUP BY ?')->execute('1', $intAlbumId, 'id'); $objPics = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE pid=? AND published=?')->execute($objAlbum->id, '1'); //Array Thumbnailbreite $arrSize = unserialize($objContentElement->gc_size_albumlisting); $href = null; if (TL_MODE == 'FE') { //generate the url as a formated string $href = $objPageModel->getFrontendUrl($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/items/%s', $objPage->language); // add albumAlias $href = sprintf($href, $objAlbum->alias); } $arrPreviewThumb = $objContentElement->getAlbumPreviewThumb($objAlbum->id); $strImageSrc = $arrPreviewThumb['path']; //Generate the thumbnails and the picture element try { $thumbSrc = \Image::create($strImageSrc, $arrSize)->executeResize()->getResizedPath(); $picture = \Picture::create($strImageSrc, $arrSize)->getTemplateData(); if ($thumbSrc !== $strImageSrc) { new \File(rawurldecode($thumbSrc), true); } } catch (\Exception $e) { \System::log('Image "' . $strImageSrc . '" could not be processed: ' . $e->getMessage(), __METHOD__, TL_ERROR); } $picture['alt'] = specialchars($objAlbum->name); $picture['title'] = specialchars($objAlbum->name); // CSS class $strCSSClass = \GalleryCreatorAlbumsModel::hasChildAlbums($objAlbum->id) ? 'has-child-album' : ''; $strCSSClass .= $objPics->numRows < 1 ? ' empty-album' : ''; $arrAlbum = array('id' => $objAlbum->id, 'pid' => $objAlbum->pid, 'sorting' => $objAlbum->sorting, 'published' => $objAlbum->published, 'owner' => $objAlbum->owner, 'owners_name' => $objAlbum->owners_name, 'tstamp' => $objAlbum->tstamp, 'event_tstamp' => $objAlbum->date, 'date' => $objAlbum->date, 'event_date' => \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $objAlbum->date), 'event_location' => specialchars($objAlbum->event_location), 'name' => specialchars($objAlbum->name), 'alias' => $objAlbum->alias, 'comment' => $objPage->outputFormat == 'xhtml' ? \StringUtil::toXhtml(nl2br_xhtml($objAlbum->comment)) : \StringUtil::toHtml5(nl2br_html5($objAlbum->comment)), 'caption' => $objPage->outputFormat == 'xhtml' ? \StringUtil::toXhtml(nl2br_xhtml($objAlbum->comment)) : \StringUtil::toHtml5(nl2br_html5($objAlbum->comment)), 'visitors' => $objAlbum->visitors, 'href' => $href, 'title' => $objAlbum->name . ' [' . ($objPics->numRows ? $objPics->numRows . ' ' . $GLOBALS['TL_LANG']['gallery_creator']['pictures'] : '') . ($objContentElement->gc_hierarchicalOutput && $objSubAlbums->countSubalbums > 0 ? ' ' . $GLOBALS['TL_LANG']['gallery_creator']['contains'] . ' ' . $objSubAlbums->countSubalbums . ' ' . $GLOBALS['TL_LANG']['gallery_creator']['subalbums'] . ']' : ']'), 'count' => $objPics->numRows, 'count_subalbums' => count(\GalleryCreatorAlbumsModel::getChildAlbums($objAlbum->id)), 'alt' => $arrPreviewThumb['name'], 'src' => TL_FILES_URL . $arrPreviewThumb['path'], 'thumb_src' => TL_FILES_URL . \Image::get($arrPreviewThumb['path'], $arrSize[0], $arrSize[1], $arrSize[2]), 'insert_article_pre' => $objAlbum->insert_article_pre ? $objAlbum->insert_article_pre : null, 'insert_article_post' => $objAlbum->insert_article_post ? $objAlbum->insert_article_post : null, 'class' => 'thumb', 'size' => $arrSize, 'thumbMouseover' => $objContentElement->gc_activateThumbSlider ? "objGalleryCreator.initThumbSlide(this," . $objAlbum->id . "," . $objPics->numRows . ");" : "", 'picture' => $picture, 'cssClass' => trim($strCSSClass)); // Fuegt dem Array weitere Eintraege hinzu, falls tl_gallery_creator_albums erweitert wurde $objAlbum = \GalleryCreatorAlbumsModel::findByPk($intAlbumId); if ($objAlbum !== null) { $arrAlbum = array_merge($objAlbum->row(), $arrAlbum); } return $arrAlbum; }