1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Rendering image elements |
4
|
|
|
* |
5
|
|
|
* @author Tim Lochmüller |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace FRUIT\Ink\Rendering; |
9
|
|
|
|
10
|
|
|
use TYPO3\CMS\Core\Resource\File; |
11
|
|
|
use TYPO3\CMS\Core\Resource\FileRepository; |
12
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Rendering image elements |
16
|
|
|
*/ |
17
|
|
|
class Image extends AbstractRendering |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Render the given element |
22
|
|
|
* |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
public function renderInternal() |
26
|
|
|
{ |
27
|
|
|
$objectManager = new ObjectManager(); |
28
|
|
|
/** @var FileRepository $fileRepository */ |
29
|
|
|
$fileRepository = $objectManager->get('TYPO3\\CMS\\Core\\Resource\\FileRepository'); |
30
|
|
|
$files = $fileRepository->findByRelation('tt_content', 'image', $this->contentObject->data['uid']); |
31
|
|
|
|
32
|
|
|
$images_arr = array(); |
33
|
|
|
foreach ($files as $file) { |
34
|
|
|
/** @var $file File */ |
35
|
|
|
$images_arr[] = $this->getLink($file->getPublicUrl()); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$lines[] = $this->renderImagesHelper($images_arr, !$this->contentObject->data['image_zoom'] ? $this->contentObject->data['image_link'] : '', $this->contentObject->data['imagecaption']); |
|
|
|
|
39
|
|
|
|
40
|
|
|
return $lines; |
41
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Render block of images - which means creating lines with links to the images. |
46
|
|
|
* |
47
|
|
|
* @param array $images_arr : the image array |
48
|
|
|
* @param string $links : Link value from the "image_link" field in tt_content records |
49
|
|
|
* @param string $caption : Caption text |
50
|
|
|
* |
51
|
|
|
* @return string Content |
52
|
|
|
* @see getImages() |
53
|
|
|
*/ |
54
|
|
|
public function renderImagesHelper($images_arr, $links, $caption) |
55
|
|
|
{ |
56
|
|
|
$linksArr = explode(',', $links); |
57
|
|
|
$lines = array(); |
58
|
|
|
$imageExists = false; |
59
|
|
|
|
60
|
|
|
foreach ($images_arr as $k => $file) { |
61
|
|
|
if (strlen(trim($file)) > 0) { |
62
|
|
|
$lines[] = $file; |
63
|
|
|
if ($links && count($linksArr) > 1) { |
64
|
|
|
if (isset($linksArr[$k])) { |
65
|
|
|
$ll = $linksArr[$k]; |
66
|
|
|
} else { |
67
|
|
|
$ll = $linksArr[0]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$theLink = $this->getLink($ll); |
71
|
|
|
if ($theLink) { |
72
|
|
|
$lines[] = $this->configuration['images.']['linkPrefix'] . $theLink; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
$imageExists = true; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
if ($this->configuration['images.']['header'] && $imageExists) { |
79
|
|
|
array_unshift($lines, $this->configuration['images.']['header']); |
80
|
|
|
} |
81
|
|
|
if ($links && count($linksArr) == 1) { |
82
|
|
|
$theLink = $this->getLink($links); |
83
|
|
|
if ($theLink) { |
84
|
|
|
$lines[] = $this->configuration['images.']['linkPrefix'] . $theLink; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
if ($caption) { |
88
|
|
|
$lines[] = ''; |
89
|
|
|
$cHeader = trim($this->configuration['images.']['captionHeader']); |
90
|
|
|
if ($cHeader) { |
91
|
|
|
$lines[] = $cHeader; |
92
|
|
|
} |
93
|
|
|
$lines[] = $this->breakContent($caption); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return chr(10) . implode(chr(10), $lines); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|