/var/www/hkosl.com/aga/wp-content/plugins/foogallery/includes/render-functions.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<?php
/**
 *
 * FooGallery helper functions for rendering HTML
 * Created by Brad Vincent
 * Date: 11/07/2017
 *
 * @since 1.4.0
 */

/**
 * Returns the attachment image source only
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.0
 *
 * @return string
 */
function foogallery_attachment_html_image_src$foogallery_attachment$args = array() ) {
    return 
apply_filters'foogallery_attachment_resize_thumbnail'$foogallery_attachment->url$args$foogallery_attachment );
}

/**
 * Returns the attachment img HTML
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.0
 *
 * @return string
 */
function foogallery_attachment_html_image$foogallery_attachment$args = array() ) {
    
$attr foogallery_build_attachment_html_image_attributes$foogallery_attachment$args );

    
$html '<img';
    foreach ( 
$attr as $name => $value ) {
        
$name str_replace(' '''$name); //ensure we have no spaces!
        
$html .= $name=" '"' foogallery_esc_attr($value) . '"';
    }
    
$html .= ' />';

    return 
apply_filters'foogallery_attachment_html_image'$html$args$foogallery_attachment );
}

/**
 * Returns the attachment img HTML
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.9
 *
 * @return array
 */
function foogallery_build_attachment_html_image_attributes$foogallery_attachment$args = array() ) {
    
$attr['src'] = foogallery_attachment_html_image_src$foogallery_attachment$args );

    if ( ! empty( 
$foogallery_attachment->alt ) ) {
        
$attr['alt'] = $foogallery_attachment->alt;
    }

    if ( ! empty( 
$foogallery_attachment->caption ) ) {
        
$attr['title'] = $foogallery_attachment->caption;
    }

    
//pull any custom attributes out the args
    
if ( isset( $args['image_attributes'] ) && is_array$args['image_attributes'] ) ) {
        
$attr array_merge$attr$args['image_attributes'] );
    }

    
//check for width and height args and add those to the image
    
if ( isset( $args['width'] ) && intval$args['width'] ) > ) {
        
$attr['width'] = $args['width'];
    }
    if ( isset( 
$args['height'] ) && intval$args['height'] ) > ) {
        
$attr['height'] = $args['height'];
    }

    
$attr apply_filters'foogallery_attachment_html_image_attributes'$attr$args$foogallery_attachment );

    if ( 
array_key_exists'class'$attr ) ) {
        
$attr['class'] .= ' fg-image';
    } else {
        
$attr['class'] = 'fg-image';
    }

    return 
$attr;
}

/**
 * Returns the attachment anchor HTML opening tag
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.0
 *
 * @return string
 */
function foogallery_attachment_html_anchor_opening$foogallery_attachment$args = array() ) {
    
$attr foogallery_build_attachment_html_anchor_attributes$foogallery_attachment$args );

    
$html '<a';
    foreach ( 
$attr as $name => $value ) {
        
$name str_replace(' '''$name); //ensure we have no spaces!
        
$html .= $name=" '"' foogallery_esc_attr($value) . '"';
    }
    
$html .= '>';

    return 
apply_filters'foogallery_attachment_html_anchor_opening'$html$args$foogallery_attachment );
}

/**
 * Returns the array of attributes that will be used on the anchor for a FooGalleryAttachment
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.9
 *
 * @return array
 */
function foogallery_build_attachment_html_anchor_attributes$foogallery_attachment$args = array() ) {
    
$arg_defaults = array(
        
'link' => 'image',
        
'custom_link' => $foogallery_attachment->custom_url
    
);

    
$args wp_parse_args$args$arg_defaults );

    
$link $args['link'];

    if ( 
'page' === $link ) {
        
//get the URL to the attachment page
        
$url get_attachment_link$foogallery_attachment->ID );
    } else if ( 
'custom' === $link ) {
        
$url $args['custom_link'];
    } else {
        
$url $foogallery_attachment->url;
    }

    
//fallback for images that might not have a custom url
    
if ( empty( $url ) ) {
        
$url $foogallery_attachment->url;
    }

    
$attr = array();

    
//only add href and target attributes to the anchor if the link is NOT set to 'none'
    
if ( $link !== 'none' ){
        
$attr['href'] = $url;
        if ( ! empty( 
$foogallery_attachment->custom_target ) && 'default' !== $foogallery_attachment->custom_target ) {
            
$attr['target'] = $foogallery_attachment->custom_target;
        }
    }

    if ( ! empty( 
$foogallery_attachment->caption ) ) {
        
$attr['data-caption-title'] = $foogallery_attachment->caption;
    }

    if ( !empty( 
$foogallery_attachment->description ) ) {
        
$attr['data-caption-desc'] = $foogallery_attachment->description;
    }

    
$attr['data-attachment-id'] = $foogallery_attachment->ID;

    
//pull any custom attributes out the args
    
