1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( !class_exists( 'FooGallery_Image_Viewer_Gallery_Template' ) ) { |
4
|
|
|
|
5
|
|
|
define('FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
6
|
|
|
|
7
|
|
|
class FooGallery_Image_Viewer_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-image-viewer', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
16
|
|
|
|
17
|
|
|
add_action( 'foogallery_located_template-image-viewer', 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
|
|
|
|
22
|
|
|
add_filter( 'foogallery_template_thumbnail_dimensions-image-viewer', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
27
|
|
|
* @param $extensions |
28
|
|
|
* |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
32
|
|
|
$extensions[] = __FILE__; |
33
|
|
|
return $extensions; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Add our gallery template to the list of templates available for every gallery |
38
|
|
|
* @param $gallery_templates |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
43
|
|
|
|
44
|
|
|
$gallery_templates[] = array( |
45
|
|
|
'slug' => 'image-viewer', |
46
|
|
|
'name' => __( 'Image Viewer', 'foogallery-image-viewer'), |
47
|
|
|
'lazyload_support' => true, |
48
|
|
|
'preview_css' => FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL . 'css/gallery-image-viewer.css', |
49
|
|
|
'admin_js' => FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL . 'js/admin-gallery-image-viewer.js', |
50
|
|
|
'fields' => array( |
51
|
|
|
array( |
52
|
|
|
'id' => 'alignment', |
53
|
|
|
'title' => __( 'Alignment', 'foogallery' ), |
54
|
|
|
'desc' => __( 'The horizontal alignment of the thumbnails inside the gallery.', 'foogallery' ), |
55
|
|
|
'default' => 'alignment-center', |
56
|
|
|
'type' => 'select', |
57
|
|
|
'choices' => array( |
58
|
|
|
'alignment-left' => __( 'Left', 'foogallery' ), |
59
|
|
|
'alignment-center' => __( 'Center', 'foogallery' ), |
60
|
|
|
'alignment-right' => __( 'Right', 'foogallery' ), |
61
|
|
|
) |
62
|
|
|
), |
63
|
|
|
array( |
64
|
|
|
'id' => 'lightbox', |
65
|
|
|
'title' => __('Lightbox', 'foogallery-image-viewer'), |
66
|
|
|
'desc' => __('Choose which lightbox you want to use in the gallery.', 'foogallery-image-viewer'), |
67
|
|
|
'type' => 'lightbox' |
68
|
|
|
), |
69
|
|
|
array( |
70
|
|
|
'id' => 'theme', |
71
|
|
|
'title' => __('Theme', 'foogallery'), |
72
|
|
|
'default' => '', |
73
|
|
|
'type' => 'radio', |
74
|
|
|
'spacer' => '<span class="spacer"></span>', |
75
|
|
|
'choices' => array( |
76
|
|
|
'' => __( 'Light', 'foogallery' ), |
77
|
|
|
'fiv-dark' => __( 'Dark', 'foogallery' ), |
78
|
|
|
'fiv-custom' => __( 'Custom', 'foogallery' ) |
79
|
|
|
) |
80
|
|
|
), |
81
|
|
|
array( |
82
|
|
|
'id' => 'theme_custom_bgcolor', |
83
|
|
|
'title' => __('Background Color', 'foogallery'), |
84
|
|
|
'section' => __( 'Custom Theme Colors', 'foogallery' ), |
85
|
|
|
'type' => 'colorpicker', |
86
|
|
|
'default' => '#FFFFFF', |
87
|
|
|
'opacity' => true |
88
|
|
|
), |
89
|
|
|
array( |
90
|
|
|
'id' => 'theme_custom_textcolor', |
91
|
|
|
'title' => __('Text Color', 'foogallery'), |
92
|
|
|
'section' => __( 'Custom Theme Colors', 'foogallery' ), |
93
|
|
|
'type' => 'colorpicker', |
94
|
|
|
'default' => '#1b1b1b', |
95
|
|
|
'opacity' => true |
96
|
|
|
), |
97
|
|
|
array( |
98
|
|
|
'id' => 'theme_custom_hovercolor', |
99
|
|
|
'title' => __('Hover BG Color', 'foogallery'), |
100
|
|
|
'section' => __( 'Custom Theme Colors', 'foogallery' ), |
101
|
|
|
'type' => 'colorpicker', |
102
|
|
|
'default' => '#F2F2F2', |
103
|
|
|
'opacity' => true |
104
|
|
|
), |
105
|
|
|
array( |
106
|
|
|
'id' => 'theme_custom_bordercolor', |
107
|
|
|
'title' => __('Border Color', 'foogallery'), |
108
|
|
|
'section' => __( 'Custom Theme Colors', 'foogallery' ), |
109
|
|
|
'type' => 'colorpicker', |
110
|
|
|
'default' => '#e6e6e6', |
111
|
|
|
'opacity' => true |
112
|
|
|
), |
113
|
|
|
array( |
114
|
|
|
'id' => 'thumbnail_size', |
115
|
|
|
'title' => __('Thumbnail Size', 'foogallery-image-viewer'), |
116
|
|
|
'section' => __( 'Thumbnail Settings', 'foogallery' ), |
117
|
|
|
'desc' => __('Choose the size of your thumbs.', 'foogallery-image-viewer'), |
118
|
|
|
'type' => 'thumb_size', |
119
|
|
|
'default' => array( |
120
|
|
|
'width' => 640, |
121
|
|
|
'height' => 360, |
122
|
|
|
'crop' => true |
123
|
|
|
) |
124
|
|
|
), |
125
|
|
|
array( |
126
|
|
|
'id' => 'thumbnail_link', |
127
|
|
|
'title' => __('Thumbnail Link', 'foogallery-image-viewer'), |
128
|
|
|
'section' => __( 'Thumbnail Settings', 'foogallery' ), |
129
|
|
|
'default' => 'image' , |
130
|
|
|
'type' => 'thumb_link', |
131
|
|
|
'spacer' => '<span class="spacer"></span>', |
132
|
|
|
'desc' => __('You can choose to either link each thumbnail to the full size image or to the image\'s attachment page.', 'foogallery-image-viewer') |
133
|
|
|
), |
134
|
|
|
array( |
135
|
|
|
'id' => 'text-prev', |
136
|
|
|
'title' => __( '"Prev" Text', 'foogallery' ), |
137
|
|
|
'section' => __( 'Language Settings', 'foogallery' ), |
138
|
|
|
'type' => 'text', |
139
|
|
|
'default' => __('Prev', 'foogallery') |
140
|
|
|
), |
141
|
|
|
array( |
142
|
|
|
'id' => 'text-of', |
143
|
|
|
'title' => __( '"of" Text', 'foogallery' ), |
144
|
|
|
'section' => __( 'Language Settings', 'foogallery' ), |
145
|
|
|
'type' => 'text', |
146
|
|
|
'default' => __('of', 'foogallery') |
147
|
|
|
), |
148
|
|
|
array( |
149
|
|
|
'id' => 'text-next', |
150
|
|
|
'title' => __( '"Next" Text', 'foogallery' ), |
151
|
|
|
'section' => __( 'Language Settings', 'foogallery' ), |
152
|
|
|
'type' => 'text', |
153
|
|
|
'default' => __('Next', 'foogallery') |
154
|
|
|
) |
155
|
|
|
) |
156
|
|
|
); |
157
|
|
|
|
158
|
|
|
return $gallery_templates; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Add thumbnail fields to the gallery template |
163
|
|
|
* |
164
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
165
|
|
|
* @param $fields |
166
|
|
|
* @param $template |
167
|
|
|
* |
168
|
|
|
* @return array |
169
|
|
|
*/ |
170
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
171
|
|
|
$fields = array_merge( $fields, foogallery_get_gallery_template_common_thumbnail_fields($template) ); |
172
|
|
|
|
173
|
|
|
return $fields; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Enqueue scripts that the default gallery template relies on |
178
|
|
|
*/ |
179
|
|
|
function enqueue_dependencies( $gallery ) { |
|
|
|
|
180
|
|
|
wp_enqueue_script( 'jquery' ); |
181
|
|
|
|
182
|
|
|
//enqueue core files |
183
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
184
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
185
|
|
|
|
186
|
|
|
$css = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'image-viewer/css/foogallery.image-viewer.min.css'; |
187
|
|
|
wp_enqueue_style( 'foogallery-image-viewer', $css, array(), FOOGALLERY_VERSION ); |
188
|
|
|
|
189
|
|
|
$js = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'image-viewer/js/foogallery.image-viewer.min.js'; |
190
|
|
|
wp_enqueue_script( 'foogallery-image-viewer', $js, array(), FOOGALLERY_VERSION ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
function render_thumbnail_preview( $field, $gallery, $template ) { |
|
|
|
|
194
|
|
|
if ( 'image_viewer_preview' == $field['type'] ) { |
195
|
|
|
$args = $gallery->get_meta( 'thumbnail_size', array( |
196
|
|
|
'width' => 640, |
197
|
|
|
'height' => 360, |
198
|
|
|
'crop' => true |
199
|
|
|
) ); |
200
|
|
|
//override the link so that it does not actually open an image |
201
|
|
|
$args['link'] = 'custom'; |
202
|
|
|
$args['custom_link'] = '#preview'; |
203
|
|
|
$args['link_attributes'] = array( |
204
|
|
|
'class' => 'fiv-active' |
205
|
|
|
); |
206
|
|
|
|
207
|
|
|
$hover_effect = $gallery->get_meta( 'image-viewer_hover-effect', 'hover-effect-zoom' ); |
208
|
|
|
$hover_effect_type = $gallery->get_meta( 'image-viewer_hover-effect-type', '' ); |
209
|
|
|
$text_prev = $gallery->get_meta( 'image-viewer_text-prev', __('Prev', 'foogallery') ); |
210
|
|
|
$text_of = $gallery->get_meta( 'image-viewer_text-of', __('of', 'foogallery') ); |
211
|
|
|
$text_next = $gallery->get_meta( 'image-viewer_text-next', __('Next', 'foogallery') ); |
212
|
|
|
|
213
|
|
|
$featured = $gallery->featured_attachment(); |
214
|
|
|
|
215
|
|
|
if ( false === $featured ) { |
216
|
|
|
$featured = new FooGalleryAttachment(); |
217
|
|
|
$featured->url = FOOGALLERY_URL . 'assets/test_thumb_1.jpg'; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
?><div class="foogallery-image-viewer-preview <?php echo foogallery_build_class_attribute( $gallery, $hover_effect, $hover_effect_type ); ?>"> |
221
|
|
|
<div class="fiv-inner"> |
222
|
|
|
<div class="fiv-inner-container"> |
223
|
|
|
<?php |
224
|
|
|
echo $featured->html( $args, true, false ); |
225
|
|
|
echo $featured->html_caption( 'both' ); |
226
|
|
|
echo '</a>'; |
227
|
|
|
?> |
228
|
|
|
</div> |
229
|
|
|
<div class="fiv-ctrls"> |
230
|
|
|
<div class="fiv-prev"><span><?php echo $text_prev; ?></span></div> |
231
|
|
|
<label class="fiv-count"><span class="fiv-count-current">1</span><?php echo $text_of; ?><span>1</span></label> |
232
|
|
|
<div class="fiv-next"><span><?php echo $text_next; ?></span></div> |
233
|
|
|
</div> |
234
|
|
|
</div> |
235
|
|
|
</div><?php |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template |
241
|
|
|
* |
242
|
|
|
* @param array $dimensions |
243
|
|
|
* @param FooGallery $foogallery |
244
|
|
|
* |
245
|
|
|
* @return mixed |
246
|
|
|
*/ |
247
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
|
|
|
|
248
|
|
|
$dimensions = $foogallery->get_meta( 'thumbnail_size', false ); |
249
|
|
|
return $dimensions; |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
} |
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.