Browse code

Refactor and rewrite as contao bundle

Benjamin Roth authored on04/11/2022 22:32:32
Showing1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,136 +0,0 @@
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_swiper;
12
-
13
-
14
-/**
15
- * Front end content element swiper slide start.
16
- */
17
-class ContentSwiperSliderSlideStart 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->eSM_addImage && $this->multiSRC)
43
-    {
44
-
45
-      $source = \StringUtil::deserialize($this->multiSRC);
46
-      $objFiles = \FilesModel::findMultipleByUuids($source);
47
-
48
-      $imageFiles = array();
49
-      $videoFiles = array();
50
-
51
-      if ($objFiles !== null) {
52
-
53
-        foreach ($objFiles as $file) {
54
-          if (is_file(TL_ROOT . '/' . $file->path))
55
-          {
56
-            if (in_array($file->extension, array_map('trim', explode(',', \Config::get('validImageTypes')))))
57
-            {
58
-              $imageFiles[] = $file;
59
-            } else if (in_array($file->extension, array_map('trim', array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv', 'm4a', 'mp3', 'wma', 'mpeg', 'wav', 'ogg'))))
60
-            {
61
-              $videoFiles[] = $file;
62
-            }
63
-          }
64
-        }
65
-      }
66
-
67
-      if (isset($imageFiles[0]))
68
-      {
69
-        $this->singleSRC = $imageFiles[0]->path;
70
-
71
-        $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
72
-
73
-        $backgroundStyle = '';
74
-
75
-        if ($this->eSM_slider_minHeight) {
76
-          if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto') {
77
-            $minHeight = $this->Template->picture['img']['height'] . 'px';
78
-          } else
79
-          {
80
-            $minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%';
81
-          }
82
-          $backgroundStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
83
-        }
84
-
85
-
86
-        $backgroundStyle .= '.slide_'.$this->id.' .swiper-background { background-image: url(\''.$this->Template->src.'\');';
87
-
88
-        if ($this->eSM_slider_bgSize) {
89
-          $backgroundStyle .= 'background-size: ' . $this->eSM_slider_bgSize . ';';
90
-        } else {
91
-          $backgroundStyle .= 'background-size: cover;';
92
-        }
93
-        if ($this->eSM_slider_bgPosition) {
94
-          $backgroundStyle .= 'background-position: ' . $this->eSM_slider_bgPosition . ';';
95
-        } else {
96
-          $backgroundStyle .= 'background-position: 0 0;';
97
-        }
98
-        if ($this->eSM_slider_bgOpacity) {
99
-          $backgroundStyle .= 'opacity:' . $this->eSM_slider_bgOpacity/100 . ';';
100
-        }
101
-        if ($this->eSM_slider_bgRepeat) {
102
-          $backgroundStyle .= 'background-repeat: ' . $this->eSM_slider_bgRepeat . ';';
103
-        }
104
-
105
-        $this->Template->backgroundStyle = $backgroundStyle.' }';
106
-
107
-        // Responsive handling
108
-        if ($this->Template->picture['sources'] && is_array($this->Template->picture['sources']))
109
-        {
110
-          $backgroundStyleResponsive = '';
111
-          foreach ($this->Template->picture['sources'] as $srcSet)
112
-          {
113
-            $srcSetStyle = '.slide_'.$this->id.' .swiper-slide-image { background-image: url(\''.$srcSet['src'].'\'); }';
114
-
115
-            if ($this->eSM_slider_minHeight) {
116
-              if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto') {
117
-                $minHeight = $srcSet['height'] . 'px';
118
-              } else
119
-              {
120
-                $minHeight = round($srcSet['height'] / $srcSet['width'] * 100) . '%';
121
-              }
122
-              $srcSetStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
123
-            }
124
-
125
-            $backgroundStyleResponsive .= '@media screen and '.$srcSet['media'].' { '.$srcSetStyle.' }';
126
-          }
127
-          $this->Template->backgroundStyleResponsive = $backgroundStyleResponsive;
128
-        }
129
-
130
-      }
131
-
132
-      $this->Template->videoFiles = $videoFiles;
133
-    }
134
-
135
-  }
136
-}
Browse code

Fix for error if image or video isn't available anymore

Benjamin Roth authored on14/03/2021 15:58:54
Showing1 changed files
... ...
@@ -129,9 +129,7 @@ class ContentSwiperSliderSlideStart extends \ContentElement
129 129
 
