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 extra fields to the templates |
15
|
|
|
add_filter( 'foogallery_override_gallery_template_fields-default', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
16
|
|
|
|
17
|
|
|
add_action( 'foogallery_located_template-default', array( $this, 'enqueue_dependencies' ) ); |
18
|
|
|
|
19
|
|
|
add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
20
|
|
|
add_action( 'foogallery_render_gallery_template_field_custom', array( $this, 'render_thumbnail_preview' ), 10, 3 ); |
21
|
|
|
add_filter( 'foogallery_template_load_js-default', array( $this, 'can_enqueue_template_js' ), 10, 2 ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
26
|
|
|
* @param $extensions |
27
|
|
|
* |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
31
|
|
|
$extensions[] = __FILE__; |
32
|
|
|
return $extensions; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Add our gallery template to the list of templates available for every gallery |
37
|
|
|
* @param $gallery_templates |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
42
|
|
|
$gallery_templates[] = array( |
43
|
|
|
'slug' => 'default', |
44
|
|
|
'name' => __( 'Responsive Image Gallery', 'foogallery' ), |
45
|
|
|
'lazyload_support' => true, |
46
|
|
|
'preview_css' => FOOGALLERY_DEFAULT_GALLERY_TEMPLATE_URL . 'css/gallery-default.css', |
47
|
|
|
'admin_js' => FOOGALLERY_DEFAULT_GALLERY_TEMPLATE_URL . 'js/admin-gallery-default.js', |
48
|
|
|
'fields' => array( |
49
|
|
|
array( |
50
|
|
|
'id' => 'lightbox', |
51
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
52
|
|
|
'desc' => __( 'Choose which lightbox you want to use. The lightbox will only work if you set the thumbnail link to "Full Size Image".', 'foogallery' ), |
53
|
|
|
'type' => 'lightbox', |
54
|
|
|
), |
55
|
|
|
array( |
56
|
|
|
'id' => 'spacing', |
57
|
|
|
'title' => __( 'Spacing', 'foogallery' ), |
58
|
|
|
'desc' => __( 'The spacing or gap between thumbnails in the gallery.', 'foogallery' ), |
59
|
|
|
'type' => 'select', |
60
|
|
|
'default' => 'spacing-width-10', |
61
|
|
|
'choices' => array( |
62
|
|
|
'spacing-width-0' => __( '0 pixels', 'foogallery' ), |
63
|
|
|
'spacing-width-5' => __( '5 pixels', 'foogallery' ), |
64
|
|
|
'spacing-width-10' => __( '10 pixels', 'foogallery' ), |
65
|
|
|
'spacing-width-15' => __( '15 pixels', 'foogallery' ), |
66
|
|
|
'spacing-width-20' => __( '20 pixels', 'foogallery' ), |
67
|
|
|
'spacing-width-25' => __( '25 pixels', 'foogallery' ), |
68
|
|
|
), |
69
|
|
|
), |
70
|
|
|
array( |
71
|
|
|
'id' => 'alignment', |
72
|
|
|
'title' => __( 'Alignment', 'foogallery' ), |
73
|
|
|
'desc' => __( 'The horizontal alignment of the thumbnails inside the gallery.', 'foogallery' ), |
74
|
|
|
'default' => 'alignment-center', |
75
|
|
|
'type' => 'select', |
76
|
|
|
'choices' => array( |
77
|
|
|
'alignment-left' => __( 'Left', 'foogallery' ), |
78
|
|
|
'alignment-center' => __( 'Center', 'foogallery' ), |
79
|
|
|
'alignment-right' => __( 'Right', 'foogallery' ), |
80
|
|
|
) |
81
|
|
|
), |
82
|
|
|
array( |
83
|
|
|
'id' => 'loading_animation', |
84
|
|
|
'title' => __( 'Loading Indicator', 'foogallery' ), |
85
|
|
|
'default' => 'yes', |
86
|
|
|
'type' => 'radio', |
87
|
|
|
'choices' => array( |
88
|
|
|
'yes' => __( 'Show Thumbnail Loading Indicator', 'foogallery' ), |
89
|
|
|
'no' => __( 'Disabled', 'foogallery' ) |
90
|
|
|
), |
91
|
|
|
'spacer' => '<span class="spacer"></span>', |
92
|
|
|
'desc' => __( 'By default, an animated loading animation indicator is shown before the thumbnails have loaded. You can disable the loader if you want.', 'foogallery' ), |
93
|
|
|
), |
94
|
|
|
array( |
95
|
|
|
'id' => 'thumbnail_dimensions', |
96
|
|
|
'title' => __( 'Size', 'foogallery' ), |
97
|
|
|
'desc' => __( 'Choose the size of your thumbnails.', 'foogallery' ), |
98
|
|
|
'section' => __( 'Thumbnail Settings', 'foogallery' ), |
99
|
|
|
'type' => 'thumb_size', |
100
|
|
|
'default' => array( |
101
|
|
|
'width' => get_option( 'thumbnail_size_w' ), |
102
|
|
|
'height' => get_option( 'thumbnail_size_h' ), |
103
|
|
|
'crop' => true, |
104
|
|
|
), |
105
|
|
|
), |
106
|
|
|
array( |
107
|
|
|
'id' => 'thumbnail_link', |
108
|
|
|
'title' => __( 'Link', 'foogallery' ), |
109
|
|
|
'section' => __( 'Thumbnail Settings', 'foogallery' ), |
110
|
|
|
'default' => 'image', |
111
|
|
|
'type' => 'thumb_link', |
112
|
|
|
'spacer' => '<span class="spacer"></span>', |
113
|
|
|
'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' ), |
114
|
|
|
) |
115
|
|
|
// array( |
|
|
|
|
116
|
|
|
// 'id' => 'thumb_preview', |
117
|
|
|
// 'title' => __( 'Preview', 'foogallery' ), |
118
|
|
|
// 'desc' => __( 'This is what your gallery thumbnails will look like.', 'foogallery' ), |
119
|
|
|
// 'section' => __( 'Thumbnail Settings', 'foogallery' ), |
120
|
|
|
// 'type' => 'default_thumb_preview', |
121
|
|
|
// ) |
122
|
|
|
) |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
return $gallery_templates; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Add thumbnail fields to the gallery template |
130
|
|
|
* |
131
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
132
|
|
|
* @param $fields |
133
|
|
|
* @param $template |
134
|
|
|
* |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
138
|
|
|
$fields = array_merge( $fields, foogallery_get_gallery_template_common_thumbnail_fields($template) ); |
139
|
|
|
|
140
|
|
|
return $fields; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Renders the thumbnail preview field |
145
|
|
|
* |
146
|
|
|
* @param $field array |
147
|
|
|
* @param $gallery FooGallery |
148
|
|
|
* @param $template array |
149
|
|
|
*/ |
150
|
|
|
function render_thumbnail_preview( $field, $gallery, $template ) { |
|
|
|
|
151
|
|
|
if ( 'default_thumb_preview' == $field['type'] ) { |
152
|
|
|
$args = $gallery->get_meta( 'default_thumbnail_dimensions', array( |
153
|
|
|
'width' => get_option( 'thumbnail_size_w' ), |
154
|
|
|
'height' => get_option( 'thumbnail_size_h' ), |
155
|
|
|
'crop' => true |
156
|
|
|
) ); |
157
|
|
|
|
158
|
|
|
//override the link so that it does not actually open an image |
159
|
|
|
$args['link'] = 'custom'; |
160
|
|
|
$args['custom_link'] = '#preview'; |
161
|
|
|
|
162
|
|
|
$hover_effect = $gallery->get_meta( 'default_hover-effect', 'hover-effect-zoom' ); |
163
|
|
|
$border_style = $gallery->get_meta( 'default_border-style', 'border-style-square-white' ); |
164
|
|
|
$hover_effect_type = $gallery->get_meta( 'default_hover-effect-type', '' ); |
165
|
|
|
$caption_hover_effect = $gallery->get_meta( 'default_caption-hover-effect', 'hover-caption-simple' ); |
166
|
|
|
|
167
|
|
|
$featured = $gallery->featured_attachment(); |
168
|
|
|
|
169
|
|
|
if ( false === $featured ) { |
170
|
|
|
$featured = new FooGalleryAttachment(); |
171
|
|
|
$featured->url = foogallery_test_thumb_url(); |
172
|
|
|
$featured->caption = __( 'Caption Title', 'foogallery' ); |
173
|
|
|
$featured->description = __( 'Long Caption Description Text', 'foogallery' ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
echo '<div class="foogallery-default-preview ' . foogallery_build_class_attribute_safe( $gallery, $hover_effect, $border_style, $hover_effect_type, $caption_hover_effect, 'foogallery-thumbnail-preview' ) . '">'; |
177
|
|
|
echo $featured->html( $args, true, false ); |
178
|
|
|
echo $featured->html_caption( 'both' ); |
179
|
|
|
echo '</a>'; |
180
|
|
|
echo '</div>'; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Enqueue scripts that the default gallery template relies on |
186
|
|
|
*/ |
187
|
|
|
function enqueue_dependencies( $gallery ) { |
|
|
|
|
188
|
|
|
wp_enqueue_script( 'jquery' ); |
189
|
|
|
|
190
|
|
|
//how do we handle loading animations |
|
|
|
|
191
|
|
|
// if ( 'yes' === $gallery->get_meta( 'default_loading_animation', 'yes' ) ) { |
192
|
|
|
// foogallery_enqueue_imagesloaded_script(); |
193
|
|
|
// } |
194
|
|
|
|
195
|
|
|
//enqueue core files |
196
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
197
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
198
|
|
|
|
199
|
|
|
$css = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'default/css/foogallery.responsive.min.css'; |
200
|
|
|
wp_enqueue_style( 'foogallery-default', $css, array(), FOOGALLERY_VERSION ); |
201
|
|
|
|
202
|
|
|
$js = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'default/js/foogallery.responsive.min.js'; |
203
|
|
|
wp_enqueue_script( 'foogallery-default', $js, array(), FOOGALLERY_VERSION ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param $include bool By default we will try to include the template JS |
208
|
|
|
* @param $gallery FooGallery the gallery instance we are loading |
209
|
|
|
* |
210
|
|
|
* @return bool if we want to try to include the template JS |
211
|
|
|
*/ |
212
|
|
|
function can_enqueue_template_js( $include, $gallery ) { |
|
|
|
|
213
|
|
|
if ( 'yes' === $gallery->get_meta( 'default_loading_animation', 'yes' ) ) { |
214
|
|
|
return true; |
215
|
|
|
} |
216
|
|
|
return false; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
} |
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.