PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.2.6
Gallery : FooGallery v3.2.6
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / extensions / default-templates / thumbnail / class-thumbnail-gallery-template.php
foogallery / extensions / default-templates / thumbnail Last commit date
js 1 month ago class-thumbnail-gallery-template.php 1 month ago gallery-thumbnail.php 1 month ago
class-thumbnail-gallery-template.php
334 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if ( !class_exists( 'FooGallery_Thumbnail_Gallery_Template' ) ) {
8
9 define('FOOGALLERY_THUMBNAIL_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
10
11 class FooGallery_Thumbnail_Gallery_Template {
12
13 const template_id = 'thumbnail';
14
15 /**
16 * Wire up everything we need to run the extension
17 */
18 function __construct() {
19 add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) );
20 add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
21
22 //build up the thumb dimensions from some arguments
23 add_filter( 'foogallery_calculate_thumbnail_dimensions-thumbnail', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
24
25 //build up the thumb dimensions on save
26 add_filter( 'foogallery_template_thumbnail_dimensions-thumbnail', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
27
28 //add additional link attributes to each item
29 add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'alter_link_attributes'), 10, 3 );
30
31 //build up the arguments needed for rendering this template
32 add_filter( 'foogallery_gallery_template_arguments-thumbnail', array( $this, 'build_gallery_template_arguments' ) );
33
34 // Add specific caption fields
35 add_filter( 'foogallery_override_gallery_template_fields-thumbnail', array( $this, 'add_caption_fields' ), 999, 2 );
36
37 // Adjust the default settings for this layout
38 add_filter( 'foogallery_override_gallery_template_fields_defaults-thumbnail', array( $this, 'field_defaults' ), 10, 1 );
39 }
40
41 /**
42 * Build up the arguments needed for rendering this gallery template
43 *
44 * @param $args
45 *
46 * @return array
47 */
48 function build_gallery_template_arguments( $args ) {
49 $args = foogallery_gallery_template_setting( 'thumbnail_dimensions', array() );
50 $args['crop'] = '1'; //we now force thumbs to be cropped
51
52 if ( foogallery_gallery_template_setting( 'link_custom_url', '' ) === 'on' ) {
53 $args['link'] = 'custom';
54 }
55
56 return $args;
57 }
58
59 /**
60 * Add a rel attribute to all image links to make the lightboxes work
61 *
62 * @param $attr
63 * @param $args
64 * @param $foogallery_attachment FooGalleryAttachment
65 *
66 * @return mixed
67 */
68 function alter_link_attributes($attr, $args, $foogallery_attachment) {
69 global $current_foogallery;
70 if ( isset( $current_foogallery ) && self::template_id === $current_foogallery->gallery_template ) {
71
72 //always set the rel so that lightboxes will group the images
73 $attr['rel'] = 'lightbox[' . $current_foogallery->ID . ']';
74
75 //check if we must hide the featured image within the lightbox
76 if ( isset( $foogallery_attachment->featured ) && foogallery_gallery_template_setting( 'exclude_featured_image', '' ) === 'on' ) {
77 $attr['class'] = 'fg-panel-hide';
78 }
79 }
80
81 return $attr;
82 }
83
84 /**
85 * Register myself so that all associated JS and CSS files can be found and automatically included
86 * @param $extensions
87 *
88 * @return array
89 */
90 function register_myself( $extensions ) {
91 $extensions[] = __FILE__;
92 return $extensions;
93 }
94
95 /**
96 * Add our gallery template to the list of templates available for every gallery
97 * @param $gallery_templates
98 *
99 * @return array
100 */
101 function add_template( $gallery_templates ) {
102 $gallery_templates[self::template_id] = array(
103 'slug' => self::template_id,
104 'name' => __( 'Single Thumbnail', 'foogallery' ),
105 'preview_support' => true,
106 'common_fields_support' => true,
107 'lazyload_support' => true,
108 'mandatory_classes' => 'fg-thumbnail',
109 'thumbnail_dimensions' => true,
110 'paging_support' => false,
111 'enqueue_core' => true,
112 'icon' => '<svg viewBox="0 0 24 24">
113 <rect x="3" y="5" width="18" height="14"/>
114 <polyline points="6,15 10,12 14,16 18,12"/>
115 <circle cx="9" cy="9" r="1.5"/>
116 </svg>',
117 'fields' => array(
118 array(
119 'id' => 'help',
120 'type' => 'html',
121 'section' => __( 'General', 'foogallery' ),
122 'help' => true,
123 'title' => __( 'Single Thumbnail Layout', 'foogallery' ),
124 'desc' => __( 'This gallery layout 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' ),
125 ),
126 array(
127 'id' => 'thumbnail_dimensions',
128 'title' => __( 'Size', 'foogallery' ),
129 'desc' => __( 'Choose the size of your thumbnail.', 'foogallery' ),
130 'section' => __( 'General', 'foogallery' ),
131 'alias' => 'thumbnail_size',
132 'type' => 'thumb_size_no_crop',
133 'for' => 'thumbnail_dimensions_width',
134 'default' => array(
135 'width' => 350,
136 'height' => 250
137 ),
138 'row_data'=> array(
139 'data-foogallery-change-selector' => 'input',
140 'data-foogallery-preview' => 'shortcode'
141 )
142 ),
143 array(
144 'id' => 'position',
145 'title' => __( 'Position', 'foogallery' ),
146 'desc' => __( 'The position of the thumbnail related to the content around it.', 'foogallery' ),
147 'section' => __( 'General', 'foogallery' ),
148 'default' => 'fg-center',
149 'type' => 'select',
150 'choices' => array(
151 'fg-center' => __( 'Full Center', 'foogallery' ),
152 'fg-left' => __( 'Full Left', 'foogallery' ),
153 'fg-right' => __( 'Full Right', 'foogallery' ),
154 'fg-float-left' => __( 'Float Left', 'foogallery' ),
155 'fg-float-right' => __( 'Float Right', 'foogallery' ),
156 ),
157 'row_data'=> array(
158 'data-foogallery-change-selector' => 'select',
159 'data-foogallery-preview' => 'shortcode'
160 )
161 ),
162 array(
163 'id' => 'show_as_stack',
164 'title' => __( 'Stacked Effect', 'foogallery' ),
165 'section' => __( 'General', 'foogallery' ),
166 'default' => 'fg-stacked',
167 'type' => 'radio',
168 'desc' => __( 'Show the thumbnails as a stack or pile of images.', 'foogallery' ),
169 'choices' => array(
170 '' => __( 'None', 'foogallery' ),
171 'fg-stacked' => __( 'Stacked', 'foogallery' )
172 ),
173 'row_data'=> array(
174 'data-foogallery-change-selector' => 'input',
175 'data-foogallery-preview' => 'shortcode',
176 'data-foogallery-value-selector' => 'input:checked',
177 )
178 ),
179 array(
180 'id' => 'link_custom_url',
181 'title' => __( 'Link To Custom URL', 'foogallery' ),
182 'section' => __( 'General', 'foogallery' ),
183 'default' => '',
184 'type' => 'checkbox',
185 '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' ),
186 'row_data'=> array(
187 'data-foogallery-change-selector' => 'input',
188 'data-foogallery-preview' => 'shortcode',
189 'data-foogallery-value-selector' => 'input:checked',
190 )
191 ),
192 array(
193 'id' => 'lightbox',
194 'type' => 'lightbox',
195 ),
196 array(
197 'id' => 'exclude_featured_image',
198 'title' => __( 'Exclude Featured Image', 'foogallery' ),
199 'section' => __( 'General', 'foogallery' ),
200 'default' => '',
201 'type' => 'checkbox',
202 'desc' => __( 'You can exclude the featured image from the images shown in the lightbox.', 'foogallery' ),
203 'row_data'=> array(
204 'data-foogallery-hidden' => true,
205 'data-foogallery-show-when-field' => 'lightbox',
206 'data-foogallery-show-when-field-operator' => '===',
207 'data-foogallery-show-when-field-value' => 'foogallery',
208 'data-foogallery-change-selector' => 'input',
209 'data-foogallery-preview' => 'shortcode',
210 'data-foogallery-value-selector' => 'input:checked',
211 )
212 )
213 )
214 );
215
216 return $gallery_templates;
217 }
218
219 /**
220 * Add caption fields to the gallery template if supported
221 *
222 * @param $fields
223 * @param $template
224 *
225 * @return array
226 */
227 function add_caption_fields( $fields, $template ) {
228
229 $new_fields[] = array(
230 'id' => 'caption_override_help',
231 'title' => __( 'Caption Override Help', 'foogallery' ),
232 'desc' => __( 'You can include dynamic placeholders in the override title and description, eg. <code>{{gallery-count}}</code> and <code>{{gallery-title}}</code>.', 'foogallery' ),
233 'section' => __( 'Captions', 'foogallery' ),
234 'type' => 'help'
235 );
236
237 $new_fields[] = array(
238 'id' => 'caption_title',
239 'title' => __('Override Title', 'foogallery'),
240 'section' => __( 'Captions', 'foogallery' ),
241 'desc' => __('Leave blank if you do not want a caption title.', 'foogallery'),
242 'type' => 'text',
243 'row_data'=> array(
244 'data-foogallery-change-selector' => 'input',
245 'data-foogallery-preview' => 'shortcode'
246 )
247 );
248 $new_fields[] = array(
249 'id' => 'caption_description',
250 'title' => __('Override Description', 'foogallery'),
251 'section' => __( 'Captions', 'foogallery' ),
252 'desc' => __('Leave blank if you do not want a caption description.', 'foogallery'),
253 'type' => 'textarea',
254 'row_data'=> array(
255 'data-foogallery-change-selector' => 'textarea',
256 'data-foogallery-preview' => 'shortcode'
257 )
258 );
259
260 $field_index = foogallery_admin_fields_find_index_of_field( $fields, 'caption_alignment' );
261
262 array_splice( $fields, $field_index + 1, 0, $new_fields );
263
264 return $fields;
265 }
266
267 /**
268 * Builds thumb dimensions from arguments
269 *
270 * @param array $dimensions
271 * @param array $arguments
272 *
273 * @return mixed
274 */
275 function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) {
276 if ( array_key_exists( 'thumbnail_dimensions', $arguments) ) {
277 return array(
278 'height' => intval($arguments['thumbnail_dimensions']['height']),
279 'width' => intval($arguments['thumbnail_dimensions']['width']),
280 'crop' => true
281 );
282 }
283 return null;
284 }
285
286 /**
287 * Get the thumb dimensions arguments saved for the gallery for this gallery template
288 *
289 * @param array $dimensions
290 * @param FooGallery $foogallery
291 *
292 * @return mixed
293 */
294 function get_thumbnail_dimensions( $dimensions, $foogallery ) {
295 $dimensions = $foogallery->get_meta( 'thumbnail_thumbnail_dimensions', array(
296 'width' => get_option( 'thumbnail_size_w' ),
297 'height' => get_option( 'thumbnail_size_h' ),
298 'crop' => true
299 ) );
300 if ( !array_key_exists( 'crop', $dimensions ) ) {
301 $dimensions['crop'] = true;
302 }
303 return $dimensions;
304 }
305
306 /**
307 * Return an array of field defaults for the template
308 *
309 * @param $field_defaults
310 *
311 * @return string[]
312 */
313 function field_defaults( $field_defaults ) {
314 return array_merge( $field_defaults, array(
315 'theme' => 'fg-light',
316 'hover_effect_caption_visibility' => 'fg-caption-always',
317 'caption_visibility_no_hover_effect' => 'fg-caption-always',
318 'border_size' => 'fg-border-medium',
319 'drop_shadow' => 'fg-shadow-small',
320 'rounded_corners' => 'fg-round-small',
321 'inner_shadow' => 'fg-shadow-inset-medium',
322 'hover_effect_type' => 'normal',
323 'hover_effect_scale' => 'fg-hover-semi-zoomed',
324 'hover_effect_icon' => 'fg-hover-zoom4',
325 'caption_title' => '{{gallery-title}}',
326 'caption_description' => '{{gallery-count}} Images',
327 'caption_alignment' => 'fg-c-c',
328 'show_as_stack' => 'fg-stacked',
329 'loaded_effect' => ''
330 ) );
331 }
332 }
333 }
334