130 130
       }
131 131
 
132
-      if (count($videoFiles)) {
133
-        $this->Template->videoFiles = $videoFiles;
134
-      }
132
+      $this->Template->videoFiles = $videoFiles;
135 133
     }
136 134
 
137 135
   }
Browse code

Initial commit

Benjamin Roth authored on19/05/2020 21:59:44
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,138 @@
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_swiper;
12
+
13
+
14
+/**
15
+ * Front end content element swiper slide start.
16
+ */
17
+class ContentSwiperSliderSlideStart 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->eSM_addImage && $this->multiSRC)
43
+    {
44
+
45
+      $source = \StringUtil::deserialize($this->multiSRC);
46
+      $objFiles = \FilesModel::findMultipleByUuids($source);
47
+
48
+      $imageFiles = array();
49
+      $videoFiles = array();
50
+
51
+      if ($objFiles !== null) {
52
+
53
+        foreach ($objFiles as $file) {
54
+          if (is_file(TL_ROOT . '/' . $file->path))
55
+          {
56
+            if (in_array($file->extension, array_map('trim', explode(',', \Config::get('validImageTypes')))))
57
+            {
58
+              $imageFiles[] = $file;
59
+            } else if (in_array($file->extension, array_map('trim', array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv', 'm4a', 'mp3', 'wma', 'mpeg', 'wav', 'ogg'))))
60
+            {
61
+              $videoFiles[] = $file;
62
+            }
63
+          }
64
+        }
65
+      }
66
+
67
+      if (isset($imageFiles[0]))
68
+      {
69
+        $this->singleSRC = $imageFiles[0]->path;
70
+
71
+        $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
72
+
73
+        $backgroundStyle = '';
74
+
75
+        if ($this->eSM_slider_minHeight) {
76
+          if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto') {
77
+            $minHeight = $this->Template->picture['img']['height'] . 'px';
78
+          } else
79
+          {
80
+            $minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%';
81
+          }
82
+          $backgroundStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
83
+        }
84
+
85
+
86
+        $backgroundStyle .= '.slide_'.$this->id.' .swiper-background { background-image: url(\''.$this->Template->src.'\');';
87
+
88
+        if ($this->eSM_slider_bgSize) {
89
+          $backgroundStyle .= 'background-size: ' . $this->eSM_slider_bgSize . ';';
90
+        } else {
91
+          $backgroundStyle .= 'background-size: cover;';
92
+        }
93
+        if ($this->eSM_slider_bgPosition) {
94
+          $backgroundStyle .= 'background-position: ' . $this->eSM_slider_bgPosition . ';';
95
+        } else {
96
+          $backgroundStyle .= 'background-position: 0 0;';
97
+        }
98
+        if ($this->eSM_slider_bgOpacity) {
99
+          $backgroundStyle .= 'opacity:' . $this->eSM_slider_bgOpacity/100 . ';';
100
+        }
101
+        if ($this->eSM_slider_bgRepeat) {
102
+          $backgroundStyle .= 'background-repeat: ' . $this->eSM_slider_bgRepeat . ';';
103
+        }
104
+
105
+        $this->Template->backgroundStyle = $backgroundStyle.' }';
106
+
107
+        // Responsive handling
108
+        if ($this->Template->picture['sources'] && is_array($this->Template->picture['sources']))
109
+        {
110
+          $backgroundStyleResponsive = '';
111
+          foreach ($this->Template->picture['sources'] as $srcSet)
112
+          {
113
+            $srcSetStyle = '.slide_'.$this->id.' .swiper-slide-image { background-image: url(\''.$srcSet['src'].'\'); }';
114
+
115
+            if ($this->eSM_slider_minHeight) {
116
+              if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto') {
117
+                $minHeight = $srcSet['height'] . 'px';
118
+              } else
119
+              {
120
+                $minHeight = round($srcSet['height'] / $srcSet['width'] * 100) . '%';
121
+              }
122
+              $srcSetStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
123
+            }
124
+
125
+            $backgroundStyleResponsive .= '@media screen and '.$srcSet['media'].' { '.$srcSetStyle.' }';
126
+          }
127
+          $this->Template->backgroundStyleResponsive = $backgroundStyleResponsive;
128
+        }
129
+
130
+      }
131
+
132
+      if (count($videoFiles)) {
133
+        $this->Template->videoFiles = $videoFiles;
134
+      }
135
+    }
136
+
137
+  }
138
+}