1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* FooGallery global functions |
4
|
|
|
* |
5
|
|
|
* @package FooGallery |
6
|
|
|
* @author Brad Vincent <[email protected]> |
7
|
|
|
* @license GPL-2.0+ |
8
|
|
|
* @link https://github.com/fooplugins/foogallery |
9
|
|
|
* @copyright 2014 FooPlugins LLC |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Returns the name of the plugin. (Allows the name to be overridden from extensions or functions.php) |
14
|
|
|
* @return string |
15
|
|
|
*/ |
16
|
|
|
function foogallery_plugin_name() { |
17
|
|
|
return apply_filters( 'foogallery_plugin_name', 'FooGallery' ); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Return all the gallery templates used within FooGallery |
22
|
|
|
* |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
function foogallery_gallery_templates() { |
26
|
|
|
return apply_filters( 'foogallery_gallery_templates', array() ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Return a specific gallery template based on the slug |
31
|
|
|
* @param $slug |
32
|
|
|
* |
33
|
|
|
* @return bool|array |
34
|
|
|
*/ |
35
|
|
|
function foogallery_get_gallery_template( $slug ) { |
36
|
|
|
foreach ( foogallery_gallery_templates() as $template ) { |
37
|
|
|
if ( $slug == $template['slug'] ) { |
38
|
|
|
return $template; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Return the FooGallery extension API class |
47
|
|
|
* |
48
|
|
|
* @return FooGallery_Extensions_API |
49
|
|
|
*/ |
50
|
|
|
function foogallery_extensions_api() { |
51
|
|
|
return new FooGallery_Extensions_API(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the default gallery template |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
function foogallery_default_gallery_template() { |
60
|
|
|
return foogallery_get_setting( 'gallery_template' ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns if gallery permalinks are enabled |
65
|
|
|
* |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
function foogallery_permalinks_enabled() { |
69
|
|
|
return foogallery_get_setting( 'gallery_permalinks_enabled' ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the gallery permalink |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
function foogallery_permalink() { |
78
|
|
|
return foogallery_get_setting( 'gallery_permalink' ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Return the FooGallery saved setting, or a default value |
83
|
|
|
* |
84
|
|
|
* @param string $key The key for the setting |
85
|
|
|
* |
86
|
|
|
* @param bool $default The default if no value is saved or found |
87
|
|
|
* |
88
|
|
|
* @return mixed |
89
|
|
|
*/ |
90
|
|
|
function foogallery_get_setting( $key, $default = false ) { |
91
|
|
|
$foogallery = FooGallery_Plugin::get_instance(); |
92
|
|
|
|
93
|
|
|
return $foogallery->options()->get( $key, foogallery_get_default( $key, $default ) ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Builds up a FooGallery gallery shortcode |
98
|
|
|
* |
99
|
|
|
* @param $gallery_id |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
function foogallery_build_gallery_shortcode( $gallery_id ) { |
104
|
|
|
return '[' . foogallery_gallery_shortcode_tag() . ' id="' . $gallery_id . '"]'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns the gallery shortcode tag |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
function foogallery_gallery_shortcode_tag() { |
113
|
|
|
return apply_filters( 'foogallery_gallery_shortcode_tag', FOOGALLERY_CPT_GALLERY ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Helper method for getting default settings |
118
|
|
|
* |
119
|
|
|
* @param string $key The default config key to retrieve. |
120
|
|
|
* |
121
|
|
|
* @param bool $default The default if no default is set or found |
122
|
|
|
* |
123
|
|
|
* @return string Key value on success, false on failure. |
124
|
|
|
*/ |
125
|
|
|
function foogallery_get_default( $key, $default = false ) { |
126
|
|
|
|
127
|
|
|
$defaults = array( |
128
|
|
|
'gallery_template' => 'default', |
129
|
|
|
'gallery_permalinks_enabled' => false, |
130
|
|
|
'gallery_permalink' => 'gallery', |
131
|
|
|
'lightbox' => 'none', |
132
|
|
|
'thumb_jpeg_quality' => '80', |
133
|
|
|
'thumb_resize_animations' => true, |
134
|
|
|
'gallery_sorting' => '', |
135
|
|
|
'datasource' => 'media_library' |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
// A handy filter to override the defaults |
139
|
|
|
$defaults = apply_filters( 'foogallery_defaults', $defaults ); |
140
|
|
|
|
141
|
|
|
// Return the key specified. |
142
|
|
|
return isset($defaults[ $key ]) ? $defaults[ $key ] : $default; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Returns the FooGallery Add Gallery Url within the admin |
147
|
|
|
* |
148
|
|
|
* @return string The Url to the FooGallery Add Gallery page in admin |
149
|
|
|
*/ |
150
|
|
|
function foogallery_admin_add_gallery_url() { |
151
|
|
|
return admin_url( 'post-new.php?post_type=' . FOOGALLERY_CPT_GALLERY ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Returns the FooGallery help page Url within the admin |
156
|
|
|
* |
157
|
|
|
* @return string The Url to the FooGallery help page in admin |
158
|
|
|
*/ |
159
|
|
|
function foogallery_admin_help_url() { |
160
|
|
|
return admin_url( add_query_arg( array( 'page' => FOOGALLERY_ADMIN_MENU_HELP_SLUG ), foogallery_admin_menu_parent_slug() ) ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Returns the FooGallery settings page Url within the admin |
165
|
|
|
* |
166
|
|
|
* @return string The Url to the FooGallery settings page in admin |
167
|
|
|
*/ |
168
|
|
|
function foogallery_admin_settings_url() { |
169
|
|
|
return admin_url( add_query_arg( array( 'page' => FOOGALLERY_ADMIN_MENU_SETTINGS_SLUG ), foogallery_admin_menu_parent_slug() ) ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Returns the FooGallery extensions page Url within the admin |
174
|
|
|
* |
175
|
|
|
* @return string The Url to the FooGallery extensions page in admin |
176
|
|
|
*/ |
177
|
|
|
function foogallery_admin_extensions_url() { |
178
|
|
|
return admin_url( add_query_arg( array( 'page' => FOOGALLERY_ADMIN_MENU_EXTENSIONS_SLUG ), foogallery_admin_menu_parent_slug() ) ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Returns the FooGallery system info page Url within the admin |
183
|
|
|
* |
184
|
|
|
* @return string The Url to the FooGallery system info page in admin |
185
|
|
|
*/ |
186
|
|
|
function foogallery_admin_systeminfo_url() { |
187
|
|
|
return admin_url( add_query_arg( array( 'page' => FOOGALLERY_ADMIN_MENU_SYSTEMINFO_SLUG ), foogallery_admin_menu_parent_slug() ) ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Returns the FooGallery pricing page Url within the admin |
192
|
|
|
* |
193
|
|
|
* @return string The Url to the FooGallery pricing page in admin |
194
|
|
|
*/ |
195
|
|
|
function foogallery_admin_pricing_url() { |
196
|
|
|
return admin_url( add_query_arg( array( 'page' => FOOGALLERY_ADMIN_MENU_PRICING_SLUG ), foogallery_admin_menu_parent_slug() ) ); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Returns the FooGallery free trial pricing page Url within the admin |
201
|
|
|
* |
202
|
|
|
* @return string The Url to the FooGallery free trial page in admin |
203
|
|
|
*/ |
204
|
|
|
function foogallery_admin_freetrial_url() { |
205
|
|
|
return add_query_arg( 'trial', 'true', foogallery_admin_pricing_url() ); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Get a foogallery template setting for the current foogallery that is being output to the frontend |
210
|
|
|
* @param string $key |
211
|
|
|
* @param string $default |
212
|
|
|
* |
213
|
|
|
* @return bool |
214
|
|
|
*/ |
215
|
|
|
function foogallery_gallery_template_setting( $key, $default = '' ) { |
216
|
|
|
global $current_foogallery; |
217
|
|
|
global $current_foogallery_arguments; |
218
|
|
|
global $current_foogallery_template; |
|
|
|
|
219
|
|
|
|
220
|
|
|
$settings_key = "{$current_foogallery_template}_{$key}"; |
221
|
|
|
|
222
|
|
|
if ( $current_foogallery_arguments && array_key_exists( $key, $current_foogallery_arguments ) ) { |
223
|
|
|
//try to get the value from the arguments |
224
|
|
|
$value = $current_foogallery_arguments[ $key ]; |
225
|
|
|
|
226
|
|
|
} else if ( !empty( $current_foogallery ) && $current_foogallery->settings && array_key_exists( $settings_key, $current_foogallery->settings ) ) { |
227
|
|
|
//then get the value out of the saved gallery settings |
228
|
|
|
$value = $current_foogallery->settings[ $settings_key ]; |
229
|
|
|
} else { |
230
|
|
|
//otherwise set it to the default |
231
|
|
|
$value = $default; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
$value = apply_filters( 'foogallery_gallery_template_setting-' . $key, $value ); |
235
|
|
|
|
236
|
|
|
return $value; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Get the admin menu parent slug |
241
|
|
|
* @return string |
242
|
|
|
*/ |
243
|
|
|
function foogallery_admin_menu_parent_slug() { |
244
|
|
|
return apply_filters( 'foogallery_admin_menu_parent_slug', FOOGALLERY_ADMIN_MENU_PARENT_SLUG ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Helper function to build up the admin menu Url |
249
|
|
|
* @param array $extra_args |
250
|
|
|
* |
251
|
|
|
* @return string|void |
252
|
|
|
*/ |
253
|
|
|
function foogallery_build_admin_menu_url( $extra_args = array() ) { |
254
|
|
|
$url = admin_url( foogallery_admin_menu_parent_slug() ); |
255
|
|
|
if ( ! empty( $extra_args ) ) { |
256
|
|
|
$url = add_query_arg( $extra_args, $url ); |
257
|
|
|
} |
258
|
|
|
return $url; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Helper function for adding a foogallery sub menu |
263
|
|
|
* |
264
|
|
|
* @param $menu_title |
265
|
|
|
* @param string $capability |
266
|
|
|
* @param string $menu_slug |
267
|
|
|
* @param $function |
268
|
|
|
*/ |
269
|
|
|
function foogallery_add_submenu_page( $menu_title, $capability, $menu_slug, $function ) { |
270
|
|
|
add_submenu_page( |
271
|
|
|
foogallery_admin_menu_parent_slug(), |
272
|
|
|
$menu_title, |
273
|
|
|
$menu_title, |
274
|
|
|
apply_filters( 'foogallery_admin_menu_capability', $capability ), |
275
|
|
|
$menu_slug, |
276
|
|
|
$function |
277
|
|
|
); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Returns all FooGallery galleries |
282
|
|
|
* |
283
|
|
|
* @return FooGallery[] array of FooGallery galleries |
284
|
|
|
*/ |
285
|
|
|
function foogallery_get_all_galleries( $excludes = false, $extra_args = false ) { |
286
|
|
|
$args = array( |
287
|
|
|
'post_type' => FOOGALLERY_CPT_GALLERY, |
288
|
|
|
'post_status' => array( 'publish', 'draft' ), |
289
|
|
|
'cache_results' => false, |
290
|
|
|
'nopaging' => true, |
291
|
|
|
); |
292
|
|
|
|
293
|
|
|
if ( is_array( $excludes ) ) { |
294
|
|
|
$args['post__not_in'] = $excludes; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
if ( is_array( $extra_args ) ) { |
298
|
|
|
$args = array_merge( $args, $extra_args ); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
$gallery_posts = get_posts( $args ); |
302
|
|
|
|
303
|
|
|
if ( empty( $gallery_posts ) ) { |
304
|
|
|
return array(); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
$galleries = array(); |
308
|
|
|
|
309
|
|
|
foreach ( $gallery_posts as $post ) { |
310
|
|
|
$galleries[] = FooGallery::get( $post ); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
return $galleries; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Parse some content and return an array of all gallery shortcodes that are used inside it |
318
|
|
|
* |
319
|
|
|
* @param $content The content to search for gallery shortcodes |
320
|
|
|
* |
321
|
|
|
* @return array An array of all the foogallery shortcodes found in the content |
322
|
|
|
*/ |
323
|
|
|
function foogallery_extract_gallery_shortcodes( $content ) { |
324
|
|
|
$shortcodes = array(); |
325
|
|
|
|
326
|
|
|
$regex_pattern = foogallery_gallery_shortcode_regex(); |
327
|
|
|
if ( preg_match_all( '/' . $regex_pattern . '/s', $content, $matches ) ) { |
328
|
|
|
for ( $i = 0; $i < count( $matches[0] ); ++$i ) { |
329
|
|
|
$shortcode = $matches[0][$i]; |
330
|
|
|
$args = $matches[3][$i]; |
331
|
|
|
$attribure_string = str_replace( ' ', '&', trim( $args ) ); |
332
|
|
|
$attribure_string = str_replace( '"', '', $attribure_string ); |
333
|
|
|
$attributes = wp_parse_args( $attribure_string ); |
334
|
|
|
if ( array_key_exists( 'id', $attributes ) ) { |
335
|
|
|
$id = intval( $attributes['id'] ); |
336
|
|
|
$shortcodes[ $id ] = $shortcode; |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
return $shortcodes; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Build up the FooGallery shortcode regex |
346
|
|
|
* |
347
|
|
|
* @return string |
348
|
|
|
*/ |
349
|
|
|
function foogallery_gallery_shortcode_regex() { |
350
|
|
|
$tag = foogallery_gallery_shortcode_tag(); |
351
|
|
|
|
352
|
|
|
return |
353
|
|
|
'\\[' // Opening bracket |
354
|
|
|
. '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] |
355
|
|
|
. "($tag)" // 2: Shortcode name |
356
|
|
|
. '(?![\\w-])' // Not followed by word character or hyphen |
357
|
|
|
. '(' // 3: Unroll the loop: Inside the opening shortcode tag |
358
|
|
|
. '[^\\]\\/]*' // Not a closing bracket or forward slash |
359
|
|
|
. '(?:' |
360
|
|
|
. '\\/(?!\\])' // A forward slash not followed by a closing bracket |
361
|
|
|
. '[^\\]\\/]*' // Not a closing bracket or forward slash |
362
|
|
|
. ')*?' |
363
|
|
|
. ')' |
364
|
|
|
. '(?:' |
365
|
|
|
. '(\\/)' // 4: Self closing tag ... |
|
|
|
|
366
|
|
|
. '\\]' // ... and closing bracket |
367
|
|
|
. '|' |
368
|
|
|
. '\\]' // Closing bracket |
369
|
|
|
. '(?:' |
370
|
|
|
. '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags |
371
|
|
|
. '[^\\[]*+' // Not an opening bracket |
372
|
|
|
. '(?:' |
373
|
|
|
. '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag |
374
|
|
|
. '[^\\[]*+' // Not an opening bracket |
375
|
|
|
. ')*+' |
376
|
|
|
. ')' |
377
|
|
|
. '\\[\\/\\2\\]' // Closing shortcode tag |
378
|
|
|
. ')?' |
379
|
|
|
. ')' |
380
|
|
|
. '(\\]?)'; // 6: Optional second closing bracket for escaping shortcodes: [[tag]] |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Builds up a class attribute that can be used in a gallery template |
385
|
|
|
* @param $gallery FooGallery |
386
|
|
|
* |
387
|
|
|
* @return string the classname based on the gallery and any extra attributes |
388
|
|
|
*/ |
389
|
|
|
function foogallery_build_class_attribute( $gallery ) { |
390
|
|
|
|
391
|
|
|
$classes[] = 'foogallery'; |
|
|
|
|
392
|
|
|
$classes[] = 'foogallery-container'; |
393
|
|
|
$classes[] = "foogallery-{$gallery->gallery_template}"; |
394
|
|
|
|
395
|
|
|
$num_args = func_num_args(); |
396
|
|
|
|
397
|
|
|
if ( $num_args > 1 ) { |
398
|
|
|
$arg_list = func_get_args(); |
399
|
|
|
for ( $i = 1; $i < $num_args; $i++ ) { |
400
|
|
|
$classes[] = $arg_list[$i]; |
401
|
|
|
} |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
$classes = apply_filters( 'foogallery_build_class_attribute', $classes, $gallery ); |
405
|
|
|
|
406
|
|
|
$classes = array_filter( $classes ); |
407
|
|
|
|
408
|
|
|
return implode( ' ', $classes ); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Builds up a SAFE class attribute that can be used in a gallery template |
413
|
|
|
* @param $gallery FooGallery |
414
|
|
|
* |
415
|
|
|
* @return string the classname based on the gallery and any extra attributes |
416
|
|
|
*/ |
417
|
|
|
function foogallery_build_class_attribute_safe( $gallery ) { |
|
|
|
|
418
|
|
|
$args = func_get_args(); |
419
|
|
|
$result = call_user_func_array("foogallery_build_class_attribute", $args); |
420
|
|
|
return esc_attr( $result ); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* Renders an escaped class attribute that can be used directly by gallery templates |
425
|
|
|
* |
426
|
|
|
* @param $gallery FooGallery |
427
|
|
|
*/ |
428
|
|
|
function foogallery_build_class_attribute_render_safe( $gallery ) { |
|
|
|
|
429
|
|
|
$args = func_get_args(); |
430
|
|
|
$result = call_user_func_array("foogallery_build_class_attribute_safe", $args); |
431
|
|
|
echo $result; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Builds up the attributes that are appended to a gallery template container |
436
|
|
|
* |
437
|
|
|
* @param $gallery FooGallery |
438
|
|
|
* @param $attributes array |
439
|
|
|
* |
440
|
|
|
* @return string |
441
|
|
|
*/ |
442
|
|
|
function foogallery_build_container_attributes_safe( $gallery, $attributes ) { |
443
|
|
|
|
444
|
|
|
//add the default gallery id |
445
|
|
|
$attributes['id'] = 'foogallery-gallery-' . $gallery->ID; |
446
|
|
|
|
447
|
|
|
//add the standard data-foogallery attribute so that the JS initializes correctly |
448
|
|
|
$attributes['data-foogallery'] = foogallery_build_container_data_options( $gallery, $attributes ); |
449
|
|
|
|
450
|
|
|
//allow others to add their own attributes globally |
451
|
|
|
$attributes = apply_filters( 'foogallery_build_container_attributes', $attributes, $gallery ); |
452
|
|
|
|
453
|
|
|
//allow others to add their own attributes for a specific gallery template |
454
|
|
|
$attributes = apply_filters( 'foogallery_build_container_attributes-' . $gallery->gallery_template, $attributes, $gallery ); |
455
|
|
|
|
456
|
|
|
//clean up the attributes to make them safe for output |
457
|
|
|
$html = ''; |
458
|
|
|
foreach( $attributes as $key=>$value) { |
459
|
|
|
$safe_value = esc_attr( $value ); |
460
|
|
|
$html .= "{$key}=\"{$safe_value}\" "; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
return $html; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Builds up the data-foogallery attribute options that is used by the core javascript |
468
|
|
|
* |
469
|
|
|
* @param $gallery |
470
|
|
|
* @param $attributes |
471
|
|
|
* |
472
|
|
|
* @return string |
473
|
|
|
*/ |
474
|
|
|
function foogallery_build_container_data_options( $gallery, $attributes ) { |
475
|
|
|
$options = apply_filters( 'foogallery_build_container_data_options', array(), $gallery, $attributes ); |
476
|
|
|
|
477
|
|
|
$options = apply_filters( 'foogallery_build_container_data_options-'. $gallery->gallery_template, $options, $gallery, $attributes ); |
478
|
|
|
|
479
|
|
|
if ( defined( 'JSON_UNESCAPED_UNICODE' ) ) { |
480
|
|
|
return json_encode( $options, JSON_UNESCAPED_UNICODE ); |
481
|
|
|
} else { |
482
|
|
|
return json_encode( $options ); |
483
|
|
|
} |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Render a foogallery |
488
|
|
|
* |
489
|
|
|
* @param $gallery_id int The id of the foogallery you want to render |
490
|
|
|
* @param array $args |
491
|
|
|
*/ |
492
|
|
|
function foogallery_render_gallery( $gallery_id, $args = array()) { |
493
|
|
|
//create new instance of template engine |
494
|
|
|
$engine = new FooGallery_Template_Loader(); |
495
|
|
|
|
496
|
|
|
$shortcode_args = wp_parse_args( $args, array( |
497
|
|
|
'id' => $gallery_id |
498
|
|
|
) ); |
499
|
|
|
|
500
|
|
|
$engine->render_template( $shortcode_args ); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* Returns the available sorting options that can be chosen for galleries and albums |
505
|
|
|
*/ |
506
|
|
|
function foogallery_sorting_options() { |
507
|
|
|
return apply_filters( 'foogallery_sorting_options', array( |
508
|
|
|
'' => __('Default', 'foogallery'), |
509
|
|
|
'date_desc' => __('Date created - newest first', 'foogallery'), |
510
|
|
|
'date_asc' => __('Date created - oldest first', 'foogallery'), |
511
|
|
|
'modified_desc' => __('Date modified - most recent first', 'foogallery'), |
512
|
|
|
'modified_asc' => __('Date modified - most recent last', 'foogallery'), |
513
|
|
|
'title_asc' => __('Title - alphabetically', 'foogallery'), |
514
|
|
|
'title_desc' => __('Title - reverse', 'foogallery'), |
515
|
|
|
'rand' => __('Random', 'foogallery') |
516
|
|
|
) ); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
function foogallery_sorting_get_posts_orderby_arg( $sorting_option ) { |
520
|
|
|
$orderby_arg = 'post__in'; |
521
|
|
|
|
522
|
|
|
switch ( $sorting_option ) { |
523
|
|
|
case 'date_desc': |
524
|
|
|
case 'date_asc': |
525
|
|
|
$orderby_arg = 'date'; |
526
|
|
|
break; |
527
|
|
|
case 'modified_desc': |
528
|
|
|
case 'modified_asc': |
529
|
|
|
$orderby_arg = 'modified'; |
530
|
|
|
break; |
531
|
|
|
case 'title_asc': |
532
|
|
|
case 'title_desc': |
533
|
|
|
$orderby_arg = 'title'; |
534
|
|
|
break; |
535
|
|
|
case 'rand': |
536
|
|
|
$orderby_arg = 'rand'; |
537
|
|
|
break; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
return apply_filters( 'foogallery_sorting_get_posts_orderby_arg', $orderby_arg, $sorting_option ); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
function foogallery_sorting_get_posts_order_arg( $sorting_option ) { |
544
|
|
|
$order_arg = 'DESC'; |
545
|
|
|
|
546
|
|
|
switch ( $sorting_option ) { |
547
|
|
|
case 'date_asc': |
548
|
|
|
case 'modified_asc': |
549
|
|
|
case 'title_asc': |
550
|
|
|
$order_arg = 'ASC'; |
551
|
|
|
break; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
return apply_filters( 'foogallery_sorting_get_posts_order_arg', $order_arg, $sorting_option ); |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
/** |
558
|
|
|
* @deprecated 1.4.7 Default templates loaded by default and no longer activated via extension |
559
|
|
|
* |
560
|
|
|
* Activate the default templates extension when there are no gallery templates loaded |
561
|
|
|
*/ |
562
|
|
|
function foogallery_activate_default_templates_extension() { |
563
|
|
|
//no longer needed but left in case any 3rd party extensions call this function |
564
|
|
|
_deprecated_function( __FUNCTION__, '1.4.7' ); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Allow FooGallery to enqueue stylesheet and allow them to be enqueued in the head on the next page load |
569
|
|
|
* |
570
|
|
|
* @param $handle string |
571
|
|
|
* @param $src string |
572
|
|
|
* @param array $deps |
573
|
|
|
* @param bool $ver |
574
|
|
|
* @param string $media |
575
|
|
|
*/ |
576
|
|
|
function foogallery_enqueue_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { |
577
|
|
|
wp_enqueue_style( $handle, $src, $deps, $ver, $media ); |
578
|
|
|
do_action( 'foogallery_enqueue_style', $handle, $src, $deps, $ver, $media ); |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
|
582
|
|
|
/** |
583
|
|
|
* Returns all foogallery post objects that are attached to the post |
584
|
|
|
* |
585
|
|
|
* @param $post_id int The ID of the post |
586
|
|
|
* |
587
|
|
|
* @return array List of foogallery posts. |
588
|
|
|
*/ |
589
|
|
|
function foogallery_get_galleries_attached_to_post( $post_id ) { |
590
|
|
|
$gallery_ids = get_post_meta( $post_id, FOOGALLERY_META_POST_USAGE, false ); |
591
|
|
|
|
592
|
|
|
if ( !empty( $gallery_ids ) ) { |
593
|
|
|
return get_posts( array( |
594
|
|
|
'post_type' => array( FOOGALLERY_CPT_GALLERY, ), |
595
|
|
|
'post_status' => array( 'draft', 'publish' ), |
596
|
|
|
'posts_per_page' => -1, |
597
|
|
|
'include' => $gallery_ids |
598
|
|
|
) ); |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
return array(); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* Clears all css load optimization post meta |
606
|
|
|
*/ |
607
|
|
|
function foogallery_clear_all_css_load_optimizations() { |
608
|
|
|
delete_post_meta_by_key( FOOGALLERY_META_POST_USAGE_CSS ); |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
/** |
612
|
|
|
* Performs a check to see if the plugin has been updated, and perform any housekeeping if necessary |
613
|
|
|
*/ |
614
|
|
|
function foogallery_perform_version_check() { |
615
|
|
|
$checker = new FooGallery_Version_Check(); |
616
|
|
|
$checker->perform_check(); |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* Returns the JPEG quality used when generating thumbnails |
621
|
|
|
* |
622
|
|
|
* @return int The quality value stored in settings |
623
|
|
|
*/ |
624
|
|
|
function foogallery_thumbnail_jpeg_quality() { |
625
|
|
|
$quality = intval( foogallery_get_setting( 'thumb_jpeg_quality' ) ); |
626
|
|
|
|
627
|
|
|
//check if we get an invalid value for whatever reason and if so return a default of 80 |
628
|
|
|
if ( $quality <= 0 ) { |
629
|
|
|
$quality = 80; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
return $quality; |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
/** |
636
|
|
|
* Returns the caption title source setting |
637
|
|
|
* |
638
|
|
|
* @return string |
639
|
|
|
*/ |
640
|
|
|
function foogallery_caption_title_source() { |
641
|
|
|
$source = foogallery_get_setting( 'caption_title_source', 'caption' ); |
|
|
|
|
642
|
|
|
|
643
|
|
|
if ( empty( $source ) ) { |
644
|
|
|
$source = 'caption'; |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
return $source; |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* Returns the attachment caption title based on the caption_title_source setting |
652
|
|
|
* |
653
|
|
|
* @param WP_Post $attachment_post |
654
|
|
|
* @param bool $source |
655
|
|
|
* |
656
|
|
|
* @return string |
657
|
|
|
*/ |
658
|
|
|
function foogallery_get_caption_title_for_attachment($attachment_post, $source = false) { |
659
|
|
|
if ( false === $source ) { |
660
|
|
|
$source = foogallery_gallery_template_setting( 'caption_title_source', false ); |
|
|
|
|
661
|
|
|
if ( empty( $source ) || "none" === $source ) { |
662
|
|
|
$source = foogallery_caption_title_source(); |
663
|
|
|
} |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
switch ( $source ) { |
667
|
|
|
case 'title': |
668
|
|
|
$caption = trim( $attachment_post->post_title ); |
669
|
|
|
break; |
670
|
|
|
case 'desc': |
671
|
|
|
$caption = trim( $attachment_post->post_content ); |
672
|
|
|
break; |
673
|
|
|
case 'alt': |
674
|
|
|
$caption = trim( get_post_meta( $attachment_post->ID, '_wp_attachment_image_alt', true ) ); |
675
|
|
|
break; |
676
|
|
|
default: |
677
|
|
|
$caption = trim( $attachment_post->post_excerpt ); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
return apply_filters( 'foogallery_get_caption_title_for_attachment', $caption, $attachment_post ); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* Returns the caption description source setting |
685
|
|
|
* |
686
|
|
|
* @return string |
687
|
|
|
*/ |
688
|
|
|
function foogallery_caption_desc_source() { |
689
|
|
|
$source = foogallery_get_setting( 'caption_desc_source', 'desc' ); |
|
|
|
|
690
|
|
|
|
691
|
|
|
if ( empty( $source ) ) { |
692
|
|
|
$source = 'desc'; |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
return $source; |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
/** |
699
|
|
|
* Returns the attachment caption description based on the caption_desc_source setting |
700
|
|
|
* |
701
|
|
|
* @param WP_Post $attachment_post |
702
|
|
|
* @param bool $source |
703
|
|
|
* |
704
|
|
|
* @return string |
705
|
|
|
*/ |
706
|
|
|
function foogallery_get_caption_desc_for_attachment($attachment_post, $source = false) { |
707
|
|
|
if ( false === $source ) { |
708
|
|
|
$source = foogallery_gallery_template_setting( 'caption_desc_source', false ); |
|
|
|
|
709
|
|
|
if ( empty( $source ) || "none" === $source ) { |
710
|
|
|
$source = foogallery_caption_desc_source(); |
711
|
|
|
} |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
switch ( $source ) { |
715
|
|
|
case 'title': |
716
|
|
|
$caption = trim( $attachment_post->post_title ); |
717
|
|
|
break; |
718
|
|
|
case 'caption': |
719
|
|
|
$caption = trim( $attachment_post->post_excerpt ); |
720
|
|
|
break; |
721
|
|
|
case 'alt': |
722
|
|
|
$caption = trim( get_post_meta( $attachment_post->ID, '_wp_attachment_image_alt', true ) ); |
723
|
|
|
break; |
724
|
|
|
default: |
725
|
|
|
$caption = trim( $attachment_post->post_content ); |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
return apply_filters( 'foogallery_get_caption_desc_for_attachment', $caption, $attachment_post ); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* Runs thumbnail tests and outputs results in a table format |
733
|
|
|
*/ |
734
|
|
|
function foogallery_output_thumbnail_generation_results() { |
735
|
|
|
$thumbs = new FooGallery_Thumbnails(); |
736
|
|
|
try { |
737
|
|
|
$results = $thumbs->run_thumbnail_generation_tests(); |
738
|
|
|
if ( $results['success'] ) { |
739
|
|
|
echo '<span style="color:#0c0">' . __('Thumbnail generation test ran successfully.', 'foogallery') . '</span>'; |
740
|
|
|
} else { |
741
|
|
|
echo '<span style="color:#c00">' . __('Thumbnail generation test failed!', 'foogallery') . '</span>'; |
742
|
|
|
var_dump( $results['error'] ); |
743
|
|
|
var_dump( $results['file_info'] ); |
744
|
|
|
} |
745
|
|
|
} |
746
|
|
|
catch (Exception $e) { |
747
|
|
|
echo 'Exception: ' . $e->getMessage(); |
748
|
|
|
} |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
/** |
752
|
|
|
* Returns the URL to the test image |
753
|
|
|
* |
754
|
|
|
* @return string |
755
|
|
|
*/ |
756
|
|
|
function foogallery_test_thumb_url() { |
757
|
|
|
return apply_filters( 'foogallery_test_thumb_url', FOOGALLERY_URL . 'assets/logo.png' ); |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* Return all the gallery datasources used within FooGallery |
762
|
|
|
* |
763
|
|
|
* @return array |
764
|
|
|
*/ |
765
|
|
|
function foogallery_gallery_datasources() { |
766
|
|
|
$default_datasource = foogallery_default_datasource(); |
767
|
|
|
|
768
|
|
|
$datasources[$default_datasource] = 'FooGalleryDatasource_MediaLibrary'; |
|
|
|
|
769
|
|
|
|
770
|
|
|
return apply_filters( 'foogallery_gallery_datasources', $datasources ); |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
/** |
774
|
|
|
* Returns the default gallery datasource |
775
|
|
|
* |
776
|
|
|
* @return string |
777
|
|
|
*/ |
778
|
|
|
function foogallery_default_datasource() { |
779
|
|
|
return foogallery_get_default( 'datasource', 'media_library' ); |
|
|
|
|
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
/** |
783
|
|
|
* Instantiates a FooGallery datasource based on a datasource name |
784
|
|
|
* |
785
|
|
|
* @param $datasource_name string |
786
|
|
|
* |
787
|
|
|
* @return IFooGalleryDatasource |
788
|
|
|
*/ |
789
|
|
|
function foogallery_instantiate_datasource( $datasource_name ) { |
790
|
|
|
$datasources = foogallery_gallery_datasources(); |
791
|
|
|
if ( array_key_exists( $datasource_name, $datasources ) ) { |
792
|
|
|
return new $datasources[$datasource_name]; |
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
return new FooGalleryDatasource_MediaLibrary(); |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
/** |
799
|
|
|
* Returns the src to the built-in image placeholder |
800
|
|
|
* @return string |
801
|
|
|
*/ |
802
|
|
|
function foogallery_image_placeholder_src() { |
803
|
|
|
return apply_filters( 'foogallery_image_placeholder_src', FOOGALLERY_URL . 'assets/image-placeholder.png' ); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
/** |
807
|
|
|
* Returns the image html for the built-in image placeholder |
808
|
|
|
* |
809
|
|
|
* @param array $args |
810
|
|
|
* |
811
|
|
|
* @return string |
812
|
|
|
*/ |
813
|
|
|
function foogallery_image_placeholder_html( $args ) { |
814
|
|
|
if ( !isset( $args ) ) { |
815
|
|
|
$args = array( |
816
|
|
|
'width' => 150, |
817
|
|
|
'height' => 150 |
818
|
|
|
); |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
$args['src'] = foogallery_image_placeholder_src(); |
822
|
|
|
$args = array_map( 'esc_attr', $args ); |
823
|
|
|
$html = '<img '; |
824
|
|
|
foreach ( $args as $name => $value ) { |
825
|
|
|
$html .= " $name=" . '"' . $value . '"'; |
826
|
|
|
} |
827
|
|
|
$html .= ' />'; |
828
|
|
|
return apply_filters( 'foogallery_image_placeholder_html', $html, $args ); |
829
|
|
|
} |
830
|
|
|
|
831
|
|
|
/** |
832
|
|
|
* Returns the thumbnail html for the featured attachment for a gallery. |
833
|
|
|
* If no featured attachment can be found, then a placeholder image src is returned instead |
834
|
|
|
* |
835
|
|
|
* @param FooGallery $gallery |
836
|
|
|
* @param array $args |
837
|
|
|
* |
838
|
|
|
* @return string |
839
|
|
|
*/ |
840
|
|
|
function foogallery_find_featured_attachment_thumbnail_html( $gallery, $args = null ){ |
841
|
|
|
if ( !isset( $gallery ) || false === $gallery ) return ''; |
842
|
|
|
|
843
|
|
|
if ( !isset( $args ) ) { |
844
|
|
|
$args = array( |
845
|
|
|
'width' => 150, |
846
|
|
|
'height' => 150 |
847
|
|
|
); |
848
|
|
|
} |
849
|
|
|
|
850
|
|
|
$featuredAttachment = $gallery->featured_attachment(); |
851
|
|
|
if ( $featuredAttachment ) { |
852
|
|
|
return $featuredAttachment->html_img( $args ); |
853
|
|
|
} else { |
854
|
|
|
//if we have no featured attachment, then use the built-in image placeholder |
855
|
|
|
return foogallery_image_placeholder_html( $args ); |
856
|
|
|
} |
857
|
|
|
} |
858
|
|
|
|
859
|
|
|
/** |
860
|
|
|
* Returns the thumbnail src for the featured attachment for a gallery. |
861
|
|
|
* If no featured attachment can be found, then a placeholder image src is returned instead |
862
|
|
|
* |
863
|
|
|
* @param FooGallery $gallery |
864
|
|
|
* @param array $args |
865
|
|
|
* |
866
|
|
|
* @return string |
867
|
|
|
*/ |
868
|
|
|
function foogallery_find_featured_attachment_thumbnail_src( $gallery, $args = null ){ |
869
|
|
|
if ( !isset( $gallery ) || false === $gallery ) return ''; |
870
|
|
|
|
871
|
|
|
if ( !isset( $args ) ) { |
872
|
|
|
$args = array( |
873
|
|
|
'width' => 150, |
874
|
|
|
'height' => 150 |
875
|
|
|
); |
876
|
|
|
} |
877
|
|
|
|
878
|
|
|
$featuredAttachment = $gallery->featured_attachment(); |
879
|
|
|
if ( $featuredAttachment ) { |
880
|
|
|
return $featuredAttachment->html_img_src( $args ); |
881
|
|
|
} else { |
882
|
|
|
//if we have no featured attachment, then use the built-in image placeholder |
883
|
|
|
return foogallery_image_placeholder_src(); |
884
|
|
|
} |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
/** |
888
|
|
|
* Returns the available retina options that can be chosen |
889
|
|
|
*/ |
890
|
|
|
function foogallery_retina_options() { |
891
|
|
|
return apply_filters( 'foogallery_retina_options', array( |
892
|
|
|
'2x' => __('2x', 'foogallery'), |
893
|
|
|
'3x' => __('3x', 'foogallery'), |
894
|
|
|
'4x' => __('4x', 'foogallery') |
895
|
|
|
) ); |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
/** |
899
|
|
|
* Does a full uninstall of the plugin including all data and settings! |
900
|
|
|
*/ |
901
|
|
|
function foogallery_uninstall() { |
902
|
|
|
|
903
|
|
|
if ( !current_user_can( 'install_plugins' ) ) exit; |
904
|
|
|
|
905
|
|
|
//delete all gallery posts first |
906
|
|
|
global $wpdb; |
|
|
|
|
907
|
|
|
$query = "SELECT p.ID FROM {$wpdb->posts} AS p WHERE p.post_type IN (%s)"; |
908
|
|
|
$gallery_post_ids = $wpdb->get_col( $wpdb->prepare( $query, FOOGALLERY_CPT_GALLERY ) ); |
909
|
|
|
|
910
|
|
|
if ( !empty( $gallery_post_ids ) ) { |
911
|
|
|
$deleted = 0; |
912
|
|
|
foreach ( $gallery_post_ids as $post_id ) { |
913
|
|
|
$del = wp_delete_post( $post_id ); |
914
|
|
|
if ( false !== $del ) { |
915
|
|
|
++$deleted; |
916
|
|
|
} |
917
|
|
|
} |
918
|
|
|
} |
919
|
|
|
|
920
|
|
|
//delete all options |
921
|
|
|
if ( is_network_admin() ) { |
922
|
|
|
delete_site_option( FOOGALLERY_SLUG ); |
923
|
|
|
} else { |
924
|
|
|
delete_option( FOOGALLERY_SLUG ); |
925
|
|
|
} |
926
|
|
|
delete_option( FOOGALLERY_OPTION_VERSION ); |
927
|
|
|
delete_option( FOOGALLERY_OPTION_THUMB_TEST ); |
928
|
|
|
delete_option( FOOGALLERY_EXTENSIONS_SLUGS_OPTIONS_KEY ); |
929
|
|
|
delete_option( FOOGALLERY_EXTENSIONS_LOADING_ERRORS ); |
930
|
|
|
delete_option( FOOGALLERY_EXTENSIONS_LOADING_ERRORS_RESPONSE ); |
931
|
|
|
delete_option( FOOGALLERY_EXTENSIONS_SLUGS_OPTIONS_KEY ); |
932
|
|
|
delete_option( FOOGALLERY_EXTENSIONS_ACTIVATED_OPTIONS_KEY ); |
933
|
|
|
delete_option( FOOGALLERY_EXTENSIONS_ERRORS_OPTIONS_KEY ); |
934
|
|
|
|
935
|
|
|
//let any extensions clean up after themselves |
936
|
|
|
do_action( 'foogallery_uninstall' ); |
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
/** |
940
|
|
|
* Returns an attachment field friendly name, based on a field name that is passed in |
941
|
|
|
* |
942
|
|
|
* @param $field |
943
|
|
|
* |
944
|
|
|
* @return string |
945
|
|
|
*/ |
946
|
|
|
function foogallery_get_attachment_field_friendly_name( $field ) { |
947
|
|
|
switch ( $field ) { |
948
|
|
|
case 'title': |
949
|
|
|
return __( 'Attachment Title', 'foogallery' ); |
950
|
|
|
case 'caption': |
951
|
|
|
return __( 'Attachment Caption', 'foogallery' ); |
952
|
|
|
case 'desc': |
953
|
|
|
return __( 'Attachment Description', 'foogallery' ); |
954
|
|
|
case 'alt': |
955
|
|
|
return __( 'Attachment Alt', 'foogallery' ); |
956
|
|
|
} |
957
|
|
|
} |
958
|
|
|
|
959
|
|
|
/** |
960
|
|
|
* Returns the fields for a specific gallery template |
961
|
|
|
* |
962
|
|
|
* @param $template mixed |
963
|
|
|
* @return mixed |
964
|
|
|
*/ |
965
|
|
|
function foogallery_get_fields_for_template( $template ) { |
966
|
|
|
|
967
|
|
|
if ( is_string( $template ) ) { |
968
|
|
|
$template = foogallery_get_gallery_template( $template ); |
969
|
|
|
} |
970
|
|
|
|
971
|
|
|
$fields = $template['fields']; |
972
|
|
|
|
973
|
|
|
// Allow for extensions to override fields for every gallery template. |
974
|
|
|
// Also passes the $template along so you can inspect and conditionally alter fields based on the template properties |
975
|
|
|
$fields = apply_filters( 'foogallery_override_gallery_template_fields', $fields, $template ); |
976
|
|
|
|
977
|
|
|
// Allow for extensions to override fields for a specific gallery template. |
978
|
|
|
// Also passes the $template along so you can inspect and conditionally alter fields based on the template properties |
979
|
|
|
$fields = apply_filters( "foogallery_override_gallery_template_fields-{$template['slug']}", $fields, $template ); |
980
|
|
|
|
981
|
|
|
foreach ( $fields as &$field ) { |
982
|
|
|
//allow for the field to be altered by extensions. Also used by the build-in fields, e.g. lightbox |
983
|
|
|
$field = apply_filters( 'foogallery_alter_gallery_template_field', $field, $template['slug'] ); |
984
|
|
|
} |
985
|
|
|
|
986
|
|
|
return $fields; |
987
|
|
|
} |
988
|
|
|
|
989
|
|
|
/** |
990
|
|
|
* Builds default settings for the supplied gallery template |
991
|
|
|
* |
992
|
|
|
* @param $template_name |
993
|
|
|
* @return array |
994
|
|
|
*/ |
995
|
|
|
function foogallery_build_default_settings_for_gallery_template( $template_name ) { |
996
|
|
|
$fields = foogallery_get_fields_for_template( $template_name ); |
997
|
|
|
$settings = array(); |
998
|
|
|
|
999
|
|
|
//loop through the fields and build up an array of keys and default values |
1000
|
|
|
foreach( $fields as $field ) { |
1001
|
|
|
$default = array_key_exists( 'default', $field ) ? $field['default'] : false; |
1002
|
|
|
if ( !empty( $default ) ) { |
1003
|
|
|
$settings["{$template_name}_{$field['id']}"] = $default; |
1004
|
|
|
} |
1005
|
|
|
} |
1006
|
|
|
|
1007
|
|
|
return $settings; |
1008
|
|
|
} |
1009
|
|
|
|
1010
|
|
|
/** |
1011
|
|
|
* Returns the choices used for the thumb link field type |
1012
|
|
|
* @return array |
1013
|
|
|
*/ |
1014
|
|
|
function foogallery_gallery_template_field_thumb_link_choices() { |
1015
|
|
|
return apply_filters( 'foogallery_gallery_template_field_thumb_links', array( |
1016
|
|
|
'image' => __( 'Full Size Image (Lightbox)', 'foogallery' ), |
1017
|
|
|
'page' => __( 'Image Attachment Page', 'foogallery' ), |
1018
|
|
|
'custom' => __( 'Custom URL', 'foogallery' ), |
1019
|
|
|
'none' => __( 'Not linked', 'foogallery' ), |
1020
|
|
|
) ); |
1021
|
|
|
} |
1022
|
|
|
|
1023
|
|
|
/** |
1024
|
|
|
* Returns the choices used for the lightbox field type |
1025
|
|
|
* @return array |
1026
|
|
|
*/ |
1027
|
|
|
function foogallery_gallery_template_field_lightbox_choices() { |
1028
|
|
|
$lightboxes = apply_filters( 'foogallery_gallery_template_field_lightboxes', array() ); |
1029
|
|
|
$lightboxes['none'] = __( 'None', 'foogallery' ); |
1030
|
|
|
return $lightboxes; |
1031
|
|
|
} |
1032
|
|
|
|
1033
|
|
|
|
1034
|
|
|
if ( !function_exists('wp_get_raw_referer') ) { |
1035
|
|
|
/** |
1036
|
|
|
* Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer. |
1037
|
|
|
* |
1038
|
|
|
* Do not use for redirects, use {@see wp_get_referer()} instead. |
1039
|
|
|
* |
1040
|
|
|
* @since 1.4.9 |
1041
|
|
|
* @return string|false Referer URL on success, false on failure. |
1042
|
|
|
*/ |
1043
|
|
|
function wp_get_raw_referer() { |
1044
|
|
|
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { |
1045
|
|
|
return wp_unslash( $_REQUEST['_wp_http_referer'] ); |
1046
|
|
|
} else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { |
1047
|
|
|
return wp_unslash( $_SERVER['HTTP_REFERER'] ); |
1048
|
|
|
} |
1049
|
|
|
|
1050
|
|
|
return false; |
1051
|
|
|
} |
1052
|
|
|
} |
1053
|
|
|
|
1054
|
|
|
/** |
1055
|
|
|
* Return the attachments for the currently displayed gallery |
1056
|
|
|
* |
1057
|
|
|
* @return array |
1058
|
|
|
*/ |
1059
|
|
|
function foogallery_current_gallery_attachments_for_rendering() { |
1060
|
|
|
global $current_foogallery; |
|
|
|
|
1061
|
|
|
|
1062
|
|
|
$attachments = apply_filters( 'foogallery_gallery_attachments_override_for_rendering', false, $current_foogallery ); |
1063
|
|
|
|
1064
|
|
|
if ( $attachments !== false) { |
1065
|
|
|
return $attachments; |
1066
|
|
|
} |
1067
|
|
|
|
1068
|
|
|
//by default, return all attachments |
1069
|
|
|
return $current_foogallery->attachments(); |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* Return attachment ID from a URL |
1074
|
|
|
* |
1075
|
|
|
* @param $url String URL to the image we are checking |
1076
|
|
|
* |
1077
|
|
|
* @return null or attachment ID |
1078
|
|
|
*/ |
1079
|
|
|
function foogallery_get_attachment_id_by_url($url) { |
1080
|
|
|
global $wpdb; |
|
|
|
|
1081
|
|
|
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid=%s"; |
1082
|
|
|
$attachment = $wpdb->get_col( $wpdb->prepare( $query, $url ) ); |
1083
|
|
|
if ( count( $attachment ) > 0 ) { |
1084
|
|
|
return $attachment[0]; |
1085
|
|
|
} |
1086
|
|
|
return null; |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
/** |
1090
|
|
|
* Safer escaping for HTML attributes. |
1091
|
|
|
* |
1092
|
|
|
* @since 1.4.31 |
1093
|
|
|
* |
1094
|
|
|
* @param string $text |
1095
|
|
|
* @return string |
1096
|
|
|
*/ |
1097
|
|
|
function foogallery_esc_attr( $text ) { |
1098
|
|
|
$safe_text = wp_check_invalid_utf8( $text ); |
1099
|
|
|
$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); |
1100
|
|
|
return $safe_text; |
1101
|
|
|
} |
1102
|
|
|
|
1103
|
|
|
|
1104
|
|
|
/** |
1105
|
|
|
* Create a FooGallery and return the ID |
1106
|
|
|
* |
1107
|
|
|
* @param $template |
1108
|
|
|
* @param $attachment_ids |
1109
|
|
|
* |
1110
|
|
|
* @return int |
1111
|
|
|
*/ |
1112
|
|
|
function foogallery_create_gallery( $template, $attachment_ids ) { |
1113
|
|
|
|
1114
|
|
|
if ( empty( $template ) ) { |
1115
|
|
|
$template = foogallery_default_gallery_template(); |
1116
|
|
|
} |
1117
|
|
|
|
1118
|
|
|
//create an empty foogallery |
1119
|
|
|
$foogallery_args = array( |
1120
|
|
|
'post_title' => 'Demo Gallery', |
1121
|
|
|
'post_type' => FOOGALLERY_CPT_GALLERY, |
1122
|
|
|
'post_status' => 'publish', |
1123
|
|
|
); |
1124
|
|
|
$gallery_id = wp_insert_post( $foogallery_args ); |
1125
|
|
|
|
1126
|
|
|
//set a gallery template |
1127
|
|
|
add_post_meta( $gallery_id, FOOGALLERY_META_TEMPLATE, $template, true ); |
1128
|
|
|
|
1129
|
|
|
$settings = array(); |
1130
|
|
|
|
1131
|
|
|
//set default settings if there are any, and also if the template is the same as the default |
1132
|
|
|
if ( foogallery_default_gallery_template() === $template ) { |
1133
|
|
|
$default_gallery_id = foogallery_get_setting( 'default_gallery_settings' ); |
1134
|
|
|
if ( $default_gallery_id ) { |
1135
|
|
|
$settings = get_post_meta( $default_gallery_id, FOOGALLERY_META_SETTINGS, true ); |
1136
|
|
|
add_post_meta( $this->foogallery_id, FOOGALLERY_META_SETTINGS, $settings, true ); |
|
|
|
|
1137
|
|
|
} |
1138
|
|
|
} |
1139
|
|
|
|
1140
|
|
|
if ( empty( $settings) ) { |
1141
|
|
|
switch ( $template ) { |
1142
|
|
|
case 'masonry': |
1143
|
|
|
$settings = array( |
1144
|
|
|
'foogallery_items_view' => 'preview', |
1145
|
|
|
'masonry_alignment' =>'fg-center', |
1146
|
|
|
'masonry_border_size' =>'fg-border-thin', |
1147
|
|
|
'masonry_caption_desc_source' =>'', |
1148
|
|
|
'masonry_caption_title_source' =>'', |
1149
|
|
|
'masonry_captions_limit_length' =>'', |
1150
|
|
|
'masonry_custom_settings' =>'', |
1151
|
|
|
'masonry_drop_shadow' =>'fg-shadow-outline', |
1152
|
|
|
'masonry_filtering_type' =>'', |
1153
|
|
|
'masonry_gutter_width' =>'10', |
1154
|
|
|
'masonry_hover_effect_caption_visibility' =>'fg-captions-bottom', |
1155
|
|
|
'masonry_hover_effect_color' =>'', |
1156
|
|
|
'masonry_hover_effect_icon' =>'fg-hover-zoom', |
1157
|
|
|
'masonry_hover_effect_preset' =>'fg-custom', |
1158
|
|
|
'masonry_hover_effect_scale' =>'', |
1159
|
|
|
'masonry_hover_effect_transition' =>'fg-hover-fade', |
1160
|
|
|
'masonry_inner_shadow' =>'', |
1161
|
|
|
'masonry_layout' =>'fixed', |
1162
|
|
|
'masonry_lazyload' =>'', |
1163
|
|
|
'masonry_lightbox' =>'foobox', |
1164
|
|
|
'masonry_loaded_effect' =>'fg-loaded-fade-in', |
1165
|
|
|
'masonry_loading_icon' =>'fg-loading-default', |
1166
|
|
|
'masonry_paging_type' =>'', |
1167
|
|
|
'masonry_rounded_corners' =>'', |
1168
|
|
|
'masonry_state' =>'no', |
1169
|
|
|
'masonry_theme' =>'fg-dark', |
1170
|
|
|
'masonry_thumbnail_link' =>'image', |
1171
|
|
|
'masonry_thumbnail_width' =>'250', |
1172
|
|
|
'masonry_video_autoplay' =>'yes', |
1173
|
|
|
'masonry_video_hover_icon' =>'fg-video-default', |
1174
|
|
|
'masonry_video_size' =>'640x360', |
1175
|
|
|
'masonry_video_sticky_icon' =>'', |
1176
|
|
|
); |
1177
|
|
|
} |
1178
|
|
|
} |
1179
|
|
|
|
1180
|
|
|
add_post_meta( $gallery_id, FOOGALLERY_META_SETTINGS, $settings, true ); |
1181
|
|
|
|
1182
|
|
|
$attachments = explode( ',', $attachment_ids ); |
1183
|
|
|
update_post_meta( $gallery_id, FOOGALLERY_META_ATTACHMENTS, $attachments ); |
1184
|
|
|
|
1185
|
|
|
return $gallery_id; |
1186
|
|
|
} |
1187
|
|
|
|
1188
|
|
|
|
1189
|
|
|
/** |
1190
|
|
|
* Returns an array of marketing demos |
1191
|
|
|
* @return array |
1192
|
|
|
*/ |
1193
|
|
|
function foogallery_marketing_demos() { |
1194
|
|
|
$demos = array(); |
1195
|
|
|
|
1196
|
|
|
$demos[] = array( |
1197
|
|
|
'demo' => __('Responsive Image Gallery', 'foogallery'), |
1198
|
|
|
'section' => __('Standard Gallery Demos', 'foogallery'), |
1199
|
|
|
'href' => 'https://foo.gallery/demos/responsive-image-gallery/' |
1200
|
|
|
); |
1201
|
|
|
$demos[] = array( |
1202
|
|
|
'demo' => __('Masonry Image Gallery', 'foogallery'), |
1203
|
|
|
'section' => __('Standard Gallery Demos', 'foogallery'), |
1204
|
|
|
'href' => 'https://foo.gallery/demos/masonry-image-gallery/' |
1205
|
|
|
); |
1206
|
|
|
$demos[] = array( |
1207
|
|
|
'demo' => __('Justified Gallery', 'foogallery'), |
1208
|
|
|
'section' => __('Standard Gallery Demos', 'foogallery'), |
1209
|
|
|
'href' => 'https://foo.gallery/demos/justified-gallery/' |
1210
|
|
|
); |
1211
|
|
|
$demos[] = array( |
1212
|
|
|
'demo' => __('Image Viewer Gallery', 'foogallery'), |
1213
|
|
|
'section' => __('Standard Gallery Demos', 'foogallery'), |
1214
|
|
|
'href' => 'https://foo.gallery/demos/image-viewer-gallery/' |
1215
|
|
|
); |
1216
|
|
|
$demos[] = array( |
1217
|
|
|
'demo' => __('Simple Portfolio Gallery', 'foogallery'), |
1218
|
|
|
'section' => __('Standard Gallery Demos', 'foogallery'), |
1219
|
|
|
'href' => 'https://foo.gallery/demos/simple-portfolio-demo/' |
1220
|
|
|
); |
1221
|
|
|
$demos[] = array( |
1222
|
|
|
'demo' => __('Single Thumbnail Gallery', 'foogallery'), |
1223
|
|
|
'section' => __('Standard Gallery Demos', 'foogallery'), |
1224
|
|
|
'href' => 'https://foo.gallery/demos/single-thumbnail-gallery/' |
1225
|
|
|
); |
1226
|
|
|
|
1227
|
|
|
$demos[] = array( |
1228
|
|
|
'demo' => __('Grid PRO Gallery', 'foogallery'), |
1229
|
|
|
'section' => __('PRO Gallery Demos', 'foogallery'), |
1230
|
|
|
'href' => 'https://foo.gallery/demos/grid-pro-demo/' |
1231
|
|
|
); |
1232
|
|
|
$demos[] = array( |
1233
|
|
|
'demo' => __('Polaroid PRO Gallery', 'foogallery'), |
1234
|
|
|
'section' => __('PRO Gallery Demos', 'foogallery'), |
1235
|
|
|
'href' => 'https://foo.gallery/demos/polaroid-pro-image-gallery/' |
1236
|
|
|
); |
1237
|
|
|
$demos[] = array( |
1238
|
|
|
'demo' => __('Slider PRO Gallery', 'foogallery'), |
1239
|
|
|
'section' => __('PRO Gallery Demos', 'foogallery'), |
1240
|
|
|
'href' => 'https://foo.gallery/demos/slider-pro/' |
1241
|
|
|
); |
1242
|
|
|
|
1243
|
|
|
$demos[] = array( |
1244
|
|
|
'demo' => __('Hover Presets Demo', 'foogallery'), |
1245
|
|
|
'section' => __('PRO Features', 'foogallery'), |
1246
|
|
|
'href' => 'https://foo.gallery/demos/hover-effect-presets-demos/' |
1247
|
|
|
); |
1248
|
|
|
$demos[] = array( |
1249
|
|
|
'demo' => __('Filtering Demos', 'foogallery'), |
1250
|
|
|
'section' => __('PRO Features', 'foogallery'), |
1251
|
|
|
'href' => 'https://foo.gallery/demos/filtering-demos/' |
1252
|
|
|
); |
1253
|
|
|
$demos[] = array( |
1254
|
|
|
'demo' => __('Pagination Types Demo', 'foogallery'), |
1255
|
|
|
'section' => __('PRO Features', 'foogallery'), |
1256
|
|
|
'href' => 'https://foo.gallery/demos/pagination-demo/' |
1257
|
|
|
); |
1258
|
|
|
$demos[] = array( |
1259
|
|
|
'demo' => __('Video Gallery Demos', 'foogallery'), |
1260
|
|
|
'section' => __('PRO Features', 'foogallery'), |
1261
|
|
|
'href' => 'https://foo.gallery/demos/video-gallery-demos/' |
1262
|
|
|
); |
1263
|
|
|
$demos[] = array( |
1264
|
|
|
'demo' => __('Loaded Effect Demos', 'foogallery'), |
1265
|
|
|
'section' => __('PRO Features', 'foogallery'), |
1266
|
|
|
'href' => 'https://foo.gallery/demos/loaded-effect-demos/' |
1267
|
|
|
); |
1268
|
|
|
$demos[] = array( |
1269
|
|
|
'demo' => __('Bulk Copy (admin)', 'foogallery'), |
1270
|
|
|
'section' => __('PRO Features', 'foogallery'), |
1271
|
|
|
'href' => 'https://fooplugins.com/bulk-copy-foogallery-pro/' |
1272
|
|
|
); |
1273
|
|
|
|
1274
|
|
|
$demos[] = array( |
1275
|
|
|
'demo' => __('Responsive Album', 'foogallery'), |
1276
|
|
|
'section' => __('Album Demos', 'foogallery'), |
1277
|
|
|
'href' => 'https://foo.gallery/demos/responsive-album-layout/' |
1278
|
|
|
); |
1279
|
|
|
$demos[] = array( |
1280
|
|
|
'demo' => __('All-In-One Stack Album', 'foogallery'), |
1281
|
|
|
'section' => __('Album Demos', 'foogallery'), |
1282
|
|
|
'href' => 'https://foo.gallery/demos/all-in-one-stack-album/' |
1283
|
|
|
); |
1284
|
|
|
|
1285
|
|
|
$demos[] = array( |
1286
|
|
|
'demo' => __('Captions Demos', 'foogallery'), |
1287
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1288
|
|
|
'href' => 'https://foo.gallery/demos/captions-demos/' |
1289
|
|
|
); |
1290
|
|
|
$demos[] = array( |
1291
|
|
|
'demo' => __('Slider PRO Variations', 'foogallery'), |
1292
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1293
|
|
|
'href' => 'https://foo.gallery/demos/slider-pro-variations/' |
1294
|
|
|
); |
1295
|
|
|
$demos[] = array( |
1296
|
|
|
'demo' => __('Masonry + Filtering', 'foogallery'), |
1297
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1298
|
|
|
'href' => 'https://foo.gallery/demos/masonry-filtering/' |
1299
|
|
|
); |
1300
|
|
|
$demos[] = array( |
1301
|
|
|
'demo' => __('Load More + Filtering', 'foogallery'), |
1302
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1303
|
|
|
'href' => 'https://foo.gallery/demos/paging-load-more-filtering/' |
1304
|
|
|
); |
1305
|
|
|
$demos[] = array( |
1306
|
|
|
'demo' => __('Mixed (Images + Videos)', 'foogallery'), |
1307
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1308
|
|
|
'href' => 'https://foo.gallery/demos/mixed/' |
1309
|
|
|
); |
1310
|
|
|
$demos[] = array( |
1311
|
|
|
'demo' => __('HTML Captions Demo', 'foogallery'), |
1312
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1313
|
|
|
'href' => 'https://foo.gallery/demos/html-captions-demo/' |
1314
|
|
|
); |
1315
|
|
|
$demos[] = array( |
1316
|
|
|
'demo' => __('Infinite Scroll Demo', 'foogallery'), |
1317
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1318
|
|
|
'href' => 'https://foo.gallery/demos/infinite-scroll-demo/' |
1319
|
|
|
); |
1320
|
|
|
$demos[] = array( |
1321
|
|
|
'demo' => __('Videos From All Sources', 'foogallery'), |
1322
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1323
|
|
|
'href' => 'https://foo.gallery/demos/videos-from-all-sources/' |
1324
|
|
|
); |
1325
|
|
|
$demos[] = array( |
1326
|
|
|
'demo' => __('Videos + Filters', 'foogallery'), |
1327
|
|
|
'section' => __('Other Demos', 'foogallery'), |
1328
|
|
|
'href' => 'https://foo.gallery/demos/videos-filters/' |
1329
|
|
|
); |
1330
|
|
|
|
1331
|
|
|
return $demos; |
1332
|
|
|
} |
1333
|
|
|
|
1334
|
|
|
|
1335
|
|
|
/** |
1336
|
|
|
* Returns an array of the PRO features |
1337
|
|
|
* @return array |
1338
|
|
|
*/ |
1339
|
|
|
function foogallery_marketing_pro_features() { |
1340
|
|
|
$features[] = array( |
|
|
|
|
1341
|
|
|
'feature' => __( 'Video Galleries', 'foogallery' ), |
1342
|
|
|
'desc' => __( 'Create beautiful video galleries from YouTube, Vimeo, Facebook, Wistia and more!', 'foogallery' ), |
1343
|
|
|
'demo' => 'https://foo.gallery/demos/video-gallery-demos/' |
1344
|
|
|
); |
1345
|
|
|
$features[] = array( |
1346
|
|
|
'feature' => __( 'Media Tags + Filtering', 'foogallery' ), |
1347
|
|
|
'desc' => __( 'Assign tags to your media, which allows visitors to filter the galleries by tag.', 'foogallery' ), |
1348
|
|
|
'demo' => 'https://foo.gallery/demos/filtering-demos/' |
1349
|
|
|
); |
1350
|
|
|
$features[] = array( |
1351
|
|
|
'feature' => __( 'More Gallery Templates', 'foogallery' ), |
1352
|
|
|
'desc' => __( '3 more awesome gallery templates, including Slider, Grid and Polaroid.', 'foogallery' ), |
1353
|
|
|
'demo' => 'https://foo.gallery/demos/slider-pro/' |
1354
|
|
|
); |
1355
|
|
|
$features[] = array( |
1356
|
|
|
'feature' => __( 'Preset Hover Effects', 'foogallery' ), |
1357
|
|
|
'desc' => __( 'Choose from 11 beautifully designed preset hover effects.', 'foogallery' ), |
1358
|
|
|
'demo' => 'https://foo.gallery/demos/hover-effect-presets-demos/' |
1359
|
|
|
); |
1360
|
|
|
$features[] = array( |
1361
|
|
|
'feature' => __( 'Advanced Pagination + Infinite Scroll', 'foogallery' ), |
1362
|
|
|
'desc' => __( 'Choose from more paging types like numbered, load more or infinite scroll.', 'foogallery' ), |
1363
|
|
|
'demo' => 'https://foo.gallery/demos/pagination-demo/' |
1364
|
|
|
); |
1365
|
|
|
$features[] = array( |
1366
|
|
|
'feature' => __( 'Animated Loading Effects', 'foogallery' ), |
1367
|
|
|
'desc' => __( 'Choose from 9 awesome animation effects to display as your galleries load.', 'foogallery' ), |
1368
|
|
|
'demo' => 'https://foo.gallery/demos/loaded-effect-demos/' |
1369
|
|
|
); |
1370
|
|
|
$features[] = array( |
1371
|
|
|
'feature' => __( 'Bulk Copy Settings', 'foogallery' ), |
1372
|
|
|
'desc' => __( 'Bulk copy your gallery settings to other galleries in a flash.', 'foogallery' ), |
1373
|
|
|
'demo' => 'https://fooplugins.com/bulk-copy-foogallery-pro/' |
1374
|
|
|
); |
1375
|
|
|
return $features; |
1376
|
|
|
} |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state