1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,151 @@ |
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 Pageimage extends \Frontend |
|
15 |
+{ |
|
16 |
+ |
|
17 |
+ public static function getImages() |
|
18 |
+ { |
|
19 |
+ global $objPage; |
|
20 |
+ $arrImages = array(); |
|
21 |
+ |
|
22 |
+ // Image settings |
|
23 |
+ $sb_imageUrl = deserialize($objPage->sb_imageUrl); |
|
24 |
+ $sb_imageOrder = deserialize($objPage->sb_imageOrder); |
|
25 |
+ $sb_imageSize = $objPage->sb_imageSize; |
|
26 |
+ |
|
27 |
+ // Inherit images if current page has none |
|
28 |
+ if ((!count($sb_imageUrl) || (count($sb_imageUrl) == 1 && !$sb_imageUrl[0])) && !$objPage->sb_imageIgnore) |
|
29 |
+ { |
|
30 |
+ $pid = $objPage->id; |
|
31 |
+ // Inherit settings |
|
32 |
+ do |
|
33 |
+ { |
|
34 |
+ $objParentPage = \Database::getInstance()->prepare("SELECT * FROM tl_page WHERE id=?") |
|
35 |
+ ->limit(1) |
|
36 |
+ ->execute($pid); |
|
37 |
+ if ($objParentPage->numRows < 1) |
|
38 |
+ { |
|
39 |
+ break; |
|
40 |
+ } |
|
41 |
+ |
|
42 |
+ $pid = $objParentPage->pid; |
|
43 |
+ $type = $objParentPage->type; |
|
44 |
+ |
|
45 |
+ $arrParentImageUrl = deserialize($objParentPage->sb_imageUrl); |
|
46 |
+ |
|
47 |
+ if ((!is_array($sb_imageUrl) || !count($sb_imageUrl) || !$sb_imageUrl[0]) && (is_array($arrParentImageUrl) && count($arrParentImageUrl) && $arrParentImageUrl[0])) |
|
48 |
+ { |
|
49 |
+ |
|
50 |
+ $sb_imageUrl = deserialize($objParentPage->sb_imageUrl); |
|
51 |
+ $sb_imageSize = $objParentPage->sb_imageSize; |
|
52 |
+ $sb_imageOrder = deserialize($objParentPage->sb_imageOrder); |
|
53 |
+ break; |
|
54 |
+ } |
|
55 |
+ } |
|
56 |
+ while ($pid > 0 && $type != 'root'); |
|
57 |
+ } |
|
58 |
+ |
|
59 |
+ // Order images |
|
60 |
+ if ($sb_imageOrder != '' && (!count($sb_imageUrl) || (count($sb_imageUrl) == 1 && !$sb_imageUrl[0]))) |
|
61 |
+ { |
|
62 |
+ $tmp = $sb_imageOrder; |
|
63 |
+ |
|
64 |
+ if (!empty($tmp) && is_array($tmp)) |
|
65 |
+ { |
|
66 |
+ // Remove all values |
|
67 |
+ $arrOrder = array_map(function(){}, array_flip($tmp)); |
|
68 |
+ |
|
69 |
+ // Move the matching elements to their position in $arrOrder |
|
70 |
+ foreach ($sb_imageUrl as $k=>$v) |
|
71 |
+ { |
|
72 |
+ if (array_key_exists($v, $arrOrder)) |
|
73 |
+ { |
|
74 |
+ $arrOrder[$v] = $v; |
|
75 |
+ unset($sb_imageUrl[$k]); |
|
76 |
+ } |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ // Append the left-over images at the end |
|
80 |
+ if (!empty($sb_imageUrl)) |
|
81 |
+ { |
|
82 |
+ $arrOrder = array_merge($arrOrder, array_values($sb_imageUrl)); |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ // Remove empty (unreplaced) entries |
|
86 |
+ $sb_imageUrl = array_values(array_filter($arrOrder)); |
|
87 |
+ unset($arrOrder); |
|
88 |
+ } |
|
89 |
+ } |
|
90 |
+ |
|
91 |
+ if (count($sb_imageUrl) && $sb_imageUrl[0]) |
|
92 |
+ { |
|
93 |
+ |
|
94 |
+ // Get all images |
|
95 |
+ $multiSRC = array_values($sb_imageUrl); |
|
96 |
+ $objFiles = \FilesModel::findMultipleByIds($multiSRC); |
|
97 |
+ |
|
98 |
+ while ($objFiles->next()) { |
|
99 |
+ // Continue if the files has been processed or does not exist |
|
100 |
+ if (isset($arrImages[$objFiles->path]) || !file_exists(TL_ROOT.'/'.$objFiles->path)) { |
|
101 |
+ continue; |
|
102 |
+ } |
|
103 |
+ |
|
104 |
+ // Single files |
|
105 |
+ $objFile = new \File($objFiles->path, true); |
|
106 |
+ |
|
107 |
+ if (!$objFile->isImage) { |
|
108 |
+ continue; |
|
109 |
+ } |
|
110 |
+ |
|
111 |
+ $arrMeta = static::getMetaData($objFiles->meta, $objPage->language); |
|
112 |
+ |
|
113 |
+ if (empty($arrMeta)) { |
|
114 |
+ if ($objPage->rootFallbackLanguage !== null) { |
|
115 |
+ $arrMeta = static::getMetaData($objFiles->meta, $objPage->rootFallbackLanguage); |
|
116 |
+ } |
|
117 |
+ } |
|
118 |
+ |
|
119 |
+ // Use the file name as title if none is given |
|
120 |
+ if ($arrMeta['title'] == '') { |
|
121 |
+ $arrMeta['title'] = specialchars($objFile->basename); |
|
122 |
+ } |
|
123 |
+ |
|
124 |
+ // Add the image |
|
125 |
+ $arrImages[$objFiles->path] = array |
|
126 |
+ ( |
|
127 |
+ 'id' => $objFiles->id, |
|
128 |
+ 'uuid' => $objFiles->uuid, |
|
129 |
+ 'name' => $objFile->basename, |
|
130 |
+ 'singleSRC' => $objFiles->path, |
|
131 |
+ 'alt' => $arrMeta['title'], |
|
132 |
+ 'imageUrl' => $arrMeta['link'], |
|
133 |
+ 'caption' => $arrMeta['caption'], |
|
134 |
+ 'size' => $sb_imageSize |
|
135 |
+ ); |
|
136 |
+ } |
|
137 |
+ $arrImages = array_values($arrImages); |
|
138 |
+ unset($objFiles); |
|
139 |
+ unset($multiSRC); |
|
140 |
+ } |
|
141 |
+ |
|
142 |
+ return $arrImages; |
|
143 |
+ |
|
144 |
+ } |
|
145 |
+ |
|
146 |
+ public static function getPageImage($strType='images') |
|
147 |
+ { |
|
148 |
+ $Hook = new HookPageimage(); |
|
149 |
+ return $Hook->piReplaceInsertTags('sb_'.$strType); |
|
150 |
+ } |
|
151 |
+} |
|
0 | 152 |
\ No newline at end of file |