post-slider.php
23.6 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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
<?php
/**
* @class FLPostSliderModule
*/
class FLPostSliderModule extends FLBuilderModule {
/**
* @method __construct
*/
public function __construct()
{
parent::__construct(array(
'name' => __('Posts Slider', 'fl-builder'),
'description' => __('Display a slider of your WordPress posts.', 'fl-builder'),
'category' => __('高级模块', 'fl-builder'),
'editor_export' => false,
'partial_refresh' => true
));
$this->add_css('jquery-bxslider');
$this->add_js('jquery-bxslider');
}
/**
* Remove pagination parameters
*
* @param array $query_args Generated query args to override
* @return array Updated query args
*/
public function remove_pagination_args($query_args){
$query_args['paged'] = 0;
$query_args['offset'] = isset($this->settings->offset) ? $this->settings->offset : 0;
return $query_args;
}
/**
* Full attachment image url.
*
* Gets a post ID and returns the url for the 'full' size of the attachment
* set as featured image.
*
* @param int $id The post ID.
* @since 1.5.9
* @return string The featured image url for the 'full' size.
*/
public function get_full_img_src( $id ){
$thumb_id = get_post_thumbnail_id( $id );
$size = isset( $this->settings->thumb_size ) ? $this->settings->thumb_size : 'medium';
$img = wp_get_attachment_image_src( $thumb_id, $size );
return $img[0];
}
/**
* Get the featured image data.
*
* Gets a post ID and returns an array containing the featured image data.
*
* @param int $id The post ID.
* @since 1.5.9
* @return array The image data.
*/
protected function _get_img_data( $id ){
$thumb_id = get_post_thumbnail_id( $id );
return FLBuilderPhoto::get_attachment_data( $thumb_id );
}
/**
* Build post slider array.
*
* Get all the query parameters and build an array with posts ID's as keys
* and the featured image's url (in 'full size') as values.
*
* @since 1.5.9
* @return array the array with all the posts ID's and featured image url's.
*
*/
public function _build_posts_array(){
// checks if the post_slides array is cached
if( !isset( $this->post_slides ) ){
// if not, create it
$this->post_slides = array();
// check if we have selected posts
if( empty( $this->settings->posts_post ) ){
// if not, create a default query with it
$settings = !empty( $this->settings ) ? $this->settings : new stdClass();
// set WP_Query "fields" arg as 'ids' to return less information
$settings->fields = 'ids';
// Get the query data.
$query = FLBuilderLoop::query( $settings );
// build the post_slides array with post id's and featured image url's
foreach( $query->posts as $key => $id ){
$this->post_slides[ $id ] = $this->get_full_img_src( $id );
}
} else{
// if yes, get the selected posts and build the post_slides array
$slides = explode( ',', $this->settings->posts_post );
foreach( $slides as $key => $id ){
$this->post_slides[$id] = $this->get_full_img_src( $id );
}
}
}
return $this->post_slides;
}
/**
* The uncropped url.
*
* Get's a post ID and returns the uncropped url for its featured image.
*
* @param int $id The post ID.
* @since 1.5.9
* @return string The featured image url for the 'full' size.
*/
public function _get_uncropped_url( $id ){
$posts = $this->_build_posts_array();
return $posts[$id];
}
/**
* Render thumbnail image.
*
* Get's the post ID and renders the html markup for the featured image
* in the desired cropped size.
*
* @param int $id The post ID.
* @since 1.5.9
* @return void
*/
public function render_img( $id ) {
// check if image_type is set
if( isset( $this->settings->image_type ) ){
// check if the choosed image type for featured image is "thumb" or "background"
if( $this->settings->image_type == 'thumb' ){
// get image source and data
$src = $this->_get_uncropped_url( $id );
$photo_data = $this->_get_img_data( $id );
// get alignment option, otherwise set the default to "left"
$align = isset( $this->settings->thumb_text_position ) ? $this->settings->thumb_text_position : 'left';
// set params
$photo_settings = array(
'align' => $align,
'crop' => $this->settings->thumb_crop,
'link_type' => 'url',
'link_url' => get_the_permalink( $id ),
'photo' => $photo_data,
'photo_src' => $src,
'photo_source' => 'library'
);
// render image
echo '<div class="fl-post-slider-img">';
FLBuilder::render_module_html( 'photo', $photo_settings );
echo '</div>';
} elseif( $this->settings->image_type == 'background' ){
// if background is selected as image size, render background markup
echo '<div class="fl-slide-bg-photo fl-post-no-height" style="background-image: url('. $this->get_full_img_src( $id ) .')"></div>';
echo '<div class="fl-post-slider-content-bg fl-post-no-height"></div>';
}
}
}
/**
* Render thumbnail image for mobile.
*
* Get's the post ID and renders the html markup for the featured image
* in the desired cropped size.
*
* @param int $id The post ID.
* @since 1.5.9
* @return void
*/
public function render_mobile_img( $id ) {
// check if image_type is set
if( isset( $this->settings->image_type ) ){
// check if "background" is choosed as image type for featured image
if( $this->settings->image_type == 'background' ){
// get image source and data
$src = $this->_get_uncropped_url( $id );
$photo_data = $this->_get_img_data( $id );
// set params
$photo_settings = array(
'align' => 'center',
'link_type' => 'url',
'link_url' => get_the_permalink( $id ),
'photo' => $photo_data,
'photo_src' => $src,
'photo_source' => 'library'
);
// render image
echo '<div class="fl-post-slider-mobile-img">';
FLBuilder::render_module_html( 'photo', $photo_settings );
echo '</div>';
}
}
}
/**
* Render slider title.
*
* Get's the post ID and renders the html markup for the slider title
*
* @param int $id The post ID.
* @since 1.5.9
* @return void
*/
public function render_post_title( $id ) {
// get choosed tag, otherwise set default to h2
$tag = !empty( $this->settings->title_tag ) ? $this->settings->title_tag : 'h2';
// build markup
$title = '<' . $tag . ' class="fl-post-slider-title" itemprop="headline">';
$title .= '<a href="'. get_the_permalink( $id ) .'" rel="bookmark" title="'. the_title_attribute( array( 'echo' => false, 'post' => $id ) ) .'">'. get_the_title( $id ) .'</a>';
$title .= '</' . $tag . '>';
echo $title;
}
/**
* Get slider css class.
*
* Get's the post ID, checks if the post has a thumbnail and the image_type
* setting, and then returns the specific slider class.
*
* @param int $id The post ID.
* @since 1.5.9
* @return string The slider class.
*/
public function get_slider_class( $id ){
// check if the post has a featured image, and if the slider module is set to show it
if( has_post_thumbnail( $id ) && $this->settings->show_thumb == 'show' ){
// if so, check if image_type is set and return it, otherwise set the default to "no-thumb"
if( isset( $this->settings->image_type ) ){
return $this->settings->image_type;
} else{
return 'no-thumb';
}
} else{
return 'no-thumb';
}
}
/**
* Render the css code for background with gradients.
*
* @since 1.5.9
* @return void
*/
public function render_slider_gradient_bg(){
if( empty( $this->settings->text_bg_color ) || empty( $this->settings->text_bg_opacity ) )
return;
// set defaults
$color_start = 'rgba('. implode( ',', FLBuilderColor::hex_to_rgb( $this->settings->text_bg_color ) ) .','. ( $this->settings->text_bg_opacity/100 ) .')';
$color_end = 'rgba('. implode( ',', FLBuilderColor::hex_to_rgb( $this->settings->text_bg_color ) ) .',0)';
// check if bg_gradient is set to "yes"
if( isset( $this->settings->bg_gradient ) && $this->settings->bg_gradient == 'yes' ){
// if so, set positions for each vendor prefix
if( isset( $this->settings->text_position ) ){
switch ( $this->settings->text_position ) {
case 'left':
$direction = 'left';
$wk_direction = 'left top, right top';
$ie_direction = 'to right';
break;
case 'right':
$direction = 'right';
$wk_direction = 'right top, left top';
$ie_direction = 'to left';
break;
case 'bottom':
$direction = 'bottom';
$wk_direction = 'left bottom, left top';
$ie_direction = 'to top';
break;
}
}
// build csss gradient code
$bg = 'background: #'. $this->settings->text_bg_color .';';
$bg .= 'background: -ms-linear-gradient('. $direction .', '. $color_start .' 0%, '. $color_end .' 100%);';
$bg .= 'background: -moz-linear-gradient('. $direction .', '. $color_start .' 0%, '. $color_end .' 100%);';
$bg .= 'background: -o-linear-gradient('. $direction .', '. $color_start .' 0%, '. $color_end .' 100%);';
$bg .= 'background: -webkit-gradient(linear, '. $wk_direction .', color-stop(0, '. $color_start .'), color-stop(1, '. $color_end .'));';
$bg .= 'background: -webkit-linear-gradient('. $direction .', '. $color_start .' 0%, '. $color .' 100%);';
$bg .= 'background: linear-gradient('. $ie_direction .', '. $color_start .' 0%, '. $color_end .' 100%);';
} else{
// if gradient isn't selected, set the background with default values
$bg = 'background-color: #'. $this->settings->text_bg_color .';';
$bg .= 'background-color: '. $color_start .';';
}
echo $bg;
}
}
/**
* Register the module and its form settings.
*/
FLBuilder::register_module('FLPostSliderModule', array(
'slider' => array(
'title' => __('Slider', 'fl-builder'),
'sections' => array(
'general' => array(
'title' => '',
'fields' => array(
'height' => array(
'type' => 'text',
'label' => __('Height', 'fl-builder'),
'default' => '400',
'maxlength' => '4',
'size' => '5',
'description' => 'px',
'help' => __('This setting is the minimum height of the post slider. Content will expand the height automatically.', 'fl-builder')
),
'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' => __('Delay', 'fl-builder'),
'default' => '5',
'size' => '5',
'description' => _x( 'seconds', 'Value unit for form field of time in seconds. Such as: "5 seconds"', 'fl-builder' )
),
'slider_loop' => array(
'type' => 'select',
'label' => __('Loop', 'fl-builder'),
'default' => 'false',
'options' => array(
'false' => __('No', 'fl-builder'),
'true' => __('Yes', 'fl-builder'),
)
),
'transition' => array(
'type' => 'select',
'label' => __('Transition', 'fl-builder'),
'default' => 'horizontal',
'options' => array(
'fade' => __('Fade', 'fl-builder'),
'horizontal' => __('Slide', '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' )
),
'posts_per_page' => array(
'type' => 'text',
'label' => __('Number of Posts', 'fl-builder'),
'default' => '10',
'size' => '4'
),
)
),
'controls' => array(
'title' => __('Slider Controls', 'fl-builder'),
'fields' => array(
'pagination' => array(
'type' => 'select',
'label' => __('Show Dots', 'fl-builder'),
'default' => 'yes',
'options' => array(
'no' => __('No', 'fl-builder'),
'yes' => __('Yes', 'fl-builder'),
)
),
'navigation' => array(
'type' => 'select',
'label' => __('Show Arrows', 'fl-builder'),
'default' => 'no',
'options' => array(
'no' => __('No', 'fl-builder'),
'yes' => __('Yes', 'fl-builder'),
),
'toggle' => array(
'yes' => array(
'fields' => ( 'nav_arrow_color' )
)
)
),
)
),
)
),
'layout' => array(
'title' => __( 'Layout', 'fl-builder' ),
'sections' => array(
'featured_img' => array(
'title' => '',
'fields' => array(
'show_thumb' => array(
'type' => 'select',
'label' => __( 'Show Featured Image?', 'fl-builder' ),
'default' => 'show',
'options' => array(
'show' => __( 'Show', 'fl-builder' ),
'hide' => __( 'Hide', 'fl-builder' )
),
'toggle' => array(
'show' => array(
'sections' => array( 'image' ),
'fields' => array( 'text_position', 'text_width' )
),
)
),
)
),
'image' => array(
'title' => __( 'Featured Image', 'fl-builder' ),
'fields' => array(
'image_type' => array(
'type' => 'select',
'label' => __( 'Image', 'fl-builder' ),
'default' => 'background',
'options' => array(
'background' => __( 'Background', 'fl-builder' ),
'thumb' => __( 'Thumbnail', 'fl-builder' )
),
'toggle' => array(
'background' => array(
'fields' => array( 'text_position', 'thumb_size' )
),
'thumb' => array(
'fields' => array( 'thumb_crop', 'thumb_size', 'thumb_text_position' )
)
)
),
'thumb_size' => array(
'type' => 'photo-sizes',
'label' => __( 'Size', 'fl-builder' ),
'default' => 'large',
),
'thumb_crop' => array(
'type' => 'select',
'label' => __( 'Crop', 'fl-builder' ),
'default' => 'landscape',
'options' => array(
'' => _x( 'None', 'Photo Crop.', 'fl-builder' ),
'landscape' => __( 'Landscape', 'fl-builder' ),
'panorama' => __( 'Panorama', 'fl-builder' ),
'portrait' => __( 'Portrait', 'fl-builder' ),
'square' => __( 'Square', 'fl-builder' ),
'circle' => __( 'Circle', 'fl-builder' )
)
),
)
),
'info' => array(
'title' => __( 'Post Info', 'fl-builder' ),
'fields' => array(
'show_author' => array(
'type' => 'select',
'label' => __( 'Author', 'fl-builder' ),
'default' => '1',
'options' => array(
'1' => __( 'Show', 'fl-builder' ),
'0' => __( 'Hide', 'fl-builder' )
)
),
'show_date' => array(
'type' => 'select',
'label' => __( 'Date', 'fl-builder' ),
'default' => '1',
'options' => array(
'1' => __( 'Show', 'fl-builder' ),
'0' => __( 'Hide', 'fl-builder' )
),
'toggle' => array(
'1' => array(
'fields' => array( 'date_format' )
)
)
),
'date_format' => array(
'type' => 'select',
'label' => __( 'Date Format', 'fl-builder' ),
'default' => 'default',
'options' => array(
'default' => __('Default', 'fl-builder'),
'M j, Y' => date( 'M j, Y' ),
'F j, Y' => date( 'F j, Y' ),
'm/d/Y' => date( 'm/d/Y' ),
'm-d-Y' => date( 'm-d-Y' ),
'd M Y' => date( 'd M Y' ),
'd F Y' => date( 'd F Y' ),
'Y-m-d' => date( 'Y-m-d' ),
'Y/m/d' => date( 'Y/m/d' ),
)
),
'show_comments' => array(
'type' => 'select',
'label' => __('Comments', 'fl-builder'),
'default' => '1',
'options' => array(
'1' => __('Show', 'fl-builder'),
'0' => __('Hide', 'fl-builder')
)
),
)
),
'content' => array(
'title' => __( 'Content', 'fl-builder' ),
'fields' => array(
'show_content' => array(
'type' => 'select',
'label' => __('Content', 'fl-builder'),
'default' => '1',
'options' => array(
'1' => __('Show', 'fl-builder'),
'0' => __('Hide', 'fl-builder')
)
),
'show_more_link' => array(
'type' => 'select',
'label' => __('More Link', 'fl-builder'),
'default' => '0',
'options' => array(
'1' => __('Show', 'fl-builder'),
'0' => __('Hide', 'fl-builder')
)
),
'more_link_text' => array(
'type' => 'text',
'label' => __('More Link Text', 'fl-builder'),
'default' => __('Read More', 'fl-builder'),
),
)
)
),
),
'style' => array( // Tab
'title' => __('Style', 'fl-builder'), // Tab title
'sections' => array( // Tab Sections
'title' => array(
'title' => __('Heading', 'fl-builder'),
'fields' => array(
'title_tag' => array(
'type' => 'select',
'label' => __('Heading Tag', 'fl-builder'),
'default' => 'h2',
'options' => array(
'h1' => 'h1',
'h2' => 'h2',
'h3' => 'h3',
'h4' => 'h4',
'h5' => 'h5',
'h6' => 'h6'
)
),
'title_size' => array(
'type' => 'select',
'label' => __('Heading Size', 'fl-builder'),
'default' => 'default',
'options' => array(
'default' => __('Default', 'fl-builder'),
'custom' => __('Custom', 'fl-builder')
),
'toggle' => array(
'custom' => array(
'fields' => array('title_custom_size')
)
)
),
'title_custom_size' => array(
'type' => 'text',
'label' => __('Heading Size', 'fl-builder'),
'default' => '24',
'maxlength' => '3',
'size' => '4',
'description' => 'px',
)
)
),
'text_position' => array(
'title' => __('Text', 'fl-builder'),
'fields' => array(
'text_position' => array(
'type' => 'select',
'label' => __('Position', 'fl-builder'),
'default' => 'left',
'help' => __('The position will move the content layout selections left, right or bottom over the background of the slide.', 'fl-builder'),
'options' => array(
'left' => __('Left', 'fl-builder'),
'right' => __('Right', 'fl-builder'),
'bottom' => __('Bottom', 'fl-builder'),
),
'toggle' => array(
'left' => array(
'fields' => array('text_width')
),
'right' => array(
'fields' => array('text_width')
)
)
),
'thumb_text_position' => array(
'type' => 'select',
'label' => __('Position', 'fl-builder'),
'default' => 'left',
'help' => __('The position will move the content layout selections left or right or center of the thumbnail of the slide.', 'fl-builder'),
'options' => array(
'left' => __('Left', 'fl-builder'),
'right' => __('Right', 'fl-builder'),
),
'toggle' => array(
'left' => array(
'fields' => array('text_width')
),
'right' => array(
'fields' => array('text_width')
)
)
),
'text_width' => array(
'type' => 'text',
'label' => __('Text Width', 'fl-builder'),
'default' => '50',
'description' => '%',
'maxlength' => '3',
'size' => '5'
),
'text_padding' => array(
'type' => 'text',
'label' => __('Text Padding', 'fl-builder'),
'default' => '50',
'description' => 'px',
'maxlength' => '4',
'size' => '5'
),
)
),
'text_style' => array(
'title' => __('Colors', 'fl-builder'),
'fields' => array(
'text_color' => array(
'type' => 'color',
'label' => __('Text Color', 'fl-builder'),
'show_reset' => true,
'default' => 'ffffff',
'preview' => array(
'type' => 'css',
'rules' => array(
array(
'selector' => '.fl-post-slider-background .fl-post-slider-content, .fl-post-slider-thumb, .fl-post-slider-no-thumb',
'property' => 'color',
)
)
)
),
'link_color' => array(
'type' => 'color',
'label' => __('Link Color', 'fl-builder'),
'show_reset' => true,
'default' => 'cccccc',
'preview' => array(
'type' => 'css',
'rules' => array(
array(
'selector' => '.fl-post-slider-content a',
'property' => 'color',
)
)
)
),
'link_hover_color' => array(
'type' => 'color',
'label' => __('Link Hover Color', 'fl-builder'),
'default' => 'ffffff',
'show_reset' => true
),
'text_bg_color' => array(
'type' => 'color',
'label' => __('Text Background Color', 'fl-builder'),
'help' => __('The color applies to the overlay behind text over the background selections.', 'fl-builder'),
'default' => '333333',
'show_reset' => true
),
'text_bg_opacity' => array(
'type' => 'text',
'label' => __('Text Background Opacity', 'fl-builder'),
'default' => '50',
'maxlength' => '3',
'size' => '4',
'description' => '%'
),
'bg_gradient' => array(
'type' => 'select',
'label' => __('Text Background Gradient', 'fl-builder'),
'default' => 'no',
'options' => array(
'no' => __( 'No', 'fl-builder' ),
'yes' => __( 'Yes', 'fl-builder' ),
)
),
'text_bg_height' => array(
'type' => 'select',
'label' => __('Text Background Height', 'fl-builder'),
'default' => '100%',
'help' => __('Auto will allow the overlay to fit however long the text content is. 100% will fit the overlay to the top and bottom of the slide.', 'fl-builder'),
'options' => array(
'auto' => _x( 'Auto', 'Background height.', 'fl-builder' ),
'100%' => '100%'
)
),
)
)
)
),
'content' => array(
'title' => __('Content', 'fl-builder'),
'file' => FL_BUILDER_DIR . 'includes/loop-settings.php',
)
));