add images to template
This commit is contained in:
113
src/News.php
Normal file
113
src/News.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* article_images extension for Contao Open Source CMS
|
||||
*
|
||||
* Copyright (C) 2011-2017 Jens Dietze
|
||||
*
|
||||
* @package article_images
|
||||
* @author Jens Dietze <http://www.jensdietze.com>
|
||||
* @license LGPL
|
||||
*/
|
||||
|
||||
namespace Jr\FalsBundle;
|
||||
|
||||
/**
|
||||
* Provide methods regarding news archives
|
||||
*/
|
||||
class News extends \Contao\News
|
||||
{
|
||||
|
||||
/**
|
||||
* Add the categories to the template
|
||||
* @param object
|
||||
* @param array
|
||||
*/
|
||||
public function addImagesToTemplate($objTemplate, $arrData, $news)
|
||||
{
|
||||
$multiSRC = deserialize($arrData['multiSRC']);
|
||||
|
||||
// Return if there are no files
|
||||
if (!is_array($multiSRC) || empty($multiSRC))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get the file entries from the database
|
||||
$objFiles = \FilesModel::findMultipleByUuids($multiSRC);
|
||||
|
||||
if ($objFiles === null)
|
||||
{
|
||||
if (!\Validator::isUuid($multiSRC[0]))
|
||||
{
|
||||
return '<p class="error">'.$GLOBALS['TL_LANG']['ERR']['version2format'].'</p>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
$objTemplate->addMoreImages = false;
|
||||
$arrArticle = $arrData;
|
||||
$objTemplate->pictures = array();
|
||||
$arrArticle['multiSRC'] = array();
|
||||
if ($news->imgSize != '')
|
||||
{
|
||||
$size = deserialize($news->imgSize);
|
||||
if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2]))
|
||||
{
|
||||
$arrArticle['size'] = $news->imgSize;
|
||||
}
|
||||
}
|
||||
while ($objFiles->next())
|
||||
{
|
||||
if (isset($arrArticle['multiSRC'][$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path) || $objFiles->type != 'file')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$objFile = new \File($objFiles->path, true);
|
||||
if (!$objFile->isImage) {
|
||||
continue;
|
||||
}
|
||||
$arrArticle['multiSRC'][$objFiles->path] = $objFile;
|
||||
}
|
||||
if (count($arrArticle['multiSRC']) > 0)
|
||||
{
|
||||
$this->addMoreImagesToTemplate($objTemplate, $arrArticle);
|
||||
}
|
||||
}
|
||||
|
||||
public function addMoreImagesToTemplate($objTemplate, $arrItem, $intMaxWidth=null, $strLightboxId=null)
|
||||
{
|
||||
/** @var \PageModel $objPage */
|
||||
global $objPage;
|
||||
|
||||
$pictures = array();
|
||||
foreach ($arrItem['multiSRC'] as $path => $objFile)
|
||||
{
|
||||
$size = unserialize($arrItem['size']);
|
||||
$arrMeta = \Frontend::getMetaData($file->meta, $objPage->language);
|
||||
|
||||
$picture = \Picture::create($path, $size)->getTemplateData();
|
||||
if (isset($arrMeta['title']))
|
||||
{
|
||||
$picture['title'] = $arrMeta['title'];
|
||||
}
|
||||
if (isset($arrMeta['link']))
|
||||
{
|
||||
$picture['link'] = $arrMeta['link'];
|
||||
}
|
||||
if (isset($arrMeta['caption']))
|
||||
{
|
||||
$picture['caption'] = $arrMeta['caption'];
|
||||
}
|
||||
$picture['href'] = TL_FILES_URL . \System::urlEncode($path);
|
||||
$pictures[] = $picture;
|
||||
}
|
||||
|
||||
$objTemplate->morePictures = $pictures;
|
||||
if (count($pictures) > 0 && $arrItem['addMoreImages'] == "1")
|
||||
{
|
||||
$objTemplate->addMoreImages = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
6
src/Resources/contao/config/config.php
Normal file
6
src/Resources/contao/config/config.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* HOOKS
|
||||
*/
|
||||
$GLOBALS['TL_HOOKS']['parseArticles'][] = array('\Jr\FalsBundle\News', 'addImagesToTemplate');
|
||||
|
||||
Reference in New Issue
Block a user