1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( !class_exists( 'FooGallery_Thumbnail_Gallery_Template' ) ) { |
4
|
|
|
|
5
|
|
|
define('FOOGALLERY_THUMBNAIL_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
6
|
|
|
|
7
|
|
|
class FooGallery_Thumbnail_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
|
|
|
add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
14
|
|
|
|
15
|
|
|
add_filter( 'foogallery_located_template-thumbnail', array( $this, 'enqueue_dependencies' ) ); |
16
|
|
|
|
17
|
|
|
//add extra fields to the templates |
18
|
|
|
add_filter( 'foogallery_override_gallery_template_fields-thumbnail', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
19
|
|
|
|
20
|
|
|
//build up any preview arguments |
21
|
|
|
add_filter( 'foogallery_preview_arguments-thumbnail', array( $this, 'preview_arguments' ), 10, 2 ); |
22
|
|
|
|
23
|
|
|
//build up the thumb dimensions from some arguments |
24
|
|
|
add_filter( 'foogallery_calculate_thumbnail_dimensions-thumbnail', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
29
|
|
|
* @param $extensions |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
34
|
|
|
$extensions[] = __FILE__; |
35
|
|
|
return $extensions; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Add our gallery template to the list of templates available for every gallery |
40
|
|
|
* @param $gallery_templates |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
45
|
|
|
$gallery_templates[] = array( |
46
|
|
|
'slug' => 'thumbnail', |
47
|
|
|
'name' => __( 'Single Thumbnail Gallery', 'foogallery' ), |
48
|
|
|
'lazyload_support' => true, |
49
|
|
|
'fields' => array( |
50
|
|
|
array( |
51
|
|
|
'id' => 'help', |
52
|
|
|
'type' => 'html', |
53
|
|
|
'section' => __( 'General', 'foogallery' ), |
54
|
|
|
'help' => true, |
55
|
|
|
'desc' => __( 'This gallery template only shows a single thumbnail, but the true power shines through when the thumbnail is clicked, because then the lightbox takes over and the user can view all the images in the gallery.', 'foogallery' ), |
56
|
|
|
), |
57
|
|
|
array( |
58
|
|
|
'id' => 'thumbnail_dimensions', |
59
|
|
|
'title' => __( 'Size', 'foogallery' ), |
60
|
|
|
'desc' => __( 'Choose the size of your thumbnail.', 'foogallery' ), |
61
|
|
|
'section' => __( 'General', 'foogallery' ), |
62
|
|
|
'type' => 'thumb_size', |
63
|
|
|
'default' => array( |
64
|
|
|
'width' => 250, |
65
|
|
|
'height' => 200, |
66
|
|
|
'crop' => true, |
67
|
|
|
), |
68
|
|
|
'row_data'=> array( |
69
|
|
|
'data-foogallery-preview' => 'shortcode' |
70
|
|
|
) |
71
|
|
|
), |
72
|
|
|
array( |
73
|
|
|
'id' => 'position', |
74
|
|
|
'title' => __( 'Position', 'foogallery' ), |
75
|
|
|
'desc' => __( 'The position of the thumbnail related to the content around it.', 'foogallery' ), |
76
|
|
|
'section' => __( 'General', 'foogallery' ), |
77
|
|
|
'default' => 'position-block', |
78
|
|
|
'type' => 'select', |
79
|
|
|
'choices' => array( |
80
|
|
|
'fg-center' => __( 'Full Width (block)', 'foogallery' ), |
81
|
|
|
'fg-left' => __( 'Float Left', 'foogallery' ), |
82
|
|
|
'fg-right' => __( 'Float Right', 'foogallery' ), |
83
|
|
|
), |
84
|
|
|
'row_data'=> array( |
85
|
|
|
'data-foogallery-change-selector' => 'select', |
86
|
|
|
'data-foogallery-preview' => 'class' |
87
|
|
|
) |
88
|
|
|
), |
89
|
|
|
array( |
90
|
|
|
'id' => 'link_custom_url', |
91
|
|
|
'title' => __( 'Link To Custom URL', 'foogallery' ), |
92
|
|
|
'section' => __( 'General', 'foogallery' ), |
93
|
|
|
'default' => '', |
94
|
|
|
'type' => 'checkbox', |
95
|
|
|
'desc' => __( 'You can link your thumbnails to Custom URL\'s (if they are set on your attachments). Fallback will be to the full size image.', 'foogallery' ) |
96
|
|
|
), |
97
|
|
|
array( |
98
|
|
|
'id' => 'lightbox', |
99
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
100
|
|
|
'section' => __( 'General', 'foogallery' ), |
101
|
|
|
'desc' => __( 'Choose which lightbox you want to use.', 'foogallery' ), |
102
|
|
|
'type' => 'lightbox', |
103
|
|
|
), |
104
|
|
|
array( |
105
|
|
|
'id' => 'caption_style', |
106
|
|
|
'title' => __( 'Caption Style', 'foogallery' ), |
107
|
|
|
'section' => __( 'Captions', 'foogallery' ), |
108
|
|
|
'desc' => __( 'Choose which caption style you want to use.', 'foogallery' ), |
109
|
|
|
'type' => 'select', |
110
|
|
|
'default' => 'simple', |
111
|
|
|
'choices' => array( |
112
|
|
|
'caption-simple' => __( 'Simple' , 'foogallery' ), |
113
|
|
|
'caption-slideup' => __( 'Slide Up' , 'foogallery' ), |
114
|
|
|
'caption-fall' => __( 'Fall Down' , 'foogallery' ), |
115
|
|
|
'caption-fade' => __( 'Fade' , 'foogallery' ), |
116
|
|
|
'caption-push' => __( 'Push From Left' , 'foogallery' ), |
117
|
|
|
'caption-scale' => __( 'Scale' , 'foogallery' ), |
118
|
|
|
'caption-none' => __( 'None' , 'foogallery' ) |
119
|
|
|
), |
120
|
|
|
), |
121
|
|
|
array( |
122
|
|
|
'id' => 'caption_title', |
123
|
|
|
'title' => __('Caption Title', 'foogallery'), |
124
|
|
|
'section' => __( 'General', 'foogallery' ), |
125
|
|
|
'desc' => __('Leave blank if you do not want a caption title.', 'foogallery'), |
126
|
|
|
'type' => 'text' |
127
|
|
|
), |
128
|
|
|
array( |
129
|
|
|
'id' => 'caption_description', |
130
|
|
|
'title' => __('Caption Description', 'foogallery'), |
131
|
|
|
'section' => __( 'General', 'foogallery' ), |
132
|
|
|
'desc' => __('Leave blank if you do not want a caption description.', 'foogallery'), |
133
|
|
|
'type' => 'textarea' |
134
|
|
|
) |
135
|
|
|
) |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
return $gallery_templates; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Enqueue scripts that the masonry gallery template relies on |
143
|
|
|
*/ |
144
|
|
|
function enqueue_dependencies() { |
|
|
|
|
145
|
|
|
//enqueue core files |
146
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
147
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Add thumbnail fields to the gallery template |
152
|
|
|
* |
153
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
154
|
|
|
* @param $fields |
155
|
|
|
* @param $template |
156
|
|
|
* |
157
|
|
|
* @return array |
158
|
|
|
*/ |
159
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
160
|
|
|
return apply_filters( 'foogallery_gallery_template_common_thumbnail_fields', $fields ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Build up a arguments used in the preview of the gallery |
165
|
|
|
* @param $args |
166
|
|
|
* @param $post_data |
167
|
|
|
* |
168
|
|
|
* @return mixed |
169
|
|
|
*/ |
170
|
|
|
function preview_arguments( $args, $post_data ) { |
|
|
|
|
171
|
|
|
$args['thumbnail_width'] = $post_data['foogallery_settings']['thumbnail_thumbnail_dimensions']['width']; |
172
|
|
|
$args['thumbnail_height'] = $post_data['foogallery_settings']['thumbnail_thumbnail_dimensions']['height']; |
173
|
|
|
$args['thumbnail_crop'] = isset( $post_data['foogallery_settings']['thumbnail_thumbnail_dimensions']['crop'] ) ? '1' : '0'; |
174
|
|
|
|
175
|
|
|
return $args; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Builds thumb dimensions from arguments |
180
|
|
|
* |
181
|
|
|
* @param array $dimensions |
182
|
|
|
* @param array $arguments |
183
|
|
|
* |
184
|
|
|
* @return mixed |
185
|
|
|
*/ |
186
|
|
|
function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) { |
|
|
|
|
187
|
|
|
return array( |
188
|
|
|
'height' => intval( $arguments['thumbnail_height'] ), |
189
|
|
|
'width' => intval( $arguments['thumbnail_width'] ), |
190
|
|
|
'crop' => $arguments['thumbnail_crop'] === '1' |
191
|
|
|
); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
} |
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.