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,199 +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
- * Front end content element swiper image slide.
15
- */
16
-class ContentSwiperSliderImage extends \ContentElement
17
-{
18
-
19
-	/**
20
-	 * Template
21
-	 * @var string
22
-	 */
23
-	protected $strTemplate = 'ce_swiper_slider_image';
24
-
25
-  /**
26
-   * @return string
27
-   */
28
-  public function generate()
29
-  {
30
-    if (TL_MODE == 'BE')
31
-    {
32
-      $return = '';
33
-
34
-      if ($this->multiSRC)
35
-      {
36
-
37
-        $source = \StringUtil::deserialize($this->multiSRC);
38
-        $objFiles = \FilesModel::findMultipleByUuids($source);
39
-
40
-        if ($objFiles !== null)
41
-        {
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
-          }
55
-        }
56
-      }
57
-
58
-      return $return;
59
-    }
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
-
71
-    return parent::generate();
72
-  }
73
-
74
-  /**
75
-   * Generate the content element
76
-   */
77
-  protected function compile()
78
-  {
79
-    if (TL_MODE == 'BE')
80
-    {
81
-      $this->strTemplate = 'be_wildcard';
82
-
83
-      /** @var \BackendTemplate|object $objTemplate */
84
-      $objTemplate = new \BackendTemplate($this->strTemplate);
85
-
86
-      $this->Template = $objTemplate;
87
-    }
88
-
89
-    if ($this->multiSRC)
90
-    {
91
-
92
-      $source = \StringUtil::deserialize($this->multiSRC);
93
-      $objFiles = \FilesModel::findMultipleByUuids($source);
94
-
95
-      $imageFiles = array();
96
-      $videoFiles = array();
97
-
98
-      if ($objFiles !== null) {
99
-
100
-        foreach ($objFiles as $file) {
101
-          if (is_file(TL_ROOT . '/' . $file->path))
102
-          {
103
-            if (in_array($file->extension, array_map('trim', explode(',', \Config::get('validImageTypes')))))
104
-            {
105
-              $imageFiles[] = $file;
106
-            } else if (in_array($file->extension, array_map('trim', array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv', 'm4a', 'mp3', 'wma', 'mpeg', 'wav', 'ogg'))))
107
-            {
108
-              $videoFiles[] = $file;
109
-            }
110
-          }
111
-        }
112
-      }
113
-
114
-      if (isset($imageFiles[0]))
115
-      {
116
-        $this->singleSRC = $imageFiles[0]->path;
117
-
118
-        $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
119
-
120
-        $backgroundStyle = '';
121
-
122
-        if ($this->eSM_slider_minHeight) {
123
-          if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto') {
124
-            $minHeight = $this->Template->picture['img']['height'] . 'px';
125
-          } else
126
-          {
127
-            $minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%';
128
-          }
129
-          $backgroundStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
130
-        }
131
-
132
-
133
-        $backgroundStyle .= '.slide_'.$this->id.' .swiper-slide-image { background-image: url(\''.$this->Template->src.'\');';
134
-
135
-        if ($this->eSM_slider_bgSize) {
136
-          $backgroundStyle .= 'background-size: ' . $this->eSM_slider_bgSize . ';';
137
-        } else {
138
-          $backgroundStyle .= 'background-size: cover;';
139
-        }
140
-        if ($this->eSM_slider_bgPosition) {
141
-          $backgroundStyle .= 'background-position: ' . $this->eSM_slider_bgPosition . ';';
142
-        } else {
143
-          $backgroundStyle .= 'background-position: 0 0;';
144
-        }
145
-        if ($this->eSM_slider_bgOpacity) {
146
-          $backgroundStyle .= 'opacity:' . $this->eSM_slider_bgOpacity/100 . ';';
147
-        }
148
-        if ($this->eSM_slider_bgRepeat) {
149
-          $backgroundStyle .= 'background-repeat: ' . $this->eSM_slider_bgRepeat . ';';
150
-        }
151
-
152
-        $this->Template->backgroundStyle = $backgroundStyle.' }';
153
-
154
-        // Responsive handling
155
-        if ($this->Template->picture['sources'] && is_array($this->Template->picture['sources']))
156
-        {
157
-          $backgroundStyleResponsive = '';
158
-          foreach ($this->Template->picture['sources'] as $srcSet)
159
-          {
160
-            $srcSetStyle = '.slide_'.$this->id.' .swiper-slide-image { background-image: url(\''.$srcSet['src'].'\'); }';
161
-
162
-            if ($this->eSM_slider_minHeight) {
163
-              if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto') {
164
-                $minHeight = $srcSet['height'] . 'px';
165
-              } else
166
-              {
167
-                $minHeight = round($srcSet['height'] / $srcSet['width'] * 100) . '%';
168
-              }
169
-              $srcSetStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
170
-            }
171
-
172
-            $backgroundStyleResponsive .= '@media screen and '.$srcSet['media'].' { '.$srcSetStyle.' }';
173
-          }
174
-          $this->Template->backgroundStyleResponsive = $backgroundStyleResponsive;
175
-        }
176
-
177
-      }
178
-
179
-      if (count($videoFiles)) {
180
-        $this->Template->videoFiles = $videoFiles;
181
-      }
182
-    }
183
-
184
-    if ($this->eSM_slider_addImageLink)
185
-    {
186
-      $this->Template->lightboxId = 'image_slide_' . ($this->parentSlickId ?: 's'.$this->id);
187
-      $this->Template->fullsize = $this->fullsize;
188
-      $this->Template->imageLink = ($this->imageUrl ?: $this->singleSRC);
189
-    }
190
-
191
-    if ($this->eSM_addText)
192
-    {
193
-      $this->Template->text = nl2br($this->eSM_slider_text);
194
-      $this->Template->link = $this->eSM_slider_url;
195
-    }
196
-
197
-  }
198
-
199
-}
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,199 @@
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
+ * Front end content element swiper image slide.
15
+ */
16
+class ContentSwiperSliderImage extends \ContentElement
17
+{
18
+
19
+	/**
20
+	 * Template
21
+	 * @var string
22
+	 */
23
+	protected $strTemplate = 'ce_swiper_slider_image';
24
+
25
+  /**
26
+   * @return string
27
+   */
28
+  public function generate()
29
+  {
30
+    if (TL_MODE == 'BE')
31
+    {
32
+      $return = '';
33
+
34
+      if ($this->multiSRC)
35
+      {
36
+
37
+        $source = \StringUtil::deserialize($this->multiSRC);
38
+        $objFiles = \FilesModel::findMultipleByUuids($source);
39
+
40
+        if ($objFiles !== null)
41
+        {
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
+          }
55
+        }
56
+      }
57
+
58
+      return $return;
59
+    }
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
+
71
+    return parent::generate();
72
+  }
73
+
74
+  /**
75
+   * Generate the content element
76
+   */
77
+  protected function compile()
78
+  {
79
+    if (TL_MODE == 'BE')
80
+    {
81
+      $this->strTemplate = 'be_wildcard';
82
+
83
+      /** @var \BackendTemplate|object $objTemplate */
84
+      $objTemplate = new \BackendTemplate($this->strTemplate);
85
+
86
+      $this->Template = $objTemplate;
87
+    }
88
+
89
+    if ($this->multiSRC)
90
+    {
91
+
92
+      $source = \StringUtil::deserialize($this->multiSRC);
93
+      $objFiles = \FilesModel::findMultipleByUuids($source);
94
+
95
+      $imageFiles = array();
96
+      $videoFiles = array();
97
+
98
+      if ($objFiles !== null) {
99
+
100
+        foreach ($objFiles as $file) {
101
+          if (is_file(TL_ROOT . '/' . $file->path))
102
+          {
103
+            if (in_array($file->extension, array_map('trim', explode(',', \Config::get('validImageTypes')))))
104
+            {
105
+              $imageFiles[] = $file;
106
+            } else if (in_array($file->extension, array_map('trim', array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv', 'm4a', 'mp3', 'wma', 'mpeg', 'wav', 'ogg'))))
107
+            {
108
+              $videoFiles[] = $file;
109
+            }
110
+          }
111
+        }
112
+      }
113
+
114
+      if (isset($imageFiles[0]))
115
+      {
116
+        $this->singleSRC = $imageFiles[0]->path;
117
+
118
+        $this->addImageToTemplate($this->Template, array('singleSRC'=>$this->singleSRC, 'size'=>$this->size));
119
+
120
+        $backgroundStyle = '';
121
+
122
+        if ($this->eSM_slider_minHeight) {
123
+          if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto') {
124
+            $minHeight = $this->Template->picture['img']['height'] . 'px';
125
+          } else
126
+          {
127
+            $minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%';
128
+          }
129
+          $backgroundStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
130
+        }
131
+
132
+
133
+        $backgroundStyle .= '.slide_'.$this->id.' .swiper-slide-image { background-image: url(\''.$this->Template->src.'\');';
134
+
135
+        if ($this->eSM_slider_bgSize) {
136
+          $backgroundStyle .= 'background-size: ' . $this->eSM_slider_bgSize . ';';
137
+        } else {
138
+          $backgroundStyle .= 'background-size: cover;';
139
+        }
140
+        if ($this->eSM_slider_bgPosition) {
141
+          $backgroundStyle .= 'background-position: ' . $this->eSM_slider_bgPosition . ';';
142
+        } else {
143
+          $backgroundStyle .= 'background-position: 0 0;';
144
+        }
145
+        if ($this->eSM_slider_bgOpacity) {
146
+          $backgroundStyle .= 'opacity:' . $this->eSM_slider_bgOpacity/100 . ';';
147
+        }
148
+        if ($this->eSM_slider_bgRepeat) {
149
+          $backgroundStyle .= 'background-repeat: ' . $this->eSM_slider_bgRepeat . ';';
150
+        }
151
+
152
+        $this->Template->backgroundStyle = $backgroundStyle.' }';
153
+
154
+        // Responsive handling
155
+        if ($this->Template->picture['sources'] && is_array($this->Template->picture['sources']))
156
+        {
157
+          $backgroundStyleResponsive = '';
158
+          foreach ($this->Template->picture['sources'] as $srcSet)
159
+          {
160
+            $srcSetStyle = '.slide_'.$this->id.' .swiper-slide-image { background-image: url(\''.$srcSet['src'].'\'); }';
161
+
162
+            if ($this->eSM_slider_minHeight) {
163
+              if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto') {
164
+                $minHeight = $srcSet['height'] . 'px';
165
+              } else
166
+              {
167
+                $minHeight = round($srcSet['height'] / $srcSet['width'] * 100) . '%';
168
+              }
169
+              $srcSetStyle .= '.slide_'.$this->id.':before { content: ""; display: block; float: left; padding-top: '.$minHeight.'; }';
170
+            }
171
+
172
+            $backgroundStyleResponsive .= '@media screen and '.$srcSet['media'].' { '.$srcSetStyle.' }';
173
+          }
174
+          $this->Template->backgroundStyleResponsive = $backgroundStyleResponsive;
175
+        }
176
+
177
+      }
178
+
179
+      if (count($videoFiles)) {
180
+        $this->Template->videoFiles = $videoFiles;
181
+      }
182
+    }
183
+
184
+    if ($this->eSM_slider_addImageLink)
185
+    {
186
+      $this->Template->lightboxId = 'image_slide_' . ($this->parentSlickId ?: 's'.$this->id);
187
+      $this->Template->fullsize = $this->fullsize;
188
+      $this->Template->imageLink = ($this->imageUrl ?: $this->singleSRC);
189
+    }
190
+
191
+    if ($this->eSM_addText)
192
+    {
193
+      $this->Template->text = nl2br($this->eSM_slider_text);
194
+      $this->Template->link = $this->eSM_slider_url;
195
+    }
196
+
197
+  }
198
+
199
+}