Browse code

Refactor and rewrite as contao bundle

Benjamin Roth authored on04/11/2022 22:32:32
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,149 @@
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 EsalesMedia\ContaoSwiperBundle\Frontend\Element;
12
+
13
+
14
+/**
15
+ * Front end content element swiper slider start.
16
+ */
17
+class ContentSwiperSliderStart extends \ContentElement
18
+{
19
+
20
+	/**
21
+	 * Template
22
+	 * @var string
23
+	 */
24
+	protected $strTemplate = 'ce_swiper_slider_start';
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
+			$this->Template->title = $this->headline;
41
+		}
42
+
43
+    $parentKey = ($this->arrData['ptable'] ?: 'tl_article') . '__' . $this->arrData['pid'];
44
+
45
+    if (!empty($GLOBALS['TL_ESM_SLICK'][$parentKey])) {
46
+      $GLOBALS['TL_ESM_SLICK_STACK'][$parentKey][] = $GLOBALS['TL_ESM_SLICK'][$parentKey];
47
+    }
48
+
49
+    $GLOBALS['TL_ESM_SLICK'][$parentKey] = $this->id;
50
+
51
+		// Slider configuration
52
+		$this->Template->config = $this->eSM_slider_autoPlaySpeed . ',' . $this->eSM_slider_speed . ',' . $this->eSM_slider_initialSlide . ',' . $this->eSM_slider_preload . ',' . $this->eSM_slider_infinite . ',' . $this->eSM_slider_arrows . ',' . $this->eSM_slider_pagination . ',' . $this->eSM_slider_stopOnInteraction . ',' . $this->eSM_slider_fade . ',' . $this->eSM_slider_slidesToShow . ',' . $this->eSM_slider_slidesToScroll . ',' . $this->eSM_slider_adaptiveHeight;
53
+
54
+		// Breakpoint config
55
+    $this->eSM_slider_breakpoints = \StringUtil::deserialize($this->eSM_slider_breakpoints);
56
+    if (is_array($this->eSM_slider_breakpoints))
57
+    {
58
+      $arrBreakpoints = array();
59
+
60
+      foreach ($this->eSM_slider_breakpoints as $breakpoint)
61
+      {
62
+        if (is_numeric($breakpoint['breakpoint_width']) && is_numeric($breakpoint['breakpoint_slidesToShow']) && is_numeric($breakpoint['breakpoint_slidesToScroll']))
63
+        {
64
+          $arrBreakpoints[$breakpoint['breakpoint_width']] = array('slidesPerView'=>$breakpoint['breakpoint_slidesToShow'],'slidesPerGroup'=>$breakpoint['breakpoint_slidesToScroll']);
65
+        }
66
+      }
67
+
68
+      if (count($arrBreakpoints))
69
+      {
70
+        $this->Template->breakpoints = json_encode($arrBreakpoints,JSON_NUMERIC_CHECK );
71
+      }
72
+    }
73
+
74
+		// Background image
75
+    if ($this->eSM_addImage && $this->multiSRC)
76
+    {
77
+      $source = \StringUtil::deserialize($this->multiSRC);
78
+      $objFiles = \FilesModel::findMultipleByUuids($source);
79
+
80
+      $imageFiles = array();
81
+      $videoFiles = array();
82
+
83
+      if ($objFiles !== null) {
84
+
85
+        foreach ($objFiles as $file) {
86
+          if (is_file(TL_ROOT . '/' . $file->path))
87
+          {
88
+            if (in_array($file->extension, array_map('trim', explode(',', \Config::get('validImageTypes')))))
89
+            {
90
+              $imageFiles[] = $file;
91
+            } else if (in_array($file->extension, array_map('trim', array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv', 'm4a', 'mp3', 'wma', 'mpeg', 'wav', 'ogg'))))
92
+            {
93
+              $videoFiles[] = $file;
94
+            }
95
+          }
96
+        }
97
+      }
98
+
99
+      if (isset($imageFiles[0]))
100
+      {
101
+        $this->singleSRC = $imageFiles[0]->path;
102
+
103
+        $this->addImageToTemplate($this->Template, array('singleSRC' => $this->singleSRC, 'size' => $this->size));
104
+
105
+        if ($this->eSM_slider_minHeight)
106
+        {
107
+          if ($this->eSM_slider_bgSize && $this->eSM_slider_bgSize == 'auto auto')
108
+          {
109
+            $this->Template->minHeight = $this->Template->picture['img']['height'] . 'px';
110
+          } else
111
+          {
112
+            $this->Template->minHeight = round($this->Template->picture['img']['height'] / $this->Template->picture['img']['width'] * 100) . '%';
113
+          }
114
+        }
115
+
116
+        $backgroundStyle = 'background-image: url(\'' . $this->Template->src . '\');';
117
+
118
+        if ($this->eSM_slider_bgSize)
119
+        {
120
+          $backgroundStyle .= 'background-size: ' . $this->eSM_slider_bgSize . ';';
121
+        } else
122
+        {
123
+          $backgroundStyle .= 'background-size: cover;';
124
+        }
125
+        if ($this->eSM_slider_bgPosition)
126
+        {
127
+          $backgroundStyle .= 'background-position: ' . $this->eSM_slider_bgPosition . ';';
128
+        } else
129
+        {
130
+          $backgroundStyle .= 'background-position: 0 0;';
131
+        }
132
+        if ($this->eSM_slider_bgOpacity)
133
+        {
134
+          $backgroundStyle .= 'opacity:' . $this->eSM_slider_bgOpacity / 100 . ';';
135
+        }
136
+        if ($this->eSM_slider_bgRepeat)
137
+        {
138
+          $backgroundStyle .= 'background-repeat: ' . $this->eSM_slider_bgRepeat . ';';
139
+        }
140
+
141
+        $this->Template->backgroundStyle = $backgroundStyle;
142
+      }
143
+
144
+      if (count($videoFiles)) {
145
+        $this->Template->videoFiles = $videoFiles;
146
+      }
147
+    }
148
+	}
149
+}