Browse code

Initial commit

Benjamin Roth authored on26/08/2015 12:12:39
Showing9 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+
2
+;;
3
+; Configure what you want the autoload creator to register
4
+;;
5
+register_namespaces = true
6
+register_classes    = true
7
+register_templates  = true
0 8
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+<?php
2
+
3
+/**
4
+ * Pageimage for Contao
5
+ *
6
+ * Copyright (c) 2015 Benjamin Roth
7
+ *
8
+ * @license LGPL-3.0+
9
+ */
10
+
11
+
12
+/**
13
+ * Register the namespaces
14
+ */
15
+ClassLoader::addNamespaces(array
16
+(
17
+	'eSM_pageimage',
18
+));
19
+
20
+
21
+/**
22
+ * Register the classes
23
+ */
24
+ClassLoader::addClasses(array
25
+(
26
+	// Hooks
27
+	'eSM_pageimage\Seitenbild' => 'system/modules/eSM_pageimage/hooks/Seitenbild.php',
28
+));
29
+
30
+
31
+/**
32
+ * Register the templates
33
+ */
34
+TemplateLoader::addFiles(array
35
+(
36
+	'eSM_pageimage_container'             => 'system/modules/eSM_pageimage/templates/container',
37
+	'eSM_pageimage_picture_default'       => 'system/modules/eSM_pageimage/templates/picture',
38
+));
0 39
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+<?php
2
+
3
+/**
4
+ * Pageimage for Contao
5
+ *
6
+ * Copyright (c) 2015 Benjamin Roth
7
+ *
8
+ * @license LGPL-3.0+
9
+ */
10
+
11
+
12
+$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array('Seitenbild', 'sbReplaceInsertTags');
0 13
new file mode 100644
... ...
@@ -0,0 +1,55 @@
1
+<?php
2
+
3
+/**
4
+ * Pageimage for Contao
5
+ *
6
+ * Copyright (c) 2015 Benjamin Roth
7
+ *
8
+ * @license LGPL-3.0+
9
+ */
10
+
11
+
12
+/**
13
+ * Palettes
14
+ */
15
+$GLOBALS['TL_DCA']['tl_page']['palettes']['regular'] = str_replace('{meta_legend}', '{sb_legend:hide},sb_imageUrl,sb_imageSize,sb_imageIgnore;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['regular']);
16
+$GLOBALS['TL_DCA']['tl_page']['palettes']['forward'] = str_replace('{meta_legend}', '{sb_legend:hide},sb_imageUrl,sb_imageSize,sb_imageIgnore;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['forward']);
17
+$GLOBALS['TL_DCA']['tl_page']['palettes']['root'] = str_replace('{meta_legend}', '{sb_legend:hide},sb_imageUrl,sb_imageSize;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['root']);
18
+
19
+/**
20
+ * Fields
21
+ */
22
+$GLOBALS['TL_DCA']['tl_page']['fields']['sb_imageUrl'] = array
23
+(
24
+	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['sb_imageUrl'],
25
+	'exclude'                 => true,
26
+	'inputType'               => 'fileTree',
27
+	'eval'                    => array('fieldType'=>'checkbox', 'multiple'=>true, 'files'=>true, 'filesOnly'=>true, 'extensions'=>'jpg,gif,png,jpeg','orderField'=>'sb_imageOrder','isGallery'=>true),
28
+	'sql'                     => 'blob NULL'
29
+);
30
+
31
+$GLOBALS['TL_DCA']['tl_page']['fields']['sb_imageOrder'] = array
32
+(
33
+	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['sb_imageOrder'],
34
+	'sql'                     => "blob NULL"
35
+);
36
+
37
+$GLOBALS['TL_DCA']['tl_page']['fields']['sb_imageSize'] = array
38
+(
39
+	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['sb_imageSize'],
40
+	'exclude'                 => true,
41
+	'inputType'               => 'imageSize',
42
+	'options'                 => System::getImageSizes(),
43
+	'reference'               => &$GLOBALS['TL_LANG']['MSC'],
44
+	'eval'                    => array('rgxp'=>'natural', 'includeBlankOption'=>true, 'nospace'=>true, 'helpwizard'=>true, 'tl_class'=>'w50'),
45
+	'sql'                     => "varchar(64) NOT NULL default ''"
46
+);
47
+
48
+$GLOBALS['TL_DCA']['tl_page']['fields']['sb_imageIgnore'] = array
49
+(
50
+	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['sb_imageIgnore'],
51
+	'exclude'                 => true,
52
+	'inputType'               => 'checkbox',
53
+	'eval'                    => array('tl_class'=>'w50 m12'),
54
+	'sql'                     => "char(1) NOT NULL default ''"
55
+);
0 56
\ No newline at end of file
1 57
new file mode 100644
... ...
@@ -0,0 +1,233 @@
1
+<?php
2
+
3
+/**
4
+ * Pageimage for Contao
5
+ *
6
+ * Copyright (c) 2015 Benjamin Roth
7
+ *
8
+ * @license LGPL-3.0+
9
+ */
10
+
11
+namespace eSM_pageimage;
12
+
13
+ 
14
+class Seitenbild extends \Frontend
15
+{
16
+
17
+	public function sbReplaceInsertTags($strTag)
18
+	{
19
+		$flags = explode('|', $strTag);
20
+		$elements = explode('::', array_shift($flags));
21
+
22
+		if (!in_array($elements[0],array('sb_images','sb_image','sb_image_url','sb_image_css')))
23
+		{
24
+			return false;
25
+		}
26
+
27
+		global $objPage;
28
+
29
+		$objPage->sb_imageUrl = deserialize($objPage->sb_imageUrl);
30
+		$objPage->sb_imageOrder = deserialize($objPage->sb_imageOrder);
31
+
32
+		if ((!count($objPage->sb_imageUrl) || (count($objPage->sb_imageUrl) == 1 && !$objPage->sb_imageUrl[0])) && !$objPage->sb_imageIgnore)
33
+		{
34
+			$this->import('Database');
35
+			$pid = $objPage->id;
36
+			// Inherit settings
37
+			do
38
+			{
39
+				$objParentPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")
40
+												->limit(1)
41
+												->execute($pid);
42
+				if ($objParentPage->numRows < 1)
43
+				{
44
+					break;
45
+				}
46
+
47
+				$pid = $objParentPage->pid;
48
+				$type = $objParentPage->type;
49
+
50
+				$arrParentImageUrl = deserialize($objParentPage->sb_imageUrl);
51
+
52
+				if ((!is_array($objPage->sb_imageUrl) || !count($objPage->sb_imageUrl) || !$objPage->sb_imageUrl[0]) && (is_array($arrParentImageUrl) && count($arrParentImageUrl) && $arrParentImageUrl[0]))
53
+				{
54
+
55
+					$objPage->sb_imageUrl = deserialize($objParentPage->sb_imageUrl);
56
+					$objPage->sb_imageSize = $objParentPage->sb_imageSize;
57
+					$objPage->sb_imageOrder = deserialize($objParentPage->sb_imageOrder);
58
+					break;
59
+				}
60
+			}
61
+			while ($pid > 0 && $type != 'root');
62
+		}
63
+
64
+		if (!is_array($objPage->sb_imageUrl) || !count($objPage->sb_imageUrl) || !$objPage->sb_imageUrl[0])
65
+		{
66
+			return;
67
+		}
68
+
69
+
70
+		if ($objPage->sb_imageOrder != '')
71
+		{
72
+			$tmp = $objPage->sb_imageOrder;
73
+
74
+			if (!empty($tmp) && is_array($tmp))
75
+			{
76
+				// Remove all values
77
+				$arrOrder = array_map(function(){}, array_flip($tmp));
78
+
79
+				// Move the matching elements to their position in $arrOrder
80
+				foreach ($objPage->sb_imageUrl as $k=>$v)
81
+				{
82
+					if (array_key_exists($v, $arrOrder))
83
+					{
84
+						$arrOrder[$v] = $v;
85
+						unset($objPage->sb_imageUrl[$k]);
86
+					}
87
+				}
88
+
89
+				// Append the left-over images at the end
90
+				if (!empty($objPage->sb_imageUrl))
91
+				{
92
+					$arrOrder = array_merge($arrOrder, array_values($objPage->sb_imageUrl));
93
+				}
94
+
95
+				// Remove empty (unreplaced) entries
96
+				$objPage->sb_imageUrl = array_values(array_filter($arrOrder));
97
+				unset($arrOrder);
98
+			}
99
+		}
100
+
101
+		$images = array();
102
+		$multiSRC = array_values($objPage->sb_imageUrl);
103
+		$objFiles = \FilesModel::findMultipleByIds($multiSRC);
104
+
105
+		// Get all images
106
+		while ($objFiles->next())
107
+		{
108
+			// Continue if the files has been processed or does not exist
109
+			if (isset($images[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path))
110
+			{
111
+				continue;
112
+			}
113
+
114
+			// Single files
115
+			$objFile = new \File($objFiles->path, true);
116
+
117
+			if (!$objFile->isImage)
118
+			{
119
+				continue;
120
+			}
121
+
122
+			$arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
123
+
124
+			if (empty($arrMeta))
125
+			{
126
+				if ($this->metaIgnore)
127
+				{
128
+					continue;
129
+				}
130
+				elseif ($objPage->rootFallbackLanguage !== null)
131
+				{
132
+					$arrMeta = $this->getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
133
+				}
134
+			}
135
+
136
+			// Use the file name as title if none is given
137
+			if ($arrMeta['title'] == '')
138
+			{
139
+				$arrMeta['title'] = specialchars($objFile->basename);
140
+			}
141
+
142
+			// Add the image
143
+			$images[$objFiles->path] = array
144
+			(
145
+				'id'        => $objFiles->id,
146
+				'uuid'      => $objFiles->uuid,
147
+				'name'      => $objFile->basename,
148
+				'singleSRC' => $objFiles->path,
149
+				'alt'       => $arrMeta['title'],
150
+				'imageUrl'  => $arrMeta['link'],
151
+				'caption'   => $arrMeta['caption'],
152
+				'size'      => $objPage->sb_imageSize
153
+			);
154
+		}
155
+		$images = array_values($images);
156
+		unset($objFiles);
157
+		unset($multiSRC);
158
+
159
+
160
+		if (!isset($elements[1]) || !$elements[1])
161
+		{
162
+			$elements[1] = 0;
163
+		} else if (count($images)-1 < --$elements[1])
164
+		{
165
+			$elements[1] = count($images)-1;
166
+		}
167
+
168
+		if ($elements[0] == 'sb_image_url' || $elements[0] == 'sb_image_css')
169
+		{
170
+			if (count($images))
171
+			{
172
+				$image = $images[$elements[1]];
173
+
174
+				if (is_array($image['size'] = deserialize($image['size'])))
175
+				{
176
+					$width = intval($image['size'][0]) > 0 ? $image['size'][0] : null;
177
+					$height = intval($image['size'][1]) > 0 ? $image['size'][1] : null;
178
+					$mode = strlen($image['size'][2]) ? $image['size'][2] : null;
179
+				}
180
+				
181
+				$strBuffer = \Image::get($image['singleSRC'], $width, $height, $mode);
182
+				
183
+				if ($elements[0] == 'sb_image_css')
184
+				{
185
+					return 'background-image: url(\'' . $this->Environment->path . '/' . $strBuffer . '\');';
186
+				}
187
+				
188
+				return $strBuffer;
189
+			}
190
+		}
191
+
192
+		if ($elements[0] == 'sb_images' && count($images) > 0)
193
+		{
194
+			$arrImageTplObjects = array();
195
+
196
+			foreach($images as $image)
197
+			{
198
+				$objImage = new \stdClass();
199
+				$this->addImageToTemplate($objImage, $image);
200
+
201
+				$arrImageTplObjects[] = $objImage;
202
+			}
203
+			$objTemplate = new \FrontendTemplate('eSM_pageimage_container');
204
+			$objTemplate->pictures = $arrImageTplObjects;
205
+
206
+			return $objTemplate->parse();
207
+
208
+		} else if ($elements[0] == 'sb_image')
209
+		{
210
+
211
+			$arrImageTplObjects = array();
212
+
213
+			$objImage = new \stdClass();
214
+			$this->addImageToTemplate($objImage, $images[$elements[1]]);
215
+			$arrImageTplObjects[] = $objImage;
216
+
217
+			$objTemplate = new \FrontendTemplate('eSM_pageimage_container');
218
+			$objTemplate->pictures = $arrImageTplObjects;
219
+
220
+			return $objTemplate->parse();
221
+		}
222
+	 
223
+		return false;
224
+	}
225
+
226
+	public static function getPageImage($strType='images')
227
+	{
228
+		$seitenbild = new Seitenbild();
229
+		return $seitenbild->sbReplaceInsertTags('sb_'.$strType);
230
+	}
231
+}
232
+
233
+?>
0 234
\ No newline at end of file
1 235
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+<?php
2
+
3
+/**
4
+ * Pageimage for Contao
5
+ *
6
+ * Copyright (c) 2015 Benjamin Roth
7
+ *
8
+ * @license LGPL-3.0+
9
+ */
10
+
11
+
12
+/**
13
+ * Fields
14
+ */
15
+$GLOBALS['TL_LANG']['tl_page']['sb_imageUrl'] = array('Seitenbild', 'Es kann ein Seitenbild zugewiesen werden das per Inserttag ausgegeben werden kann.');
16
+$GLOBALS['TL_LANG']['tl_page']['sb_imageSize'] = array('Bildgröße', 'Hier kann die Bildgröße und die Art des Zuschnitts gewählt werden.');
17
+$GLOBALS['TL_LANG']['tl_page']['sb_imageIgnore'] = array('Ignoriere Fallback', 'Übergeordnete Seitenbilder werden ignoriert.');
18
+
19
+
20
+/**
21
+ * Fields
22
+ */
23
+$GLOBALS['TL_LANG']['tl_page']['sb_legend'] = 'Seitenbild';
0 24
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+<?php
2
+
3
+/**
4
+ * Pageimage for Contao
5
+ *
6
+ * Copyright (c) 2015 Benjamin Roth
7
+ *
8
+ * @license LGPL-3.0+
9
+ */
10
+
11
+
12
+/**
13
+ * Fields
14
+ */
15
+$GLOBALS['TL_LANG']['tl_page']['sb_imageUrl'] = array('Page image', 'You can choose an image for this page which can be displayed through an inserttag.');
16
+$GLOBALS['TL_LANG']['tl_page']['sb_imageSize'] = array('Image width and height', 'Here you can set the image dimensions and the resize mode.');
17
+$GLOBALS['TL_LANG']['tl_page']['sb_imageIgnore'] = array('Ignore fallback', 'Ignore inherited page images.');
18
+
19
+
20
+/**
21
+ * Fields
22
+ */
23
+$GLOBALS['TL_LANG']['tl_page']['sb_legend'] = 'Page image';
0 24
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+<div class="eSM_pageimage block">
2
+
3
+<?php $this->block('content'); ?>
4
+
5
+  <figure class="image_container">
6
+
7
+    <?php foreach($this->pictures as $picturedata): ?>
8
+      <?php $this->insert('eSM_pageimage_picture_default', $picturedata->picture); ?>
9
+    <?php endforeach; ?>
10
+
11
+    <?php if ($this->caption): ?>
12
+      <figcaption class="caption"><?= $this->caption ?></figcaption>
13
+    <?php endif; ?>
14
+
15
+  </figure>
16
+
17
+<?php $this->endblock(); ?>
18
+
19
+</div>
0 20
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+
2
+<?php if ($this->sources): ?>
3
+  <picture>
4
+    <!--[if IE 9]><video style="display: none;"><![endif]-->
5
+    <?php foreach ($this->sources as $source): ?>
6
+      <source srcset="<?= $source['srcset'] ?>"<?php if (!empty($source['sizes'])) echo ' sizes="' . $source['sizes'] . '"'; ?><?php if (!empty($source['media'])) echo ' media="' . $source['media'] . '"'; ?>>
7
+    <?php endforeach; ?>
8
+    <!--[if IE 9]></video><![endif]-->
9
+<?php endif; ?>
10
+
11
+<img src="<?= $this->img['src'] ?>"<?php if ($this->img['srcset'] !== $this->img['src']) echo ' srcset="' . $this->img['srcset'] . '"'; ?><?php if (!empty($this->img['sizes'])) echo ' sizes="' . $this->img['sizes'] . '"'; elseif (!$this->sources) echo ' width="' . $this->img['width'] . '" height="' . $this->img['height'] . '"'; ?> alt="<?= $this->alt ?>"<?php if ($this->title) echo ' title="' . $this->title . '"'; ?><?php if ($this->class) echo ' class="' . $this->class . '"'; ?><?= $this->attributes ?>>
12
+
13
+<?php if ($this->sources): ?>
14
+  </picture>
15
+<?php endif; ?>
16
+
17
+<?php if ($this->sources || $this->img['src'] !== $this->img['srcset']): ?>
18
+  <script>
19
+    window.respimage && window.respimage({
20
+      elements: [document.images[document.images.length - 1]]
21
+    });
22
+  </script>
23
+<?php endif; ?>