/** * Replace line breaks with <br> tags preserving preformatted text * @param string * @param boolean * @return string */ function nl2br_pre($str, $xhtml = false) { $str = $xhtml ? nl2br_xhtml($str) : nl2br_html5($str); if (stripos($str, '<pre') === false) { return $str; } $chunks = array(); preg_match_all('/<pre[^>]*>.*<\\/pre>/Uis', $str, $chunks); foreach ($chunks as $chunk) { $str = str_replace($chunk, str_ireplace(array('<br>', '<br />'), '', $chunk), $str); } return $str; }
/** * 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; }