Browse code

Always set empty arrays for images and videos

Benjamin Roth authored on13/01/2020 17:03:21
Showing1 changed files
... ...
@@ -45,9 +45,10 @@ class ContentSlickSliderSlideStart extends \ContentElement
45 45
       $source = \StringUtil::deserialize($this->multiSRC);
46 46
       $objFiles = \FilesModel::findMultipleByUuids($source);
47 47
 
48
+      $imageFiles = array();
49
+      $videoFiles = array();
50
+
48 51
       if ($objFiles !== null) {
49
-        $imageFiles = array();
50
-        $videoFiles = array();
51 52
 
52 53
         foreach ($objFiles as $file) {
53 54
           if (is_file(TL_ROOT . '/' . $file->path))
Browse code

Fix slide envelope background

Benjamin Roth authored on27/11/2019 10:51:32
Showing1 changed files
... ...
@@ -82,7 +82,7 @@ class ContentSlickSliderSlideStart extends \ContentElement
82 82
         }
83 83
 
84 84
 
85
-        $backgroundStyle .= '.slide_'.$this->id.' .slick-slider-slide-image { background-image: url(\''.$this->Template->src.'\');';
85
+        $backgroundStyle .= '.slide_'.$this->id.' .slick-slider-background { background-image: url(\''.$this->Template->src.'\');';
86 86
 
87 87
         if ($this->eSM_slick_bgSize) {
88 88
           $backgroundStyle .= 'background-size: ' . $this->eSM_slick_bgSize . ';';
Browse code

Allow background videos

Benjamin Roth authored on06/06/2019 19:27:31
Showing1 changed files
... ...
@@ -39,14 +39,33 @@ class ContentSlickSliderSlideStart extends \ContentElement
39 39
 			$this->Template = $objTemplate;
40 40
 		}
41 41
 
42
-    if ($this->singleSRC)
42
+    if ($this->eSM_addImage && $this->multiSRC)
43 43
     {
44 44
 
45
-      $objFile = \FilesModel::findByUuid($this->singleSRC);
45
+      $source = \StringUtil::deserialize($this->multiSRC);
46
+      $objFiles = \FilesModel::findMultipleByUuids($source);
46 47
 
47
-      if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path))
48
+      if ($objFiles !== null) {
49
+        $imageFiles = array();
50
+        $videoFiles = array();
51
+
52
+        foreach ($objFiles as $file) {
53
+          if (is_file(TL_ROOT . '/' . $file->path))
54
+          {
55
+            if (in_array($file->extension, array_map('trim', explode(',', \Config::get('validImageTypes')))))
56
+            {
57
+              $imageFiles[] = $file;
58
+            } else if (in_array($file->extension, array_map('trim', array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv', 'm4a', 'mp3', 'wma', 'mpeg', 'wav', 'ogg'))))
59
+            {
60
+              $videoFiles[] = $file;
61
+            }
62
+          }
63
+        }
64
+      }
65
+
66
+      if (isset($imageFiles[0]))
48 67
       {
49
-        $this->singleSRC = $objFile->path;
68
+        $this->singleSRC = $imageFiles[0]->path;
50 69
 
51 70
         $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
52 71
 
... ...
@@ -108,6 +127,10 @@ class ContentSlickSliderSlideStart extends \ContentElement
108 127
         }
109 128
 
110 129
       }
130
+
131
+      if (count($videoFiles)) {
132
+        $this->Template->videoFiles = $videoFiles;
133
+      }
111 134
     }
112 135
 
113 136
   }
Browse code

Support responsive images through Contao source sets

Benjamin Roth authored on01/08/2018 08:45:04
Showing1 changed files
... ...
@@ -50,36 +50,64 @@ class ContentSlickSliderSlideStart extends \ContentElement
50 50
 
51 51
         $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
52 52
 
53
+        $backgroundStyle = '';
54
+
53 55
         if ($this->eSM_slick_minHeight) {
54 56
           if ($this->eSM_slick_bgSize && $this->eSM_slick_bgSize == 'auto auto') {
55
-            $this->Template->minHeight = $this->Template->picture['img']['height'] . 'px';
57
+            $minHeight = $this->Template->picture['img']['height'] . 'px';
56 58
           } else
57 59
           {
58
-            $this->Template->minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%';
60
+            $minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%';
59 61
           }
62
+          $backgroundStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
60 63
         }
61
-      }
62 64
 
63
-      $backgroundStyle = 'background-image: url(\''.$this->Template->src.'\');';
64 65
 
65
-      if ($this->eSM_slick_bgSize) {
66
-        $backgroundStyle .= 'background-size: ' . $this->eSM_slick_bgSize . ';';
67
-      } else {
68
-        $backgroundStyle .= 'background-size: cover;';
69
-      }
70
-      if ($this->eSM_slick_bgPosition) {
71
-        $backgroundStyle .= 'background-position: ' . $this->eSM_slick_bgPosition . ';';
72
-      } else {
73
-        $backgroundStyle .= 'background-position: 0 0;';
74
-      }
75
-      if ($this->eSM_slick_bgOpacity) {
76
-        $backgroundStyle .= 'opacity:' . $this->eSM_slick_bgOpacity/100 . ';';
77
-      }
78
-      if ($this->eSM_slick_bgRepeat) {
79
-        $backgroundStyle .= 'background-repeat: ' . $this->eSM_slick_bgRepeat . ';';
80
-      }
66
+        $backgroundStyle .= '.slide_'.$this->id.' .slick-slider-slide-image { background-image: url(\''.$this->Template->src.'\');';
81 67
 
