... | ... |
@@ -92,9 +92,10 @@ class ContentSlickSliderImage extends \ContentElement |
92 | 92 |
$source = \StringUtil::deserialize($this->multiSRC); |
93 | 93 |
$objFiles = \FilesModel::findMultipleByUuids($source); |
94 | 94 |
|
95 |
+ $imageFiles = array(); |
|
96 |
+ $videoFiles = array(); |
|
97 |
+ |
|
95 | 98 |
if ($objFiles !== null) { |
96 |
- $imageFiles = array(); |
|
97 |
- $videoFiles = array(); |
|
98 | 99 |
|
99 | 100 |
foreach ($objFiles as $file) { |
100 | 101 |
if (is_file(TL_ROOT . '/' . $file->path)) |
... | ... |
@@ -58,6 +58,16 @@ class ContentSlickSliderImage extends \ContentElement |
58 | 58 |
return $return; |
59 | 59 |
} |
60 | 60 |
|
61 |
+ $parentKey = ($this->arrData['ptable'] ?: 'tl_article') . '__' . $this->arrData['pid']; |
|
62 |
+ |
|
63 |
+ if (isset($GLOBALS['TL_ESM_SLICK'][$parentKey])) |
|
64 |
+ { |
|
65 |
+ $this->arrData['parentSlickId'] = $GLOBALS['TL_ESM_SLICK'][$parentKey]; |
|
66 |
+ } else { |
|
67 |
+ $this->arrData['parentSlickId'] = 0; |
|
68 |
+ } |
|
69 |
+ |
|
70 |
+ |
|
61 | 71 |
return parent::generate(); |
62 | 72 |
} |
63 | 73 |
|
... | ... |
@@ -172,6 +182,7 @@ class ContentSlickSliderImage extends \ContentElement |
172 | 182 |
|
173 | 183 |
if ($this->eSM_slick_addImageLink) |
174 | 184 |
{ |
185 |
+ $this->Template->lightboxId = 'image_slide_' . ($this->parentSlickId ?: 's'.$this->id); |
|
175 | 186 |
$this->Template->fullsize = $this->fullsize; |
176 | 187 |
$this->Template->imageLink = ($this->imageUrl ?: $this->singleSRC); |
177 | 188 |
} |
... | ... |
@@ -170,10 +170,16 @@ class ContentSlickSliderImage extends \ContentElement |
170 | 170 |
} |
171 | 171 |
} |
172 | 172 |
|
173 |
+ if ($this->eSM_slick_addImageLink) |
|
174 |
+ { |
|
175 |
+ $this->Template->fullsize = $this->fullsize; |
|
176 |
+ $this->Template->imageLink = ($this->imageUrl ?: $this->singleSRC); |
|
177 |
+ } |
|
178 |
+ |
|
173 | 179 |
if ($this->eSM_addText) |
174 | 180 |
{ |
175 | 181 |
$this->Template->text = nl2br($this->eSM_slick_text); |
176 |
- $this->Template->link = nl2br($this->eSM_slick_url); |
|
182 |
+ $this->Template->link = $this->eSM_slick_url; |
|
177 | 183 |
} |
178 | 184 |
|
179 | 185 |
} |
... | ... |
@@ -31,14 +31,27 @@ class ContentSlickSliderImage extends \ContentElement |
31 | 31 |
{ |
32 | 32 |
$return = ''; |
33 | 33 |
|
34 |
- if ($this->singleSRC) |
|
34 |
+ if ($this->multiSRC) |
|
35 | 35 |
{ |
36 |
- $objFile = \FilesModel::findByUuid($this->singleSRC); |
|
37 | 36 |
|
38 |
- if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) |
|
37 |
+ $source = \StringUtil::deserialize($this->multiSRC); |
|
38 |
+ $objFiles = \FilesModel::findMultipleByUuids($source); |
|
39 |
+ |
|
40 |
+ if ($objFiles !== null) |
|
39 | 41 |
{ |
40 |
- $src = \System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . $objFile->path, array(100,40,'crop'))->getUrl(TL_ROOT); |
|
41 |
- $return = '<img src="'.$src.'">'; |
|
42 |
+ foreach ($objFiles as $file) |
|
43 |
+ { |
|
44 |
+ if (is_file(TL_ROOT . '/' . $file->path)) |
|
45 |
+ { |
|
46 |
+ if (in_array($file->extension, array_map('trim', explode(',', \Config::get('validImageTypes'))))) |
|
47 |
+ { |
|
48 |
+ $src = \System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . $file->path, array(66, 55, 'crop'))->getUrl(TL_ROOT); |
|
49 |
+ $return .= '<img src="' . $src . '">'."\n"; |
|
50 |
+ } else if (in_array($file->extension, array_map('trim', array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv', 'm4a', 'mp3', 'wma', 'mpeg', 'wav', 'ogg')))) { |
|
51 |
+ $return .= '<span>'.$GLOBALS['TL_LANG']['tl_content']['singleSRC'][0].': <a href="'.$file->path.'" target="_blank">'.$file->name.'</a></span>'."\n"; |
|
52 |
+ } |
|
53 |
+ } |
|
54 |
+ } |
|
42 | 55 |
} |
43 | 56 |
} |
44 | 57 |
|
... | ... |
@@ -63,14 +63,33 @@ class ContentSlickSliderImage extends \ContentElement |
63 | 63 |
$this->Template = $objTemplate; |
64 | 64 |
} |
65 | 65 |
|
66 |
- if ($this->singleSRC) |
|
66 |
+ if ($this->multiSRC) |
|
67 | 67 |
{ |
68 | 68 |
|
69 |
- $objFile = \FilesModel::findByUuid($this->singleSRC); |
|
69 |
+ $source = \StringUtil::deserialize($this->multiSRC); |
|
70 |
+ $objFiles = \FilesModel::findMultipleByUuids($source); |
|
70 | 71 |
|
71 |
- if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) |
|
72 |
+ if ($objFiles !== null) { |
|
73 |
+ $imageFiles = array(); |
|
74 |
+ $videoFiles = array(); |
|
75 |
+ |
|
76 |
+ foreach ($objFiles as $file) { |
|
77 |
+ if (is_file(TL_ROOT . '/' . $file->path)) |
|
78 |
+ { |
|
79 |
+ if (in_array($file->extension, array_map('trim', explode(',', \Config::get('validImageTypes'))))) |
|
80 |
+ { |
|
81 |
+ $imageFiles[] = $file; |
|
82 |
+ } else if (in_array($file->extension, array_map('trim', array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv', 'm4a', 'mp3', 'wma', 'mpeg', 'wav', 'ogg')))) |
|
83 |
+ { |
|
84 |
+ $videoFiles[] = $file; |
|
85 |
+ } |
|
86 |
+ } |
|
87 |
+ } |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ if (isset($imageFiles[0])) |
|
72 | 91 |
{ |
73 |
- $this->singleSRC = $objFile->path; |
|
92 |
+ $this->singleSRC = $imageFiles[0]->path; |
|
74 | 93 |
|
75 | 94 |
$this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size)); |
76 | 95 |
|
... | ... |
@@ -86,6 +105,7 @@ class ContentSlickSliderImage extends \ContentElement |
86 | 105 |
$backgroundStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }'; |
87 | 106 |
} |
88 | 107 |
|
108 |
+ |
|
89 | 109 |
$backgroundStyle .= '.slide_'.$this->id.' .slick-slider-slide-image { background-image: url(\''.$this->Template->src.'\');'; |
90 | 110 |
|
91 | 111 |
if ($this->eSM_slick_bgSize) { |
... | ... |
@@ -131,6 +151,10 @@ class ContentSlickSliderImage extends \ContentElement |
131 | 151 |
} |
132 | 152 |
|
133 | 153 |
} |
154 |
+ |
|
155 |
+ if (count($videoFiles)) { |
|
156 |
+ $this->Template->videoFiles = $videoFiles; |
|
157 |
+ } |
|
134 | 158 |
} |
135 | 159 |
|
136 | 160 |
if ($this->eSM_addText) |
... | ... |
@@ -133,7 +133,11 @@ class ContentSlickSliderImage extends \ContentElement |
133 | 133 |
} |
134 | 134 |
} |
135 | 135 |
|
136 |
- $this->Template->text = nl2br($this->eSM_slick_text); |
|
136 |
+ if ($this->eSM_addText) |
|
137 |
+ { |
|
138 |
+ $this->Template->text = nl2br($this->eSM_slick_text); |
|
139 |
+ $this->Template->link = nl2br($this->eSM_slick_url); |
|
140 |
+ } |
|
137 | 141 |
|
138 | 142 |
} |
139 | 143 |
|
... | ... |
@@ -74,36 +74,63 @@ class ContentSlickSliderImage extends \ContentElement |
74 | 74 |
|
75 | 75 |
$this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size)); |
76 | 76 |
|
77 |
+ $backgroundStyle = ''; |
|
78 |
+ |
|
77 | 79 |
if ($this->eSM_slick_minHeight) { |
78 | 80 |
if ($this->eSM_slick_bgSize && $this->eSM_slick_bgSize == 'auto auto') { |
79 |
- $this->Template->minHeight = $this->Template->picture['img']['height'] . 'px'; |
|
81 |
+ $minHeight = $this->Template->picture['img']['height'] . 'px'; |
|
80 | 82 |
} else |
81 | 83 |
{ |
82 |
- $this->Template->minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%'; |
|
84 |
+ $minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%'; |
|
83 | 85 |
} |
86 |
+ $backgroundStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }'; |
|
84 | 87 |
} |
85 |
- } |
|
86 | 88 |
|
87 |
- $backgroundStyle = 'background-image: url(\''.$this->Template->src.'\');'; |
|
89 |
+ $backgroundStyle .= '.slide_'.$this->id.' .slick-slider-slide-image { background-image: url(\''.$this->Template->src.'\');'; |
|
88 | 90 |
|
89 |
- if ($this->eSM_slick_bgSize) { |
|
90 |
- $backgroundStyle .= 'background-size: ' . $this->eSM_slick_bgSize . ';'; |
|
91 |
- } else { |
|
92 |
- $backgroundStyle .= 'background-size: cover;'; |
|
93 |
- } |
|
94 |
- if ($this->eSM_slick_bgPosition) { |
|
95 |
- $backgroundStyle .= 'background-position: ' . $this->eSM_slick_bgPosition . ';'; |
|
96 |
- } else { |
|
97 |
- $backgroundStyle .= 'background-position: 0 0;'; |
|
98 |
- } |
|
99 |
- if ($this->eSM_slick_bgOpacity) { |
|
100 |
- $backgroundStyle .= 'opacity:' . $this->eSM_slick_bgOpacity/100 . ';'; |
|
101 |
- } |
|
102 |
- if ($this->eSM_slick_bgRepeat) { |
|
103 |
- $backgroundStyle .= 'background-repeat: ' . $this->eSM_slick_bgRepeat . ';'; |
|
104 |
- } |
|
91 |
+ if ($this->eSM_slick_bgSize) { |
|
92 |
+ $backgroundStyle .= 'background-size: ' . $this->eSM_slick_bgSize . ';'; |
|
93 |
+ } else { |
|
94 |
+ $backgroundStyle .= 'background-size: cover;'; |
|
95 |
+ } |
|
96 |
+ if ($this->eSM_slick_bgPosition) { |
|
97 |
+ $backgroundStyle .= 'background-position: ' . $this->eSM_slick_bgPosition . ';'; |
|
98 |
+ } else { |
|
99 |
+ $backgroundStyle .= 'background-position: 0 0;'; |
|
100 |
+ } |
|
101 |
+ if ($this->eSM_slick_bgOpacity) { |
|
102 |
+ $backgroundStyle .= 'opacity:' . $this->eSM_slick_bgOpacity/100 . ';'; |
|
103 |
+ } |
|
104 |
+ if ($this->eSM_slick_bgRepeat) { |
|
105 |
+ $backgroundStyle .= 'background-repeat: ' . $this->eSM_slick_bgRepeat . ';'; |
|
106 |
+ } |
|
107 |
+ |
|
108 |
+ $this->Template->backgroundStyle = $backgroundStyle.' }'; |
|
109 |
+ |
|
110 |
+ // Responsive handling |
|
111 |
+ if ($this->Template->picture['sources'] && is_array($this->Template->picture['sources'])) |
|
112 |
+ { |
|
113 |
+ $backgroundStyleResponsive = ''; |
|
114 |
+ foreach ($this->Template->picture['sources'] as $srcSet) |
|
115 |
+ { |
|
116 |
+ $srcSetStyle = '.slide_'.$this->id.' .slick-slider-slide-image { background-image: url(\''.$srcSet['src'].'\'); }'; |
|
117 |
+ |
|
118 |
+ if ($this->eSM_slick_minHeight) { |
|
119 |
+ if ($this->eSM_slick_bgSize && $this->eSM_slick_bgSize == 'auto auto') { |
|
120 |
+ $minHeight = $srcSet['height'] . 'px'; |
|
121 |
+ } else |
|
122 |
+ { |
|
123 |
+ $minHeight = round($srcSet['height'] / $srcSet['width'] * 100) . '%'; |
|
124 |
+ } |
|
125 |
+ $srcSetStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }'; |
|
126 |
+ } |
|
127 |
+ |
|
128 |
+ $backgroundStyleResponsive .= '@media screen and '.$srcSet['media'].' { '.$srcSetStyle.' }'; |
|
129 |
+ } |
|
130 |
+ $this->Template->backgroundStyleResponsive = $backgroundStyleResponsive; |
|
131 |
+ } |
|
105 | 132 |
|
106 |
- $this->Template->backgroundStyle = $backgroundStyle; |
|
133 |
+ } |
|
107 | 134 |
} |
108 | 135 |
|
109 | 136 |
$this->Template->text = nl2br($this->eSM_slick_text); |
... | ... |
@@ -10,7 +10,6 @@ |
10 | 10 |
|
11 | 11 |
namespace eSM_slick; |
12 | 12 |
|
13 |
- |
|
14 | 13 |
/** |
15 | 14 |
* Front end content element slick slider start. |
16 | 15 |
*/ |
... | ... |
@@ -24,6 +23,32 @@ class ContentSlickSliderImage extends \ContentElement |
24 | 23 |
protected $strTemplate = 'ce_slick_slider_image'; |
25 | 24 |
|
26 | 25 |
/** |
26 |
+ * @return string |
|
27 |
+ */ |
|
28 |
+ public function generate() |
|
29 |
+ { |
|
30 |
+ if (TL_MODE == 'BE') |
|
31 |
+ { |
|
32 |
+ $return = ''; |
|
33 |
+ |
|
34 |
+ if ($this->singleSRC) |
|
35 |
+ { |
|
36 |
+ $objFile = \FilesModel::findByUuid($this->singleSRC); |
|
37 |
+ |
|
38 |
+ if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) |
|
39 |
+ { |
|
40 |
+ $src = \System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . $objFile->path, array(100,40,'crop'))->getUrl(TL_ROOT); |
|
41 |
+ $return = '<img src="'.$src.'">'; |
|
42 |
+ } |
|
43 |
+ } |
|
44 |
+ |
|
45 |
+ return $return; |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ return parent::generate(); |
|
49 |
+ } |
|
50 |
+ |
|
51 |
+ /** |
|
27 | 52 |
* Generate the content element |
28 | 53 |
*/ |
29 | 54 |
protected function compile() |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,88 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * Slick slider for Contao |
|
5 |
+ * |
|
6 |
+ * Copyright (c) 2016 Benjamin Roth |
|
7 |
+ * |
|
8 |
+ * @license LGPL-3.0+ |
|
9 |
+ */ |
|
10 |
+ |
|
11 |
+namespace eSM_slick; |
|
12 |
+ |
|
13 |
+ |
|
14 |
+/** |
|
15 |
+ * Front end content element slick slider start. |
|
16 |
+ */ |
|
17 |
+class ContentSlickSliderImage extends \ContentElement |
|
18 |
+{ |
|
19 |
+ |
|
20 |
+ /** |
|
21 |
+ * Template |
|
22 |
+ * @var string |
|
23 |
+ */ |
|
24 |
+ protected $strTemplate = 'ce_slick_slider_image'; |
|
25 |
+ |
|
26 |
+ /** |
|
27 |
+ * Generate the content element |
|
28 |
+ */ |
|
29 |
+ protected function compile() |
|
30 |
+ { |
|
31 |
+ if (TL_MODE == 'BE') |
|
32 |
+ { |
|
33 |
+ $this->strTemplate = 'be_wildcard'; |
|
34 |
+ |
|
35 |
+ /** @var \BackendTemplate|object $objTemplate */ |
|
36 |
+ $objTemplate = new \BackendTemplate($this->strTemplate); |
|
37 |
+ |
|
38 |
+ $this->Template = $objTemplate; |
|
39 |
+ } |
|
40 |
+ |
|
41 |
+ if ($this->singleSRC) |
|
42 |
+ { |
|
43 |
+ |
|
44 |
+ $objFile = \FilesModel::findByUuid($this->singleSRC); |
|
45 |
+ |
|
46 |
+ if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) |
|
47 |
+ { |
|
48 |
+ $this->singleSRC = $objFile->path; |
|
49 |
+ |
|
50 |
+ $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size)); |
|
51 |
+ |
|
52 |
+ if ($this->eSM_slick_minHeight) { |
|
53 |
+ if ($this->eSM_slick_bgSize && $this->eSM_slick_bgSize == 'auto auto') { |
|
54 |
+ $this->Template->minHeight = $this->Template->picture['img']['height'] . 'px'; |
|
55 |
+ } else |
|
56 |
+ { |
|
57 |
+ $this->Template->minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%'; |
|
58 |
+ } |
|
59 |
+ } |
|
60 |
+ } |
|
61 |
+ |
|
62 |
+ $backgroundStyle = 'background-image: url(\''.$this->Template->src.'\');'; |
|
63 |
+ |
|
64 |
+ if ($this->eSM_slick_bgSize) { |
|
65 |
+ $backgroundStyle .= 'background-size: ' . $this->eSM_slick_bgSize . ';'; |
|
66 |
+ } else { |
|
67 |
+ $backgroundStyle .= 'background-size: cover;'; |
|
68 |
+ } |
|
69 |
+ if ($this->eSM_slick_bgPosition) { |
|
70 |
+ $backgroundStyle .= 'background-position: ' . $this->eSM_slick_bgPosition . ';'; |
|
71 |
+ } else { |
|
72 |
+ $backgroundStyle .= 'background-position: 0 0;'; |
|
73 |
+ } |
|
74 |
+ if ($this->eSM_slick_bgOpacity) { |
|
75 |
+ $backgroundStyle .= 'opacity:' . $this->eSM_slick_bgOpacity/100 . ';'; |
|
76 |
+ } |
|
77 |
+ if ($this->eSM_slick_bgRepeat) { |
|
78 |
+ $backgroundStyle .= 'background-repeat: ' . $this->eSM_slick_bgRepeat . ';'; |
|
79 |
+ } |
|
80 |
+ |
|
81 |
+ $this->Template->backgroundStyle = $backgroundStyle; |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ $this->Template->text = nl2br($this->eSM_slick_text); |
|
85 |
+ |
|
86 |
+ } |
|
87 |
+ |
|
88 |
+} |