gallery.php
8.5 KB
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?php
/**
* @class FLGalleryModule
*/
class FLGalleryModule extends FLBuilderModule {
/**
* @method __construct
*/
public function __construct()
{
parent::__construct(array(
'name' => __('相册', 'fl-builder'),
'description' => __('Display multiple photos in a gallery view.', 'fl-builder'),
'category' => __('基本模块', 'fl-builder'),
'editor_export' => false,
'partial_refresh' => true
));
$this->add_styles_scripts();
}
/**
* @method add_styles_scripts()
*/
public function add_styles_scripts()
{
$this->add_js('jquery-wookmark');
$this->add_js('jquery-mosaicflow');
$override_lightbox = apply_filters( 'fl_builder_override_lightbox', false );
if ( ! $override_lightbox ) {
$this->add_js('jquery-magnificpopup');
$this->add_css('jquery-magnificpopup');
}
else {
wp_dequeue_script('jquery-magnificpopup');
wp_dequeue_style('jquery-magnificpopup');
}
}
/**
* @method update
* @param $settings {object}
*/
public function update($settings)
{
// Cache the photo data if using the WordPress media library.
if($settings->source == 'wordpress') {
$settings->photo_data = $this->get_wordpress_photos();
}
return $settings;
}
/**
* @method get_photos
*/
public function get_photos()
{
// WordPress
if($this->settings->source == 'wordpress') {
return $this->get_wordpress_photos();
}
// SmugMug
if($this->settings->source == 'smugmug') {
return $this->get_smugmug_photos();
}
}
/**
* @method get_wordpress_photos
*/
public function get_wordpress_photos()
{
$photos = array();
$ids = $this->settings->photos;
$medium_w = get_option('medium_size_w');
$large_w = get_option('large_size_w');
if(empty($this->settings->photos)) {
return $photos;
}
foreach($ids as $id) {
$photo = FLBuilderPhoto::get_attachment_data($id);
// Use the cache if we didn't get a photo from the id.
if ( ! $photo ) {
if ( ! isset( $this->settings->photo_data ) ) {
continue;
}
else if ( is_array( $this->settings->photo_data ) ) {
$photos[ $id ] = $this->settings->photo_data[ $id ];
}
else if ( is_object( $this->settings->photo_data ) ) {
$photos[ $id ] = $this->settings->photo_data->{$id};
}
else {
continue;
}
}
// Only use photos who have the sizes object.
if(isset($photo->sizes)) {
// Photo data object
$data = new stdClass();
$data->id = $id;
$data->alt = $photo->alt;
$data->caption = $photo->caption;
$data->description = $photo->description;
$data->title = $photo->title;
// Collage photo src
if($this->settings->layout == 'collage') {
if($this->settings->photo_size < $medium_w && isset($photo->sizes->medium)) {
$data->src = $photo->sizes->medium->url;
}
else if($this->settings->photo_size <= $large_w && isset($photo->sizes->large)) {
$data->src = $photo->sizes->large->url;
}
else {
$data->src = $photo->sizes->full->url;
}
}
// Grid photo src
else {
if(isset($photo->sizes->thumbnail)) {
$data->src = $photo->sizes->thumbnail->url;
}
else {
$data->src = $photo->sizes->full->url;
}
}
// Photo Link
if(isset($photo->sizes->large)) {
$data->link = $photo->sizes->large->url;
}
else {
$data->link = $photo->sizes->full->url;
}
// Push the photo data
$photos[$id] = $data;
}
}
return $photos;
}
/**
* @method get_smugmug_photos
*/
public function get_smugmug_photos()
{
$photos = array();
// Load the feed into a DOM object.
$feed = @simplexml_load_file($this->settings->feed_url);
if($feed !== false) {
// Get the feed data into an array.
foreach($feed->channel->item as $item) {
// SmugMug photo sizes.
$media = array();
foreach($item->xpath('media:group/media:content') as $media_content) {
if($media_content['medium'] == 'image') {
$media[] = array(
'height' => $media_content['height'],
'width' => $media_content['width'],
'url' => $media_content['url']
);
}
}
// Only continue if we have media.
if(count($media) > 0) {
// Photo link
if(count($media) <= 3) {
$link = $media[0]['url'];
}
else {
$link = $media[count($media) - 2]['url'];
}
// Photo Src
if($this->settings->layout == 'collage') {
for($i = count($media) - 1; $i >= 0; $i--) {
if($this->settings->photo_size <= $media[$i]['width']) {
$src = $media[$i]['url'];
}
}
}
else {
$src = $media[1]['url'];
}
// Photo data object.
$data = new stdClass();
$data->alt = $item->title;
$data->caption = $item->title;
$data->description = $item->title;
$data->title = $item->title;
$data->height = $media[count($media) - 1]['height'];
$data->width = $media[count($media) - 1]['width'];
$data->link = $link;
$data->src = $src;
// Push the photo data.
array_push($photos, $data);
}
}
}
return $photos;
}
}
/**
* Register the module and its form settings.
*/
FLBuilder::register_module('FLGalleryModule', array(
'general' => array(
'title' => __('General', 'fl-builder'),
'sections' => array(
'general' => array(
'title' => '',
'fields' => array(
'layout' => array(
'type' => 'select',
'label' => __('Layout', 'fl-builder'),
'default' => 'collage',
'options' => array(
'collage' => __('Collage', 'fl-builder'),
'grid' => _x( 'Thumbs', 'Gallery layout: thumbnails.', 'fl-builder' )
),
'toggle' => array(
'collage' => array(
'fields' => array('photo_size')
)
)
),
'source' => array(
'type' => 'select',
'label' => __('Source', 'fl-builder'),
'default' => 'wordpress',
'options' => array(
'wordpress' => __('Media Library', 'fl-builder'),
'smugmug' => 'SmugMug'
),
'help' => __('Pull images from the WordPress media library or a gallery on your SmugMug site by inserting the RSS feed URL from SmugMug. The RSS feed URL can be accessed by using the get a link function in your SmugMug gallery.', 'fl-builder'),
'toggle' => array(
'wordpress' => array(
'fields' => array('photos')
),
'smugmug' => array(
'fields' => array('feed_url')
)
)
),
'photos' => array(
'type' => 'multiple-photos',
'label' => __('Photos', 'fl-builder')
),
'feed_url' => array(
'type' => 'text',
'label' => __('Feed URL', 'fl-builder')
),
'photo_size' => array(
'type' => 'select',
'label' => __('Photo Size', 'fl-builder'),
'default' => '300',
'options' => array(
'200' => _x( 'Small', 'Photo size.', 'fl-builder' ),
'300' => _x( 'Medium', 'Photo size.', 'fl-builder' ),
'400' => _x( 'Large', 'Photo size.', 'fl-builder')
)
),
'photo_spacing' => array(
'type' => 'text',
'label' => __('Photo Spacing', 'fl-builder'),
'default' => '20',
'maxlength' => '3',
'size' => '4',
'description' => 'px'
),
'show_captions' => array(
'type' => 'select',
'label' => __('Show Captions', 'fl-builder'),
'default' => '0',
'options' => array(
'0' => __('Never', 'fl-builder'),
'hover' => __('On Hover', 'fl-builder'),
'below' => __('Below Photo', 'fl-builder')
),
'help' => __('The caption pulls from whatever text you put in the caption area in the media manager for each image. The caption is also pulled directly from SmugMug if you have captions set in your gallery.', 'fl-builder')
),
'click_action' => array(
'type' => 'select',
'label' => __('Click Action', 'fl-builder'),
'default' => 'lightbox',
'options' => array(
'none' => _x( 'None', 'Click action.', 'fl-builder' ),
'lightbox' => __('Lightbox', 'fl-builder'),
'link' => __('Photo Link', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
)
)
)
)
)
));