82
-      $this->Template->backgroundStyle = $backgroundStyle;
68
+        if ($this->eSM_slick_bgSize) {
69
+          $backgroundStyle .= 'background-size: ' . $this->eSM_slick_bgSize . ';';
70
+        } else {
71
+          $backgroundStyle .= 'background-size: cover;';
72
+        }
73
+        if ($this->eSM_slick_bgPosition) {
74
+          $backgroundStyle .= 'background-position: ' . $this->eSM_slick_bgPosition . ';';
75
+        } else {
76
+          $backgroundStyle .= 'background-position: 0 0;';
77
+        }
78
+        if ($this->eSM_slick_bgOpacity) {
79
+          $backgroundStyle .= 'opacity:' . $this->eSM_slick_bgOpacity/100 . ';';
80
+        }
81
+        if ($this->eSM_slick_bgRepeat) {
82
+          $backgroundStyle .= 'background-repeat: ' . $this->eSM_slick_bgRepeat . ';';
83
+        }
84
+
85
+        $this->Template->backgroundStyle = $backgroundStyle.' }';
86
+
87
+        // Responsive handling
88
+        if ($this->Template->picture['sources'] && is_array($this->Template->picture['sources']))
89
+        {
90
+          $backgroundStyleResponsive = '';
91
+          foreach ($this->Template->picture['sources'] as $srcSet)
92
+          {
93
+            $srcSetStyle = '.slide_'.$this->id.' .slick-slider-slide-image { background-image: url(\''.$srcSet['src'].'\'); }';
94
+
95
+            if ($this->eSM_slick_minHeight) {
96
+              if ($this->eSM_slick_bgSize && $this->eSM_slick_bgSize == 'auto auto') {
97
+                $minHeight = $srcSet['height'] . 'px';
98
+              } else
99
+              {
100
+                $minHeight = round($srcSet['height'] / $srcSet['width'] * 100) . '%';
101
+              }
102
+              $srcSetStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
103
+            }
104
+
105
+            $backgroundStyleResponsive .= '@media screen and '.$srcSet['media'].' { '.$srcSetStyle.' }';
106
+          }
107
+          $this->Template->backgroundStyleResponsive = $backgroundStyleResponsive;
108
+        }
109
+
110
+      }
83 111
     }
84 112
 
85 113
   }
Browse code

Use fixed height for original source bgSize setting

Benjamin Roth authored on07/05/2018 12:42:50
Showing1 changed files
... ...
@@ -51,8 +51,12 @@ class ContentSlickSliderSlideStart extends \ContentElement
51 51
         $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
52 52
 
53 53
         if ($this->eSM_slick_minHeight) {
54
-
55
-          $this->Template->minHeight = round($this->Template->picture['img']['height']/$this->Template->picture['img']['width']*100).'%';
54
+          if ($this->eSM_slick_bgSize && $this->eSM_slick_bgSize == 'auto auto') {
55
+            $this->Template->minHeight = $this->Template->picture['img']['height'] . 'px';
56
+          } else
57
+          {
58
+            $this->Template->minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%';
59
+          }
56 60
         }
57 61
       }
58 62
 
Browse code

Add background-repeat setting to slide

Benjamin Roth authored on07/05/2018 12:21:13
Showing1 changed files
... ...
@@ -71,6 +71,9 @@ class ContentSlickSliderSlideStart extends \ContentElement
71 71
       if ($this->eSM_slick_bgOpacity) {
72 72
         $backgroundStyle .= 'opacity:' . $this->eSM_slick_bgOpacity/100 . ';';
73 73
       }
74
+      if ($this->eSM_slick_bgRepeat) {
75
+        $backgroundStyle .= 'background-repeat: ' . $this->eSM_slick_bgRepeat . ';';
76
+      }
74 77
 
75 78
       $this->Template->backgroundStyle = $backgroundStyle;
76 79
     }
Browse code

Calculate the min height correctly

Benjamin Roth authored on07/05/2018 11:48:59
Showing1 changed files
... ...
@@ -49,6 +49,11 @@ class ContentSlickSliderSlideStart extends \ContentElement
49 49
         $this->singleSRC = $objFile->path;
50 50
 
51 51
         $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
52
+
53
+        if ($this->eSM_slick_minHeight) {
54
+
55
+          $this->Template->minHeight = round($this->Template->picture['img']['height']/$this->Template->picture['img']['width']*100).'%';
56
+        }
52 57
       }
53 58
 
54 59
       $backgroundStyle = 'background-image: url(\''.$this->Template->src.'\');';
