|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class used to handle paging for gallery templates |
|
4
|
|
|
*/ |
|
5
|
|
|
if ( ! class_exists( 'FooGallery_Paging' ) ) { |
|
6
|
|
|
|
|
7
|
|
|
class FooGallery_Paging { |
|
8
|
|
|
|
|
9
|
|
|
function __construct() { |
|
|
|
|
|
|
10
|
|
|
if ( is_admin() ) { |
|
11
|
|
|
//add extra fields to the templates that support lazy loading |
|
12
|
|
|
add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_paging_fields' ), 10, 2 ); |
|
13
|
|
|
|
|
14
|
|
|
//build up any preview arguments |
|
15
|
|
|
add_filter( 'foogallery_preview_arguments', array( $this, 'preview_arguments' ), 10, 3 ); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
//adds the paging property to a FooGallery |
|
19
|
|
|
add_action( 'foogallery_foogallery_instance_after_load', array( $this, 'determine_paging' ), 10, 2 ); |
|
20
|
|
|
|
|
21
|
|
|
//add the paging attributes to the gallery container |
|
22
|
|
|
add_filter( 'foogallery_build_container_data_options', array( $this, 'add_paging_options' ), 10, 3 ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Add paging fields to the gallery template |
|
27
|
|
|
* |
|
28
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
|
29
|
|
|
* @param $fields |
|
30
|
|
|
* @param $template |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
function add_paging_fields( $fields, $template ) { |
|
|
|
|
|
|
35
|
|
|
if ( $template && array_key_exists( 'paging_support', $template ) && true === $template['paging_support'] ) { |
|
36
|
|
|
$fields[] = array( |
|
37
|
|
|
'id' => 'paging_type', |
|
38
|
|
|
'title' => __( 'Paging', 'foogallery' ), |
|
39
|
|
|
'desc' => __( 'Add paging to a large gallery.', 'foogallery' ), |
|
40
|
|
|
'section' => __( 'Paging', 'foogallery' ), |
|
41
|
|
|
'spacer' => '<span class="spacer"></span>', |
|
42
|
|
|
'type' => 'radio', |
|
43
|
|
|
'choices' => apply_filters( 'foogallery_gallery_template_paging_choices', array( |
|
44
|
|
|
'' => __( 'None', 'foogallery' ), |
|
45
|
|
|
'dots' => __( 'Dots', 'foogallery' ), |
|
46
|
|
|
'pagination' => __( 'Pagination', 'foogallery' ), |
|
47
|
|
|
'infinite' => __( 'Infinite Scroll', 'foogallery' ), |
|
48
|
|
|
'loadMore' => __( 'Load More', 'foogallery' ) |
|
49
|
|
|
) ), |
|
50
|
|
|
'row_data'=> array( |
|
51
|
|
|
'data-foogallery-change-selector' => 'input', |
|
52
|
|
|
'data-foogallery-preview' => 'shortcode' |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $fields; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Determine if the gallery has paging enabled |
|
62
|
|
|
* |
|
63
|
|
|
* @param $foogallery FooGallery |
|
64
|
|
|
* @param $post |
|
65
|
|
|
*/ |
|
66
|
|
|
function determine_paging( $foogallery, $post ) { |
|
|
|
|
|
|
67
|
|
|
//always disable paging by default |
|
68
|
|
|
$paging = $foogallery->get_setting( 'paging_type', '' ) !== ''; |
|
69
|
|
|
|
|
70
|
|
|
$foogallery->paging = apply_filters( 'foogallery_paging', $paging, $foogallery ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Add the required paging options if needed |
|
75
|
|
|
* |
|
76
|
|
|
* @param $attributes array |
|
77
|
|
|
* @param $gallery FooGallery |
|
78
|
|
|
* |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
|
|
function add_paging_options($options, $gallery, $attributes) { |
|
|
|
|
|
|
82
|
|
|
if ( isset( $gallery->paging ) && true === $gallery->paging) { |
|
83
|
|
|
|
|
84
|
|
|
//check if we have arguments from the shortcode and override the saved settings |
|
85
|
|
|
global $current_foogallery_arguments; |
|
86
|
|
|
if ( isset( $current_foogallery_arguments ) && isset( $current_foogallery_arguments['paging'] ) ) { |
|
87
|
|
|
$paging = $current_foogallery_arguments['paging']; |
|
88
|
|
|
} else { |
|
89
|
|
|
$paging = $gallery->get_setting( 'paging_type', '' ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$options['paging'] = array( |
|
93
|
|
|
'type' => $paging, |
|
94
|
|
|
'theme' => 'fg-light', |
|
95
|
|
|
'size' => 3, |
|
96
|
|
|
'position' => 'both', |
|
97
|
|
|
'scrollToTop' => true |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
return $options; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Build up a arguments used in the preview of the gallery |
|
105
|
|
|
* |
|
106
|
|
|
* @param $args |
|
107
|
|
|
* @param $post_data |
|
108
|
|
|
* @param $template |
|
109
|
|
|
* |
|
110
|
|
|
* @return mixed |
|
111
|
|
|
*/ |
|
112
|
|
|
function preview_arguments( $args, $post_data, $template ) { |
|
|
|
|
|
|
113
|
|
|
$template_data = foogallery_get_gallery_template( $template ); |
|
114
|
|
|
$post_key = $template. '_paging_type'; |
|
115
|
|
|
|
|
116
|
|
|
//check the template supports paging |
|
117
|
|
|
if ( $template_data && array_key_exists( 'paging_support', $template_data ) && true === $template_data['paging_support'] ) { |
|
118
|
|
|
$args['paging'] = $post_data[FOOGALLERY_META_SETTINGS][$post_key]; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $args; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.