if ( isset( $args['link_attributes'] ) && is_array$args['link_attributes'] ) ) {
        
$attr array_merge$attr$args['link_attributes'] );
    }

    
$attr apply_filters'foogallery_attachment_html_link_attributes'$attr$args$foogallery_attachment );

    
//always add the fg-thumb class
    
if ( array_key_exists'class'$attr ) && !empty( $attr['class'] ) ) {
        
$attr['class'] .= ' fg-thumb';
    } else {
        
$attr['class'] = 'fg-thumb';
    }

    return 
$attr;
}

/**
 * Returns the attachment anchor HTML
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 * @param bool $output_image
 * @param bool $output_closing_tag
 *
 * @since 1.4.0
 *
 * @return string
 */
function foogallery_attachment_html_anchor$foogallery_attachment$args = array(), $output_image true$output_closing_tag true ) {
    if ( empty ( 
$foogallery_attachment->url ) )  {
        return 
'';
    }

    
$html foogallery_attachment_html_anchor_opening$foogallery_attachment$args );

    if ( 
$output_image ) {
        
$html .= foogallery_attachment_html_image$foogallery_attachment$args );;
    }

    if ( 
$output_closing_tag ) {
        
$html .= '</a>';
    }

    return 
apply_filters'foogallery_attachment_html_anchor'$html$args$foogallery_attachment );
}

/**
 * Builds up the captions for an attachment
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.9
 *
 * @return array|bool
 */
function foogallery_build_attachment_html_caption$foogallery_attachment$args = array() ) {
    
$captions = array();

    
$preset foogallery_gallery_template_setting'caption_preset''fg-custom' );

    if ( 
'none' !== $preset ) {
        
$caption_html = array();

        
$show_caption_title false;
        
$show_caption_desc false;

        
//check if we have provided overrides for the caption title
        
if ( isset( $args['override_caption_title'] ) ) {
            
$caption_title $args['override_caption_title'];
            
$show_caption_title true;
        } else {
            
$caption_title_source foogallery_gallery_template_setting'caption_title_source''' );

            
//if we need to use the settings, then make sure our source is false
            
if ( empty( $caption_title_source ) ) { $caption_title_source false; }

            if ( 
'fg-custom' === $preset ) {
                
$show_caption_title $caption_title_source !== 'none';
            } else {
                
//always show both title and desc for the presets
                
$show_caption_title true;
            }

            
//get the correct captions
            
$caption_title foogallery_get_caption_title_for_attachment$foogallery_attachment->_post$caption_title_source );
        }

        
//check if we have provided overrides for the caption description
        
if ( isset( $args['override_caption_desc'] ) ) {
            
$caption_desc $args['override_caption_desc'];
            
$show_caption_desc true;
        } else {

            
$caption_desc_source foogallery_gallery_template_setting'caption_desc_source''' );

            
//if we need to use the settings, then make sure our source is false
            
if ( empty( $caption_desc_source ) ) { $caption_desc_source false; }

            if ( 
'fg-custom' === $preset ) {
                
$show_caption_desc $caption_desc_source !== 'none';
            } else {
                
//always show both title and desc for the presets
                
$show_caption_desc true;
            }

            
$caption_desc foogallery_get_caption_desc_for_attachment$foogallery_attachment->_post$caption_desc_source );
        }

        if ( 
$caption_title && $show_caption_title ) {
            
$captions['title'] = $caption_title;
        }
        if ( 
$caption_desc && $show_caption_desc ) {
            
$captions['desc'] = $caption_desc;
        }

    } else {
        
$captions false;
    }

    return 
apply_filters'foogallery_build_attachment_html_caption'$captions$foogallery_attachment$args );
}

/**
 * Returns generic html for captions
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.0
 *
 * @return string
 */
function foogallery_attachment_html_caption$foogallery_attachment$args = array() ) {
    
$captions foogallery_build_attachment_html_caption$foogallery_attachment$args );
    
$html '';

    if ( 
$captions !== false ) {
        
$html '<figcaption class="fg-caption"><div class="fg-caption-inner">';
        if ( 
array_key_exists'title'$captions ) ) {
            
$html .= '<div class="fg-caption-title">' $captions['title'] . '</div>';
        }
        if ( 
array_key_exists'desc'$captions ) ) {
            
$html .= '<div class="fg-caption-desc">' $captions['desc'] . '</div>';
        }
        
$html .= '</div></figcaption>';
    }

    return 
apply_filters'foogallery_attachment_html_caption'$html$foogallery_attachment$args );
}

/**
 * Returns the attachment item opening HTML
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.0
 *
 * @return string
 */
function foogallery_attachment_html_item_opening($foogallery_attachment$args = array() ) {

    
$classes[] = 'fg-item';

    
$classes apply_filters'foogallery_attachment_html_item_classes'$classes$foogallery_attachment$args );

    
$class_list '';
    if ( 
is_array$classes ) ) {
        
$class_list implode' '$classes );
    }

    
