slideshow.php
19.4 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
<?php
/**
* @class FLSlideshowModule
*/
class FLSlideshowModule extends FLBuilderModule {
/**
* @method __construct
*/
public function __construct()
{
parent::__construct(array(
'name' => __('图片幻灯片', 'fl-builder'),
'description' => __('Display multiple photos in a slideshow view.', 'fl-builder'),
'category' => __('图文模块', 'fl-builder'),
'editor_export' => false,
'partial_refresh' => true
));
$this->add_js('yui3');
$this->add_js('fl-slideshow');
$this->add_css('fl-slideshow');
}
/**
* @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_source
*/
public function get_source()
{
// WordPress
if($this->settings->source == 'wordpress') {
return $this->get_wordpress_source();
}
// SmugMug
if($this->settings->source == 'smugmug') {
return $this->get_smugmug_source();
}
}
/**
* @method get_wordpress_photos
*/
public function get_wordpress_photos()
{
$photos = array();
$ids = $this->settings->photos;
$thumb_w = get_option('thumbnail_size_w');
$medium_w = get_option('medium_size_w');
$large_w = get_option('large_size_w');
if(empty($ids)) {
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->caption = $photo->caption;
// Photo sizes
if(isset($photo->sizes->large)) {
$data->largeURL = $photo->sizes->large->url;
if($photo->sizes->full->width <= 2560) {
$data->x3largeURL = $photo->sizes->full->url;
}
else {
$data->x3largeURL = $photo->sizes->large->url;
}
}
else {
$data->largeURL = $photo->sizes->full->url;
$data->x3largeURL = $photo->sizes->full->url;
}
// Thumb size
if(isset($photo->sizes->thumbnail)) {
$data->thumbURL = $photo->sizes->thumbnail->url;
}
else {
$data->thumbURL = $photo->sizes->full->url;
}
// Push the photo data
$photos[$id] = $data;
}
}
return $photos;
}
/**
* @method get_wordpress_source
*/
public function get_wordpress_source()
{
$photos = $this->get_wordpress_photos();
// Build the source js object
if(count($photos) > 0) {
$source = 'type: "urls", urls:';
$objects = array();
foreach($photos as $photo) {
$caption = str_replace( array("\r", "\n") , '', nl2br( htmlspecialchars( $photo->caption ) ) );
$urls = '{' . "\n";
$urls .= 'thumbURL: "'. $photo->thumbURL .'",';
$urls .= 'largeURL: "'. $photo->largeURL .'",';
$urls .= 'x3largeURL: "'. $photo->x3largeURL .'",';
$urls .= 'caption: "'. $caption .'"';
$urls .= '}';
$objects[] = $urls;
}
return $source . '[' . implode(',', $objects) . ']';
}
else {
return '';
}
}
/**
* @method get_smugmug_source
*/
public function get_smugmug_source()
{
$gallery_id = array();
$parts = explode('?', $this->settings->feed_url);
if(count($parts) == 2) {
$parts = explode('&', $parts[1]);
foreach($parts as $part) {
if(stristr($part, 'data')) {
$parts = explode('=', $part);
$gallery_id = explode('_', $parts[1]);
break;
}
}
}
if(count($gallery_id) > 0) {
return 'type: "smugmug", id: "'. $gallery_id[0] .'", key: "'. $gallery_id[1] .'"';
}
else {
return '';
}
}
/**
* @method get_nav_buttons
*/
public function get_nav_buttons()
{
$buttons = array();
if($this->settings->nav_type == 'buttons') {
if($this->settings->arrow_buttons) {
$buttons[] = '"prev"';
}
if($this->settings->play_button) {
$buttons[] = '"play"';
}
if($this->settings->arrow_buttons) {
$buttons[] = '"next"';
}
echo implode(',', $buttons);
}
}
/**
* @method get_nav_buttons_left
*/
public function get_nav_buttons_left()
{
$buttons = array();
if($this->settings->thumbs_button && $this->settings->nav_type != 'thumbs') {
$buttons[] = '"thumbs"';
}
if($this->settings->caption_button) {
$buttons[] = '"caption"';
}
if($this->settings->social_button) {
$buttons[] = '"social"';
}
if($this->settings->nav_type == 'thumbs') {
$buttons[] = '"prevPage"';
}
echo implode(',', $buttons);
}
/**
* @method get_nav_buttons_right
*/
public function get_nav_buttons_right()
{
$buttons = array();
if($this->settings->count) {
$buttons[] = '"count"';
}
if($this->settings->fs_button) {
$buttons[] = '"fullscreen"';
}
if($this->settings->nav_type == 'thumbs') {
$buttons[] = '"nextPage"';
}
echo implode(',', $buttons);
}
}
/**
* Register the module and its form settings.
*/
FLBuilder::register_module('FLSlideshowModule', array(
'general' => array(
'title' => __('General', 'fl-builder'),
'sections' => array(
'general' => array(
'title' => '',
'fields' => array(
'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')
)
)
),
'display' => array(
'title' => __('Display', 'fl-builder'),
'fields' => array(
'height' => array(
'type' => 'text',
'label' => __('Height', 'fl-builder'),
'default' => '500',
'maxlength' => '4',
'size' => '5',
'description' => 'px'
),
'color' => array(
'type' => 'select',
'label' => __('Skin Color', 'fl-builder'),
'default' => 'light',
'options' => array(
'light' => _x( 'Light', 'Color.', 'fl-builder' ),
'dark' => _x( 'Dark', 'Color.', 'fl-builder' )
),
'help' => __('If your overall theme/images are lighter in color, light will display buttons in a darker color scheme and vice versa for dark.', 'fl-builder')
),
'crop' => array(
'type' => 'select',
'label' => __('Crop', 'fl-builder'),
'default' => '0',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
),
'help' => __('Crop set to no will fit the slideshow images to the height you specify and keep the width proportional, whereas crop set to yes will fit the slideshow images to all sides of the content area while cropping the left and right to fit the height you specify.', 'fl-builder')
),
'protect' => array(
'type' => 'select',
'label' => __('Disable Right-Click', 'fl-builder'),
'default' => 'true',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
)
)
),
'click_action' => array(
'title' => __('Click Action', 'fl-builder'),
'fields' => array(
'click_action' => array(
'type' => 'select',
'label' => __('Type', 'fl-builder'),
'default' => 'none',
'options' => array(
'none' => _x( 'None', 'Click action type.', 'fl-builder' ),
'url' => __('Link', 'fl-builder')
),
'toggle' => array(
'url' => array(
'fields' => array('click_action_url')
)
),
'preview' => array(
'type' => 'none'
)
),
'click_action_url' => array(
'type' => 'link',
'label' => __('Link URL', 'fl-builder'),
'preview' => array(
'type' => 'none'
)
)
)
)
)
),
'playback' => array(
'title' => __('Playback', 'fl-builder'),
'sections' => array(
'general' => array(
'title' => '',
'fields' => array(
'auto_play' => array(
'type' => 'select',
'label' => __('Auto Play', 'fl-builder'),
'default' => 'true',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
)
),
'speed' => array(
'type' => 'text',
'label' => __('Speed', 'fl-builder'),
'default' => '3',
'size' => '5',
'description' => _x( 'seconds', 'Value unit for form field of time in seconds. Such as: "5 seconds"', 'fl-builder' )
),
'transition' => array(
'type' => 'select',
'label' => __('Transition', 'fl-builder'),
'default' => 'fade',
'options' => array(
'none' => _x( 'None', 'Slideshow transition.', 'fl-builder' ),
'fade' => __('Fade', 'fl-builder'),
'kenBurns' => __('Ken Burns', 'fl-builder'),
'slideHorizontal' => __('Slide Horizontal', 'fl-builder'),
'slideVertical' => __('Slide Vertical', 'fl-builder'),
'blinds' => __('Blinds', 'fl-builder'),
'bars' => __('Bars', 'fl-builder'),
'barsRandom' => __('Random Bars', 'fl-builder'),
'boxes' => __('Boxes', 'fl-builder'),
'boxesRandom' => __('Random Boxes', 'fl-builder'),
'boxesGrow' => __('Boxes Grow', 'fl-builder')
)
),
'transitionDuration' => array(
'type' => 'text',
'label' => __('Transition Speed', 'fl-builder'),
'default' => '1',
'size' => '5',
'description' => _x( 'seconds', 'Value unit for form field of time in seconds. Such as: "5 seconds"', 'fl-builder' )
),
'randomize' => array(
'type' => 'select',
'label' => __('Randomize Photos', 'fl-builder'),
'default' => 'false',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
)
)
)
)
),
'controls' => array(
'title' => __('Controls', 'fl-builder'),
'sections' => array(
'general' => array(
'title' => '',
'fields' => array(
'image_nav' => array(
'type' => 'select',
'label' => __('Navigation Arrows', 'fl-builder'),
'default' => 'true',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
),
'help' => __('Navigational arrows allow the visitor to freely move through the images in your slideshow. These are larger arrows that overlay your slideshow images and are separate from the control bar navigational arrows.', 'fl-builder')
)
)
),
'control_bar' => array(
'title' => __('Control Bar', 'fl-builder'),
'fields' => array(
'nav_type' => array(
'type' => 'select',
'label' => __('Nav Type', 'fl-builder'),
'default' => 'none',
'options' => array(
'none' => _x( 'None', 'Nav type.', 'fl-builder' ),
'buttons' => __('Buttons', 'fl-builder'),
'thumbs' => __('Thumbs', 'fl-builder')
),
'toggle' => array(
'buttons' => array(
'sections' => array('control_bar_buttons', 'control_bar_overlay', 'thumbs', 'social'),
'fields' => array('nav_position', 'arrow_buttons', 'thumbs_button')
),
'thumbs' => array(
'sections' => array('control_bar_buttons', 'control_bar_overlay', 'thumbs', 'social'),
'fields' => array('nav_position')
)
)
),
'nav_position' => array(
'type' => 'select',
'label' => __('Nav Position', 'fl-builder'),
'default' => 'bottom',
'options' => array(
'bottom' => __('Bottom', 'fl-builder'),
'top' => __('Top', 'fl-builder')
)
)
)
),
'control_bar_buttons' => array(
'title' => __('Control Bar Buttons', 'fl-builder'),
'fields' => array(
'arrow_buttons' => array(
'type' => 'select',
'label' => __('Navigation Arrows', 'fl-builder'),
'default' => '1',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
)
),
'play_button' => array(
'type' => 'select',
'label' => __('Play Button', 'fl-builder'),
'default' => '1',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
)
),
'fs_button' => array(
'type' => 'select',
'label' => __('Fullscreen Button', 'fl-builder'),
'default' => '1',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
)
),
'count' => array(
'type' => 'select',
'label' => __('Photo Count', 'fl-builder'),
'default' => '1',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
)
),
'thumbs_button' => array(
'type' => 'select',
'label' => __('Thumbs Button', 'fl-builder'),
'default' => '1',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
)
),
'caption_button' => array(
'type' => 'select',
'label' => __('Caption Button', 'fl-builder'),
'default' => '1',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
)
),
'social_button' => array(
'type' => 'select',
'label' => __('Social Button', 'fl-builder'),
'default' => '1',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
)
)
)
),
'control_bar_overlay' => array(
'title' => __('Control Bar Overlay', 'fl-builder'),
'fields' => array(
'nav_overlay' => array(
'type' => 'select',
'label' => __('Overlay Enabled', 'fl-builder'),
'default' => '0',
'options' => array(
'0' => __('No', 'fl-builder'),
'1' => __('Yes', 'fl-builder')
),
'toggle' => array(
'1' => array(
'fields' => array('overlay_hide', 'overlay_hide_delay')
)
),
'help' => __('Control bar overlay specifies if the control bar buttons you choose overlay your slideshow images or site below the slideshow completely.', 'fl-builder')
),
'overlay_hide' => array(
'type' => 'select',
'label' => __('Overlay Hide', 'fl-builder'),
'default' => 'true',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
),
'help' => __('Overlay hide will hide the control bar after however many seconds you specify below. They will reappear upon mouse over.', 'fl-builder')
),
'overlay_hide_delay' => array(
'type' => 'text',
'label' => __('Overlay Hide Delay', 'fl-builder'),
'default' => '3',
'size' => '5',
'description' => _x( 'seconds', 'Value unit for form field of time in seconds. Such as: "5 seconds"', 'fl-builder' )
)
)
),
'thumbs' => array(
'title' => __('Thumbs', 'fl-builder'),
'fields' => array(
'thumbs_size' => array(
'type' => 'text',
'label' => __('Thumbs Size', 'fl-builder'),
'default' => '50',
'maxlength' => '3',
'size' => '5',
'description' => 'px'
)
)
),
'social' => array(
'title' => __('Social', 'fl-builder'),
'fields' => array(
'facebook' => array(
'type' => 'select',
'label' => __('Facebook Button', 'fl-builder'),
'default' => 'true',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
),
'twitter' => array(
'type' => 'select',
'label' => __('Twitter Button', 'fl-builder'),
'default' => 'true',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
),
'google' => array(
'type' => 'select',
'label' => __('Google Plus Button', 'fl-builder'),
'default' => 'true',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
),
'pinterest' => array(
'type' => 'select',
'label' => __('Pinterest Button', 'fl-builder'),
'default' => 'true',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder')
),
'preview' => array(
'type' => 'none'
)
)
)
)
)
)
));