1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( !class_exists( 'FooGallery_Default_Gallery_Template' ) ) { |
4
|
|
|
|
5
|
|
|
define('FOOGALLERY_DEFAULT_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
6
|
|
|
|
7
|
|
|
class FooGallery_Default_Gallery_Template { |
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Wire up everything we need to run the extension |
10
|
|
|
*/ |
11
|
|
|
function __construct() { |
|
|
|
|
12
|
|
|
add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) ); |
13
|
|
|
|
14
|
|
|
add_action( 'foogallery_located_template-default', array( $this, 'enqueue_dependencies' ) ); |
15
|
|
|
|
16
|
|
|
add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
17
|
|
|
|
18
|
|
|
//build up any preview arguments |
19
|
|
|
add_filter( 'foogallery_preview_arguments-default', array( $this, 'preview_arguments' ), 10, 2 ); |
20
|
|
|
|
21
|
|
|
//build up the thumb dimensions from some arguments |
22
|
|
|
add_filter( 'foogallery_calculate_thumbnail_dimensions-default', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 ); |
23
|
|
|
|
24
|
|
|
//build up the thumb dimensions on save |
25
|
|
|
add_filter( 'foogallery_template_thumbnail_dimensions-default', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
30
|
|
|
* @param $extensions |
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
35
|
|
|
$extensions[] = __FILE__; |
36
|
|
|
return $extensions; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Add our gallery template to the list of templates available for every gallery |
41
|
|
|
* @param $gallery_templates |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
46
|
|
|
$gallery_templates[] = array( |
47
|
|
|
'slug' => 'default', |
48
|
|
|
'name' => __( 'Responsive Image Gallery', 'foogallery' ), |
49
|
|
|
'preview_support' => true, |
50
|
|
|
'common_fields_support' => true, |
51
|
|
|
'paging_support' => true, |
52
|
|
|
'lazyload_support' => true, |
53
|
|
|
'mandatory_classes' => 'fg-default', |
54
|
|
|
'thumbnail_dimensions' => true, |
55
|
|
|
'fields' => array( |
56
|
|
|
array( |
57
|
|
|
'id' => 'thumbnail_dimensions', |
58
|
|
|
'title' => __( 'Thumbnail Size', 'foogallery' ), |
59
|
|
|
'desc' => __( 'Choose the size of your thumbnails.', 'foogallery' ), |
60
|
|
|
'section' => __( 'General', 'foogallery' ), |
61
|
|
|
'type' => 'thumb_size_no_crop', |
62
|
|
|
'default' => array( |
63
|
|
|
'width' => get_option( 'thumbnail_size_w' ), |
64
|
|
|
'height' => get_option( 'thumbnail_size_h' ), |
65
|
|
|
), |
66
|
|
|
'row_data'=> array( |
67
|
|
|
'data-foogallery-change-selector' => 'input', |
68
|
|
|
'data-foogallery-preview' => 'shortcode' |
69
|
|
|
) |
70
|
|
|
), |
71
|
|
|
array( |
72
|
|
|
'id' => 'thumbnail_link', |
73
|
|
|
'title' => __( 'Link To', 'foogallery' ), |
74
|
|
|
'section' => __( 'General', 'foogallery' ), |
75
|
|
|
'default' => 'image', |
76
|
|
|
'type' => 'thumb_link', |
77
|
|
|
'desc' => __( 'You can choose to link each thumbnail to the full size image, the image\'s attachment page, a custom URL, or you can choose to not link to anything.', 'foogallery' ), |
78
|
|
|
), |
79
|
|
|
array( |
80
|
|
|
'id' => 'lightbox', |
81
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
82
|
|
|
'desc' => __( 'Choose which lightbox you want to use. The lightbox will generally only work if you set the thumbnail link to "Full Size Image".', 'foogallery' ), |
83
|
|
|
'section' => __( 'General', 'foogallery' ), |
84
|
|
|
'type' => 'lightbox', |
85
|
|
|
'default' => 'none', |
86
|
|
|
'row_data'=> array( |
87
|
|
|
'data-foogallery-change-selector' => 'select' |
88
|
|
|
) |
89
|
|
|
), |
90
|
|
|
array( |
91
|
|
|
'id' => 'lightbox_foobox_help', |
92
|
|
|
'title' => __( 'FooBox Help', 'foogallery' ), |
93
|
|
|
'desc' => __( 'The FooBox lightbox is a separate plugin.', 'foogallery' ), |
94
|
|
|
'section' => __( 'General', 'foogallery' ), |
95
|
|
|
'type' => 'help', |
96
|
|
|
'row_data'=> array( |
97
|
|
|
'data-foogallery-hidden' => true, |
98
|
|
|
'data-foogallery-show-when-field' => 'lightbox', |
99
|
|
|
'data-foogallery-show-when-field-value' => 'foobox' |
100
|
|
|
) |
101
|
|
|
), |
102
|
|
|
array( |
103
|
|
|
'id' => 'spacing', |
104
|
|
|
'title' => __( 'Spacing', 'foogallery' ), |
105
|
|
|
'desc' => __( 'The spacing or gap between thumbnails in the gallery.', 'foogallery' ), |
106
|
|
|
'section' => __( 'General', 'foogallery' ), |
107
|
|
|
'type' => 'select', |
108
|
|
|
'default' => 'fg-gutter-10', |
109
|
|
|
'choices' => array( |
110
|
|
|
'fg-gutter-0' => __( 'none', 'foogallery' ), |
111
|
|
|
'fg-gutter-5' => __( '5 pixels', 'foogallery' ), |
112
|
|
|
'fg-gutter-10' => __( '10 pixels', 'foogallery' ), |
113
|
|
|
'fg-gutter-15' => __( '15 pixels', 'foogallery' ), |
114
|
|
|
'fg-gutter-20' => __( '20 pixels', 'foogallery' ), |
115
|
|
|
'fg-gutter-25' => __( '25 pixels', 'foogallery' ), |
116
|
|
|
), |
117
|
|
|
'row_data'=> array( |
118
|
|
|
'data-foogallery-change-selector' => 'select', |
119
|
|
|
'data-foogallery-preview' => 'class' |
120
|
|
|
) |
121
|
|
|
), |
122
|
|
|
array( |
123
|
|
|
'id' => 'alignment', |
124
|
|
|
'title' => __( 'Alignment', 'foogallery' ), |
125
|
|
|
'desc' => __( 'The horizontal alignment of the thumbnails inside the gallery.', 'foogallery' ), |
126
|
|
|
'section' => __( 'General', 'foogallery' ), |
127
|
|
|
'default' => 'fg-center', |
128
|
|
|
'type' => 'radio', |
129
|
|
|
'spacer' => '<span class="spacer"></span>', |
130
|
|
|
'choices' => array( |
131
|
|
|
'fg-left' => __( 'Left', 'foogallery' ), |
132
|
|
|
'fg-center' => __( 'Center', 'foogallery' ), |
133
|
|
|
'fg-right' => __( 'Right', 'foogallery' ), |
134
|
|
|
), |
135
|
|
|
'row_data'=> array( |
136
|
|
|
'data-foogallery-change-selector' => 'input:radio', |
137
|
|
|
'data-foogallery-preview' => 'class' |
138
|
|
|
) |
139
|
|
|
) |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
return $gallery_templates; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Enqueue scripts that the default gallery template relies on |
148
|
|
|
*/ |
149
|
|
|
function enqueue_dependencies( $gallery ) { |
|
|
|
|
150
|
|
|
//enqueue core files |
151
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
152
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Build up a arguments used in the preview of the gallery |
157
|
|
|
* @param $args |
158
|
|
|
* @param $post_data |
159
|
|
|
* |
160
|
|
|
* @return mixed |
161
|
|
|
*/ |
162
|
|
|
function preview_arguments( $args, $post_data ) { |
|
|
|
|
163
|
|
|
$args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['default_thumbnail_dimensions']; |
164
|
|
|
return $args; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Builds thumb dimensions from arguments |
169
|
|
|
* |
170
|
|
|
* @param array $dimensions |
171
|
|
|
* @param array $arguments |
172
|
|
|
* |
173
|
|
|
* @return mixed |
174
|
|
|
*/ |
175
|
|
|
function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) { |
|
|
|
|
176
|
|
|
return array( |
177
|
|
|
'height' => intval( $arguments['thumbnail_dimensions']['height'] ), |
178
|
|
|
'width' => intval( $arguments['thumbnail_dimensions']['width'] ), |
179
|
|
|
'crop' => '1' |
180
|
|
|
); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template |
185
|
|
|
* |
186
|
|
|
* @param array $dimensions |
187
|
|
|
* @param FooGallery $foogallery |
188
|
|
|
* |
189
|
|
|
* @return mixed |
190
|
|
|
*/ |
191
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
|
|
|
|
192
|
|
|
$dimensions = $foogallery->get_meta( 'default_thumbnail_dimensions', array( |
193
|
|
|
'width' => get_option( 'thumbnail_size_w' ), |
194
|
|
|
'height' => get_option( 'thumbnail_size_h' ) |
195
|
|
|
) ); |
196
|
|
|
$dimensions['crop'] = true; |
197
|
|
|
return $dimensions; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.