$attachment_item_figure_class apply_filters'foogallery_attachment_html_item_figure_class''fg-item-inner'$foogallery_attachment$args );
    
$html '<div class="' $class_list '"><figure class="'esc_attr$attachment_item_figure_class ) . '">';
    return 
apply_filters'foogallery_attachment_html_item_opening'$html$foogallery_attachment$args );
}

/**
 * Returns generic html for an attachment
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array $args
 *
 * @since 1.4.0
 *
 * @return string
 */
function foogallery_attachment_html$foogallery_attachment$args = array() ) {

    
//check if no arguments were passed in, and build them up if so
    
if ( empty( $args ) ) {
        
$args foogallery_gallery_template_arguments();
    }

    
$html foogallery_attachment_html_item_opening$foogallery_attachment$args );
    
$html .= foogallery_attachment_html_anchor_opening$foogallery_attachment$args );
    
$html .= '<span class="fg-image-wrap">';
    
$html .= foogallery_attachment_html_image$foogallery_attachment$args );
    
$html .= '</span>';
    
$html .= '</a>';
    
$html .= foogallery_attachment_html_caption$foogallery_attachment$args );
    
$html .= '</figure><div class="fg-loader"></div></div>';
    return 
$html;
}

/**
 * Get the foogallery template arguments for the current foogallery that is being output to the frontend
 *
 * @return array
 */
function foogallery_gallery_template_arguments() {
    global 
$current_foogallery_template;

    return 
apply_filters'foogallery_gallery_template_arguments-' $current_foogallery_template, array() );
}

/**
 * Build up an object that will be encoded to JSON for a FooGallery Attachment
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array                $args
 *
 * @since 1.6.0
 *
 * @returns string
 * @return string
 */
function foogallery_build_json_object_from_attachment$foogallery_attachment$args = array() ) {
    if ( isset( 
$foogallery_attachment ) ) {

        
//check if no arguments were passed in, and build them up if so
        
if ( empty( $args ) ) {
            
$args foogallery_gallery_template_arguments();
        }

        
$anchor_attributes foogallery_build_attachment_html_anchor_attributes$foogallery_attachment$args );
        
$image_attributes  foogallery_build_attachment_html_image_attributes$foogallery_attachment$args );
        
$captions          foogallery_build_attachment_html_caption$foogallery_attachment$args );

        if ( 
array_key_exists'data-src-fg'$image_attributes ) ) {
            
$src $image_attributes['data-src-fg'];
        } else if (
array_key_exists'src'$image_attributes ) ) {
            
$src $image_attributes['src'];
        }

        if ( 
array_key_exists'data-srcset-fg'$image_attributes ) ) {
            
$srcset $image_attributes['data-srcset-fg'];
        } else if ( 
array_key_exists'srcset'$image_attributes ) ) {
            
$srcset $image_attributes['srcset'];
        }

        
$json_object       = new stdClass();
        
$json_object->href $anchor_attributes['href'];
        if ( isset( 
$src ) ) {
            
$json_object->src $src;
        }
        if ( isset( 
$srcset ) ) {
            
$json_object->srcset $srcset;
        }
        if ( 
array_key_exists'width'$image_attributes ) ) {
            
$json_object->width $image_attributes['width'];
        }
        if ( 
array_key_exists'height'$image_attributes ) ) {
            
$json_object->height $image_attributes['height'];
        }

        
$json_object->alt $foogallery_attachment->alt;

        
$json_object_attr_anchor                         = new stdClass();
        
$json_object_attr_anchor->{'data-attachment-id'} = $foogallery_attachment->ID;

        if ( 
$captions !== false ) {
            if ( 
array_key_exists'title'$captions ) ) {
                
$json_object->caption $json_object->title $json_object_attr_anchor->{'data-caption-title'} = $captions['title'];
            }
            if ( 
array_key_exists'desc'$captions ) ) {
                
$json_object->description $json_object_attr_anchor->{'data-caption-desc'} = $captions['desc'];
            }
        }

        
$json_object->attr         = new stdClass();
        
$json_object->attr->anchor $json_object_attr_anchor;

        
$json_object apply_filters'foogallery_build_attachment_json'$json_object$foogallery_attachment$args$anchor_attributes$image_attributes$captions );

        return 
$json_object;
    }

    return 
false;
}

/**
 * Build up a JSON string for a FooGallery Attachment
 *
 * @param FooGalleryAttachment $foogallery_attachment
 * @param array                $args
 *
 * @since 1.4.9
 *
 * @returns string
 * @return string
 */
function foogallery_build_json_from_attachment$foogallery_attachment$args = array() ) {
    if ( isset( 
$foogallery_attachment ) ) {

        
$json_object foogallery_build_json_object_from_attachment$foogallery_attachment$args );

        if ( 
defined'JSON_UNESCAPED_UNICODE' ) ) {
            return 
json_encode$json_objectJSON_UNESCAPED_UNICODE );
        } else {
            return 
json_encode$json_object );
        }
    }

    return 
'';
}