... ...
@@ -67,10 +72,6 @@ class ContentSlickSliderSlideStart extends \ContentElement
67 72
         $backgroundStyle .= 'opacity:' . $this->eSM_slick_bgOpacity/100 . ';';
68 73
       }
69 74
 
70
-      if ($this->eSM_slick_minHeight) {
71
-        $this->Template->minHeight = round($this->Template->height/$this->Template->width*100).'%';
72
-      }
73
-
74 75
       $this->Template->backgroundStyle = $backgroundStyle;
75 76
     }
76 77
 
Browse code

Add even more background options

Benjamin Roth authored on01/11/2017 16:54:37
Showing1 changed files
... ...
@@ -53,21 +53,21 @@ class ContentSlickSliderSlideStart extends \ContentElement
53 53
 
54 54
       $backgroundStyle = 'background-image: url(\''.$this->Template->src.'\');';
55 55
 
56
-      if ($this->eSM_slick_slide_bgSize) {
57
-        $backgroundStyle .= 'background-size: ' . $this->eSM_slick_slide_bgSize . ';';
56
+      if ($this->eSM_slick_bgSize) {
57
+        $backgroundStyle .= 'background-size: ' . $this->eSM_slick_bgSize . ';';
58 58
       } else {
59 59
         $backgroundStyle .= 'background-size: cover;';
60 60
       }
61
-      if ($this->eSM_slick_slide_bgPosition) {
62
-        $backgroundStyle .= 'background-position: ' . $this->eSM_slick_slide_bgPosition . ';';
61
+      if ($this->eSM_slick_bgPosition) {
62
+        $backgroundStyle .= 'background-position: ' . $this->eSM_slick_bgPosition . ';';
63 63
       } else {
64 64
         $backgroundStyle .= 'background-position: 0 0;';
65 65
       }
66
-      if ($this->eSM_slick_slide_bgOpacity) {
67
-        $backgroundStyle .= 'opacity:' . $this->eSM_slick_slide_bgOpacity/100 . ';';
66
+      if ($this->eSM_slick_bgOpacity) {
67
+        $backgroundStyle .= 'opacity:' . $this->eSM_slick_bgOpacity/100 . ';';
68 68
       }
69 69
 
70
-      if ($this->eSM_slick_slide_minHeight) {
70
+      if ($this->eSM_slick_minHeight) {
71 71
         $this->Template->minHeight = round($this->Template->height/$this->Template->width*100).'%';
72 72
       }
73 73
 
Browse code

Add more slide background options

Benjamin Roth authored on01/11/2017 15:50:43
Showing1 changed files
... ...
@@ -50,6 +50,28 @@ class ContentSlickSliderSlideStart extends \ContentElement
50 50
 
51 51
         $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
52 52
       }
53
+
54
+      $backgroundStyle = 'background-image: url(\''.$this->Template->src.'\');';
55
+
56
+      if ($this->eSM_slick_slide_bgSize) {
57
+        $backgroundStyle .= 'background-size: ' . $this->eSM_slick_slide_bgSize . ';';
58
+      } else {
59
+        $backgroundStyle .= 'background-size: cover;';
60
+      }
61
+      if ($this->eSM_slick_slide_bgPosition) {
62
+        $backgroundStyle .= 'background-position: ' . $this->eSM_slick_slide_bgPosition . ';';
63
+      } else {
64
+        $backgroundStyle .= 'background-position: 0 0;';
65
+      }
66
+      if ($this->eSM_slick_slide_bgOpacity) {
67
+        $backgroundStyle .= 'opacity:' . $this->eSM_slick_slide_bgOpacity/100 . ';';
68
+      }
69
+
70
+      if ($this->eSM_slick_slide_minHeight) {
71
+        $this->Template->minHeight = round($this->Template->height/$this->Template->width*100).'%';
72
+      }
73
+
74
+      $this->Template->backgroundStyle = $backgroundStyle;
53 75
     }
54 76
 
55 77
   }
Browse code

Initial commit

Benjamin Roth authored on16/02/2017 11:35:38
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,56 @@
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 ContentSlickSliderSlideStart extends \ContentElement
18
+{
19
+
20
+	/**
21
+	 * Template
22
+	 * @var string
23
+	 */
24
+	protected $strTemplate = 'slide_start_default';
25
+
26
+
27
+	/**
28
+	 * Generate the content element
29
+	 */
30
+	protected function compile()
31
+	{
32
+		if (TL_MODE == 'BE')
33
+		{
34
+			$this->strTemplate = 'be_wildcard';
35
+
36
+			/** @var \BackendTemplate|object $objTemplate */
37
+			$objTemplate = new \BackendTemplate($this->strTemplate);
38
+
39
+			$this->Template = $objTemplate;
40
+		}
41
+
42
+    if ($this->singleSRC)
43
+    {
44
+
45
+      $objFile = \FilesModel::findByUuid($this->singleSRC);
46
+
47
+      if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path))
48
+      {
49
+        $this->singleSRC = $objFile->path;
50
+
51
+        $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
52
+      }
53
+    }
54
+
55
+  }
56
+}