-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
250 lines (223 loc) · 9.18 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
// Custom SCKLS
// -- Exhibit Builder Random Featured Exhibit Display
function sckls_exhibit_builder_display_random_featured_exhibit() {
$html = '';
$featuredExhibit = exhibit_builder_random_featured_exhibit();
if ($featuredExhibit) {
$image = sckls_exhibit_builder_get_first_image_object($featuredExhibit);
} else {
$image = '';
}
if ($featuredExhibit) {
$html .= '<a href="' . sckls_exhibit_builder_link_to_exhibit($featuredExhibit) . '" class="featured">';
$html .= ' <h6 class="header-label">Featured Exhibit</h6>';
$html .= ' <div class="overlay"></div>';
$html .= ' <span class="title">' . $featuredExhibit->title . '</span>';
if ($image) {
$html .= '<div style="background-image: url(' . file_display_url($image, 'fullsize') . ');" class="img"></div>';
} else {
$html .= '<div style="background-image: url(' . img('defaultImage@2x.jpg') . ');" class="img default"></div>';
}
$html .= '</a>';
} else {
$html .= '<h4 class="not-featured">No exhibits added, yet.</h4>';
}
$html = apply_filters('exhibit_builder_display_random_featured_exhibit', $html);
return $html;
}
function sckls_exhibit_builder_link_to_exhibit($exhibit = null, $exhibitPage = null) {
if (!$exhibit) {
$exhibit = get_current_record('exhibit');
}
$uri = exhibit_builder_exhibit_uri($exhibit, $exhibitPage);
return html_escape($uri);
}
// Custom SCKLS
// -- Random Featured Collection
function sckls_random_featured_collection() {
$html = '';
$collection = get_db()->getTable('Collection')->findRandomFeatured();
if ($collection){
set_current_record('collection', $collection);
$html .= '<a href="' . record_url($collection, null, true) . '" class="featured">';
$html .= ' <h6 class="header-label">Featured Collection</h6>';
$html .= ' <div class="overlay"></div>';
$items = get_records('Item', array('collection'=>$collection->id), 8);
set_loop_records('items', $items);
if (has_loop_records('items')){
$image = $items[0]->Files;
if ($image) {
$html .= '<div style="background-image: url(' . file_display_url($image[0], 'fullsize') . ');" class="img"></div>';
} else {
$html .= '<div style="background-image: url(' . img('defaultImage@2x.jpg') . ');" class="img default"></div>';
}
} else {
$html .= '<div style="background-image: url(' . img('defaultImage@2x.jpg') . ');" class="img default"></div>';
}
$html .= ' <span class="title">' . metadata('collection', array('Dublin Core', 'Title')) . '</span>';
$html .= '</a>';
} else {
$html .= '<h4 class="not-featured">No featured collections.</h4>';
}
return $html;
}
// Custom SCKLS
// -- Random Featured Item
function sckls_random_featured_item() {
$html = '';
$items = get_records('Item', array('featured' => true), 1);
set_loop_records('items', $items);
if (has_loop_records('items')){
foreach (loop('items') as $item){
$html .= '<a href="' . record_url($item, null, true) . '" class="featured">';
$html .= ' <h6 class="header-label">Featured Item</h6>';
$html .= ' <div class="overlay"></div>';
$image = $item->Files;
if ($image) {
$html .= '<div style="background-image: url(' . file_display_url($image[0], 'fullsize') . ');" class="img"></div>';
} else {
$html .= '<div style="background-image: url(' . img('defaultImage@2x.jpg') . ');" class="img default"></div>';
}
$html .= ' <span class="title">' . metadata('item', array('Dublin Core', 'Title')) . '</span>';
$html .= '</a>';
}
} else {
$html .= '<h4 class="not-featured">No featured items.</h4>';
}
return $html;
}
function sckls_exhibit_builder_get_first_image_object($exhibit) {
$file = '';
$count = 0;
if (!$exhibit) {
$exhibit = get_current_record('exhibit');
}
set_loop_records('exhibit_page', $exhibit->TopPages);
foreach (loop('exhibit_page') as $exhibitPage) {
$attachments = $exhibitPage->getAllAttachments();
foreach ($attachments as $attachment):
if ($file === ''){
$item = $attachment->getItem();
$file = $attachment->getFile();
}
endforeach;
}
return $file;
}
function sckls_exhibit_builder_get_first_image_html($exhibit) {
$html = '';
$count = 0;
if (!$exhibit) {
$exhibit = get_current_record('exhibit');
}
set_loop_records('exhibit_page', $exhibit->TopPages);
foreach (loop('exhibit_page') as $exhibitPage) {
$attachments = $exhibitPage->getAllAttachments();
foreach ($attachments as $attachment):
if ($count === 0){
$item = $attachment->getItem();
$file = $attachment->getFile();
$html .= file_display_url($file, 'fullsize');
}
$count++;
endforeach;
}
return $html;
}
function sckls_exhibit_builder_get_images($exhibit) {
$html = '';
if (!$exhibit) {
$exhibit = get_current_record('exhibit');
}
set_loop_records('exhibit_page', $exhibit->TopPages);
foreach (loop('exhibit_page') as $exhibitPage) {
$attachments = $exhibitPage->getAllAttachments();
foreach ($attachments as $attachment):
$item = $attachment->getItem();
$file = $attachment->getFile();
$html .= '<div class="item">';
//$html .= ' <a href="' . record_url($item, null, true) . '" class="featured">';
$html .= ' <a>';
//$html .= ' <div class="overlay"></div>';
$html .= ' <div style="background-image: url(' . file_display_url($file, 'fullsize') . ');" class="img"></div>';
//$html .= ' <span class="title">' . metadata($item, array('Dublin Core', 'Title')) . '</span>';
$html .= ' </a>';
$html .= '</div>';
endforeach;
}
return $html;
}
function sckls_exhibit_builder_page_nav($exhibitPage = null) {
$html = '';
if (!$exhibitPage) {
if (!($exhibitPage = get_current_record('exhibit_page', false))) {
return;
}
}
$exhibit = $exhibitPage->getExhibit();
$pagesTrail = $exhibitPage->getAncestors();
$pagesTrail[] = $exhibitPage;
$html .= '<li>';
$html .= '<a class="exhibit-title" href="'. html_escape(exhibit_builder_exhibit_uri($exhibit)) . '">';
$html .= html_escape($exhibit->title) .'</a></li>' . "\n";
foreach ($pagesTrail as $page) {
$linkText = $page->title;
$pageExhibit = $page->getExhibit();
$pageParent = $page->getParent();
$pageSiblings = ($pageParent ? exhibit_builder_child_pages($pageParent) : $pageExhibit->getTopPages());
$html .= "<li>\n<ul class='nav nav-pills nav-stacked'>\n";
foreach ($pageSiblings as $pageSibling) {
$html .= '<li' . ($pageSibling->id == $page->id ? ' class="current"' : '') . '>';
$html .= '<a class="exhibit-page-title" href="' . html_escape(exhibit_builder_exhibit_uri($exhibit, $pageSibling)) . '">';
$html .= html_escape($pageSibling->title) . "</a></li>\n";
}
$html .= "</ul>\n</li>\n";
}
$html = apply_filters('exhibit_builder_page_nav', $html);
return $html;
}
function sckls_item_image_gallery($attrs = array(), $imageType = 'square_thumbnail', $filesShow = false, $item = null) {
if (!$item) {
$item = get_current_record('item');
}
$files = $item->Files;
if (!$files) {
return '';
}
$defaultAttrs = array(
'wrapper' => array('id' => 'item-images'),
'linkWrapper' => array(),
'link' => array(),
'image' => array()
);
$attrs = array_merge($defaultAttrs, $attrs);
$count = 1;
$html = '';
foreach ($files as $file) {
$mime = $file->mime_type;
// Is it the first item? If so, give it a special class name
if ($count == 1){
$class = 'image-large';
$image = file_image($imageType, array('size' => 'fullsize'), $file);
} else {
$class = 'image-small';
$image = file_image($imageType, $attrs['image'], $file);
}
// Setup list items with appropriate classes
if (strstr($mime, 'image') == true) {
$html .= '<li data-src="' . $file->getWebPath('original') . '" class="' . $class . '">';
} elseif (strstr($mime, 'video') == true) {
$html .= '<li data-iframe="true" data-src="' . $file->getWebPath('original') . '?video" class="' . $class . '">';
} elseif (strstr($mime, 'pdf') == true) {
$html .= '<li data-iframe="true" data-src="' . $file->getWebPath('original') . '?pdf" class="' . $class . '">';
} else {
$html .= '<li data-iframe="true" data-src="' . $file->getWebPath('original') . '" class="' . $class . '">';
}
// Get the files/images
$html .= $image;
$html .= '</li>';
$count++;
}
return $html;
}