GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( c721e5...0f0dc5 )
by Brad
03:00
created

FooGallery_Upgrade_Helper   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 696
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 696
rs 9.7482
c 0
b 0
f 0
wmc 18
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A perform_gallery_settings_upgrade() 0 22 2
D build_new_settings() 0 670 16
1
<?php
2
/**
3
 * Class used to upgrade internal gallery settings when needed
4
 * Date: 19/07/2017
5
 */
6
if ( ! class_exists( 'FooGallery_Upgrade' ) ) {
7
8
	class FooGallery_Upgrade {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
		function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
			//add_action( 'foogallery_admin_new_version_detected', array( $this, 'upgrade_all_galleries' ) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
12
			add_filter( 'foogallery_settings_upgrade', array( $this, 'upgrade_gallery_settings' ), 10, 2 );
13
14
			add_filter( 'foogallery_admin_settings_override', array( $this, 'add_force_upgrade_setting' ) );
15
			add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_force_upgrades_settings' ) );
16
			add_action( 'wp_ajax_foogallery_force_upgrade', array( $this, 'ajax_force_upgrade' ) );
17
18
			add_action( 'add_meta_boxes_' . FOOGALLERY_CPT_GALLERY, array( $this, 'add_meta_boxes_to_gallery' ) );
19
		}
20
21
		public function upgrade_gallery_settings( $settings, $foogallery ) {
22
			$old_settings = get_post_meta( $foogallery->ID, FOOGALLERY_META_SETTINGS_OLD, true );
23
24
			//we have old settings - so upgrade them!!!
25
			if ( !empty( $old_settings ) ) {
26
				$upgrade_helper = new FooGallery_Upgrade_Helper();
27
				$settings = $upgrade_helper->perform_gallery_settings_upgrade( $foogallery );
28
			}
29
30
			return $settings;
31
		}
32
33
		public function add_meta_boxes_to_gallery( $post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
35
			if ( foogallery_get_setting( 'enable_debugging' ) ) {
36
				add_meta_box(
37
					'foogallery_upgrade_debug',
38
					__( 'Settings Upgrade Debugging', 'foogallery' ),
39
					array( $this, 'render_upgrade_debug_metabox' ),
40
					FOOGALLERY_CPT_GALLERY,
41
					'normal',
42
					'low'
43
				);
44
			}
45
		}
46
47
		public function render_upgrade_debug_metabox( $post ) {
48
			$gallery = FooGallery::get( $post );
49
50
			if ( $gallery->is_new() ) {
51
				return;
52
			}
53
54
			$old_settings = get_post_meta( $gallery->ID, FOOGALLERY_META_SETTINGS_OLD, true );
55
			$new_settings = $gallery->settings; // get_post_meta( $gallery->ID, FOOGALLERY_META_SETTINGS, true );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
			$upgrade_helper = new FooGallery_Upgrade_Helper();
57
			$upgrade_settings = $upgrade_helper->build_new_settings( $gallery );
58
59
			if ( is_array( $old_settings ) ) { ksort( $old_settings ); }
60
            if ( is_array( $new_settings ) ) { ksort( $new_settings ); }
61
            if ( is_array( $upgrade_settings ) ) { ksort( $upgrade_settings ); }
62
			?>
63
			<style>
64
				#foogallery_upgrade_debug .inside { overflow: scroll; }
65
				#foogallery_upgrade_debug table { font-size: 0.8em; }
66
				#foogallery_upgrade_debug td { vertical-align: top; }
67
			</style>
68
			<table>
69
				<tr>
70
					<td><h3>Old Settings</h3></td>
71
					<td><h3>New Settings</h3></td>
72
					<td><h3>Upgrade Settings</h3></td>
73
				</tr>
74
				<tr>
75
					<td><?php var_dump( $old_settings ); ?></td>
1 ignored issue
show
Security Debugging Code introduced by
var_dump($old_settings); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
76
					<td><?php var_dump( $new_settings ); ?></td>
77
					<td><?php var_dump( $upgrade_settings ); ?></td>
78
				</tr>
79
			</table>
80
			<?php
81
		}
82
83
		function ajax_force_upgrade() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
84
			if ( check_admin_referer( 'foogallery_force_upgrade' ) && current_user_can( 'install_plugins' ) ) {
85
86
				//clear any and all previous upgrades!
87
				delete_post_meta_by_key( '_foogallery_settings' );
88
				$this->upgrade_all_galleries();
89
90
				_e('The BETA upgrade process has been run!', 'foogallery' );
91
				die();
92
			}
93
		}
94
95
		function add_force_upgrade_setting( $settings ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
96
			$settings['settings'][] = array(
97
				'id'      => 'force_upgrade',
98
				'title'   => __( 'Force Upgrade', 'foogallery' ),
99
				'desc'    => sprintf( __( 'Force the BETA upgrade process to run. This may sometimes be needed if the upgrade did not run automatically. Any changes you have made to galleries after updating will be lost. THERE IS NO UNDO.', 'foogallery' ), foogallery_plugin_name() ),
100
				'type'    => 'force_upgrade',
101
				'tab'     => 'advanced'
102
			);
103
104
			return $settings;
105
		}
106
107
		function render_force_upgrades_settings( $args ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
108
			if ( 'force_upgrade' === $args['type'] ) { ?>
109
				<div class="foogallery_settings_ajax_container">
110
					<input type="button" data-action="foogallery_force_upgrade" data-confirm="<?php _e('Are you sure? Any changes you have made since updating will be lost. There is no undo!', 'foogallery'); ?>" data-response="replace_container" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_force_upgrade' ) ); ?>" class="button-primary foogallery_settings_ajax foogallery_force_upgrade" value="<?php _e( 'Run Upgrade Process', 'foogallery' ); ?>">
111
					<span style="position: absolute" class="spinner"></span>
112
				</div>
113
			<?php }
114
		}
115
116
		function upgrade_all_galleries() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
117
			$galleries = foogallery_get_all_galleries();
118
119
			foreach ( $galleries as $gallery ) {
120
				$new_settings = get_post_meta( $gallery->ID, FOOGALLERY_META_SETTINGS, true );
121
				$old_settings = get_post_meta( $gallery->ID, FOOGALLERY_META_SETTINGS_OLD, true );
122
123
				//only upgrade galleries that need to be
124
				if ( !is_array($new_settings) && is_array($old_settings) ) {
125
					$upgrade_helper = new FooGallery_Upgrade_Helper();
126
					$upgrade_helper->perform_gallery_settings_upgrade( $gallery );
127
				}
128
			}
129
		}
130
	}
131
}
132
133
if ( ! class_exists( 'FooGallery_Upgrade_Helper' ) ) {
134
135
	class FooGallery_Upgrade_Helper {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
136
137
		function perform_gallery_settings_upgrade( $foogallery ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
138
			//build up the new settings
139
			$new_settings = $this->build_new_settings( $foogallery );
140
141
			if ( !empty( $new_settings ) ) {
142
143
                //save the new settings
144
                add_post_meta($foogallery->ID, FOOGALLERY_META_SETTINGS, $new_settings, true);
145
146
                //clear any cache that may be saved for the gallery
147
                delete_post_meta($foogallery->ID, FOOGALLERY_META_CACHE);
148
149
                //clear any previously calculated thumb dimensions
150
                delete_post_meta($foogallery->ID, FOOGALLERY_META_THUMB_DIMENSIONS);
151
152
                //calculate new thumb dimensions if needed
153
                $thumb_dimensions = new FooGallery_Thumbnail_Dimensions();
154
                $thumb_dimensions->calculate_thumbnail_dimensions($foogallery->ID);
155
            }
156
157
			return $new_settings;
158
		}
159
160
		function build_new_settings( $foogallery ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
161
			$mappings = array(
162
				array(
163
					'id' => 'border-style',
164
					'value' => 'border-style-square-white',
165
					'new' => array(
166
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
167
						array ( 'id' => 'border_size', 'value' => 'fg-border-thin' ),
168
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
169
						array ( 'id' => 'rounded_corners', 'value' => '' ),
170
						array ( 'id' => 'inner_shadow', 'value' => '' ),
171
					)
172
				),
173
				array(
174
					'id' => 'border-style',
175
					'value' => 'border-style-circle-white',
176
					'new' => array(
177
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
178
						array ( 'id' => 'border_size', 'value' => 'fg-border-thin' ),
179
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
180
						array ( 'id' => 'rounded_corners', 'value' => 'fg-round-full' ),
181
						array ( 'id' => 'inner_shadow', 'value' => '' ),
182
					)
183
				),
184
				array(
185
					'id' => 'border-style',
186
					'value' => 'border-style-square-black',
187
					'new' => array(
188
						array ( 'id' => 'theme', 'value' => 'fg-dark' ),
189
						array ( 'id' => 'border_size', 'value' => 'fg-border-thin' ),
190
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
191
						array ( 'id' => 'rounded_corners', 'value' => '' ),
192
						array ( 'id' => 'inner_shadow', 'value' => '' ),
193
					)
194
				),
195
				array(
196
					'id' => 'border-style',
197
					'value' => 'border-style-circle-black',
198
					'new' => array(
199
						array ( 'id' => 'theme', 'value' => 'fg-dark' ),
200
						array ( 'id' => 'border_size', 'value' => 'fg-border-thin' ),
201
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
202
						array ( 'id' => 'rounded_corners', 'value' => 'fg-round-full' ),
203
						array ( 'id' => 'inner_shadow', 'value' => '' ),
204
					)
205
				),
206
				array(
207
					'id' => 'border-style',
208
					'value' => 'border-style-inset',
209
					'new' => array(
210
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
211
						array ( 'id' => 'border_size', 'value' => '' ),
212
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
213
						array ( 'id' => 'rounded_corners', 'value' => '' ),
214
						array ( 'id' => 'inner_shadow', 'value' => 'fg-shadow-inset-large' ),
215
					)
216
				),
217
				array(
218
					'id' => 'border-style',
219
					'value' => 'border-style-rounded',
220
					'new' => array(
221
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
222
						array ( 'id' => 'border_size', 'value' => '' ),
223
						array ( 'id' => 'drop_shadow', 'value' => '' ),
224
						array ( 'id' => 'rounded_corners', 'value' => 'fg-round-small' ),
225
						array ( 'id' => 'inner_shadow', 'value' => '' ),
226
					)
227
				),
228
				array(
229
					'id' => 'border-style',
230
					'value' => '',
231
					'new' => array(
232
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
233
						array ( 'id' => 'border_size', 'value' => '' ),
234
						array ( 'id' => 'drop_shadow', 'value' => '' ),
235
						array ( 'id' => 'rounded_corners', 'value' => '' ),
236
						array ( 'id' => 'inner_shadow', 'value' => '' ),
237
					)
238
				),
239
240
				array(
241
					'id' => 'spacing',
242
					'value' => 'spacing-width-0',
243
					'new' => array(
244
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-0' )
245
					)
246
				),
247
				array(
248
					'id' => 'spacing',
249
					'value' => 'spacing-width-5',
250
					'new' => array(
251
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-5' )
252
					)
253
				),
254
				array(
255
					'id' => 'spacing',
256
					'value' => 'spacing-width-10',
257
					'new' => array(
258
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-10' )
259
					)
260
				),
261
				array(
262
					'id' => 'spacing',
263
					'value' => 'spacing-width-15',
264
					'new' => array(
265
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-15' )
266
					)
267
				),
268
				array(
269
					'id' => 'spacing',
270
					'value' => 'spacing-width-20',
271
					'new' => array(
272
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-20' )
273
					)
274
				),
275
				array(
276
					'id' => 'spacing',
277
					'value' => 'spacing-width-25',
278
					'new' => array(
279
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-25' )
280
					)
281
				),
282
283
				array(
284
					'id' => 'alignment',
285
					'value' => 'alignment-left',
286
					'new' => array(
287
						array ( 'id' => 'alignment', 'value' => 'fg-left' )
288
					)
289
				),
290
				array(
291
					'id' => 'alignment',
292
					'value' => 'alignment-center',
293
					'new' => array(
294
						array ( 'id' => 'alignment', 'value' => 'fg-center' )
295
					)
296
				),
297
				array(
298
					'id' => 'alignment',
299
					'value' => 'alignment-right',
300
					'new' => array(
301
						array ( 'id' => 'alignment', 'value' => 'fg-right' )
302
					)
303
				),
304
305
				array(
306
					'id' => 'loading_animation',
307
					'value' => 'yes',
308
					'new' => array(
309
						array ( 'id' => 'loading_icon', 'value' => 'fg-loading-default' )
310
					)
311
				),
312
				array(
313
					'id' => 'loading_animation',
314
					'value' => 'no',
315
					'new' => array(
316
						array ( 'id' => 'loading_icon', 'value' => 'fg-loading-none' )
317
					)
318
				),
319
320
                //Icon hover effects
321
				array(
322
					'id' => 'hover-effect-type',
323
					'value' => '', //Icon
324
					'new' => array(
325
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
326
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => '' ),
327
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
328
						array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-zoom' ),
329
						array ( 'id' => 'caption_title_source', 'value' => 'none' ),
330
						array ( 'id' => 'caption_desc_source', 'value' => 'none' )
331
					)
332
				),
333
334
                array(
335
                    'id' => 'hover-effect',
336
                    'value' => 'hover-effect-zoom',
337
                    'preconditions' => array (
338
                        array ( 'id' => 'hover-effect-type', 'value' => '' ),
339
                    ),
340
                    'new' => array(
341
                        array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-zoom' )
342
                    )
343
                ),
344
345
                array(
346
                    'id' => 'hover-effect',
347
                    'value' => 'hover-effect-zoom2',
348
                    'preconditions' => array (
349
                        array ( 'id' => 'hover-effect-type', 'value' => '' ),
350
                    ),
351
                    'new' => array(
352
                        array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-zoom2' )
353
                    )
354
                ),
355
356
                array(
357
                    'id' => 'hover-effect',
358
                    'value' => 'hover-effect-zoom3',
359
                    'preconditions' => array (
360
                        array ( 'id' => 'hover-effect-type', 'value' => '' ),
361
                    ),
362
                    'new' => array(
363
                        array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-zoom3' )
364
                    )
365
                ),
366
367
                array(
368
                    'id' => 'hover-effect',
369
                    'value' => 'hover-effect-plus',
370
                    'preconditions' => array (
371
                        array ( 'id' => 'hover-effect-type', 'value' => '' ),
372
                    ),
373
                    'new' => array(
374
                        array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-plus' )
375
                    )
376
                ),
377
378
                array(
379
                    'id' => 'hover-effect',
380
                    'value' => 'hover-effect-circle-plus',
381
                    'preconditions' => array (
382
                        array ( 'id' => 'hover-effect-type', 'value' => '' ),
383
                    ),
384
                    'new' => array(
385
                        array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-circle-plus' )
386
                    )
387
                ),
388
389
                array(
390
                    'id' => 'hover-effect',
391
                    'value' => 'hover-effect-eye',
392
                    'preconditions' => array (
393
                        array ( 'id' => 'hover-effect-type', 'value' => '' ),
394
                    ),
395
                    'new' => array(
396
                        array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-eye' )
397
                    )
398
                ),
399
400
                array(
401
					'id' => 'hover-effect-type',
402
					'value' => 'hover-effect-tint', //Dark Tint
403
					'new' => array(
404
						array ( 'id' => 'hover_effect_preset', 'value' => '' ),
405
						array ( 'id' => 'hover_effect', 'value' => 'fg-hover-tint' ),
406
                        array ( 'id' => 'hover_effect_caption_visibility', 'value' => '' ),
407
					)
408
				),
409
410
				array(
411
					'id' => 'hover-effect-type',
412
					'value' => 'hover-effect-color', //Colorize
413
					'new' => array(
414
						array ( 'id' => 'hover_effect_preset', 'value' => '' ),
415
						array ( 'id' => 'hover_effect_color', 'value' => 'fg-hover-colorize' ),
416
                        array ( 'id' => 'hover_effect_icon', 'value' => '' ),
417
                        array ( 'id' => 'hover_effect_caption_visibility', 'value' => '' ),
418
					)
419
				),
420
421
				array(
422
					'id' => 'hover-effect-type',
423
					'value' => 'hover-effect-none', //None
424
					'new' => array(
425
						array ( 'id' => 'hover_effect_preset', 'value' => '' ),
426
                        array ( 'id' => 'hover_effect_icon', 'value' => '' ),
427
                        array ( 'id' => 'hover_effect_caption_visibility', 'value' => '' ),
428
					)
429
				),
430
431
				array(
432
					'id' => 'hover-effect-type',
433
					'value' => 'hover-effect-caption', //Caption
434
					'new' => array(
435
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
436
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
437
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
438
                        array ( 'id' => 'hover_effect_icon', 'value' => '' )
439
					)
440
				),
441
442
				array(
443
					'id' => 'caption-hover-effect',
444
					'value' => 'hover-caption-simple',
445
                    'preconditions' => array (
446
                        array ( 'id' => 'hover-effect-type', 'value' => 'hover-effect-caption' ),
447
                    ),
448
					'new' => array(
449
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
450
					)
451
				),
452
				array(
453
					'id' => 'caption-hover-effect',
454
					'value' => 'hover-caption-full-drop',
455
                    'preconditions' => array (
456
                        array ( 'id' => 'hover-effect-type', 'value' => 'hover-effect-caption' ),
457
                    ),
458
					'new' => array(
459
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-slide-down' ),
460
					)
461
				),
462
				array(
463
					'id' => 'caption-hover-effect',
464
					'value' => 'hover-caption-full-fade',
465
                    'preconditions' => array (
466
                        array ( 'id' => 'hover-effect-type', 'value' => 'hover-effect-caption' ),
467
                    ),
468
					'new' => array(
469
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
470
					)
471
				),
472
				array(
473
					'id' => 'caption-hover-effect',
474
					'value' => 'hover-caption-push',
475
                    'preconditions' => array (
476
                        array ( 'id' => 'hover-effect-type', 'value' => 'hover-effect-caption' ),
477
                    ),
478
					'new' => array(
479
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-push' ),
480
					)
481
				),
482
				array(
483
					'id' => 'caption-hover-effect',
484
					'value' => 'hover-caption-simple-always',
485
                    'preconditions' => array (
486
                        array ( 'id' => 'hover-effect-type', 'value' => 'hover-effect-caption' ),
487
                    ),
488
					'new' => array(
489
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-always' ),
490
					)
491
				),
492
493
				array(
494
					'id' => 'caption-content',
495
					'value' => 'title',
496
					'new' => array(
497
						array ( 'id' => 'caption_title_source', 'value' => '' ),
498
						array ( 'id' => 'caption_desc_source', 'value' => 'none' )
499
					)
500
				),
501
				array(
502
					'id' => 'caption-content',
503
					'value' => 'desc',
504
					'new' => array(
505
						array ( 'id' => 'caption_title_source', 'value' => 'none' ),
506
						array ( 'id' => 'caption_desc_source', 'value' => '' )
507
					)
508
				),
509
				array(
510
					'id' => 'caption-content',
511
					'value' => 'both',
512
					'new' => array(
513
						array ( 'id' => 'caption_title_source', 'value' => '' ),
514
						array ( 'id' => 'caption_desc_source', 'value' => '' )
515
					)
516
				),
517
518
				//masonry layout mappings
519
				array(
520
					'id' => 'layout',
521
					'value' => '2col',
522
					'new' => array(
523
						array ( 'id' => 'layout', 'value' => 'col2' )
524
					)
525
				),
526
527
				array(
528
					'id' => 'layout',
529
					'value' => '3col',
530
					'new' => array(
531
						array ( 'id' => 'layout', 'value' => 'col3' )
532
					)
533
				),
534
535
				array(
536
					'id' => 'layout',
537
					'value' => '4col',
538
					'new' => array(
539
						array ( 'id' => 'layout', 'value' => 'col4' )
540
					)
541
				),
542
543
				array(
544
					'id' => 'layout',
545
					'value' => '5col',
546
					'new' => array(
547
						array ( 'id' => 'layout', 'value' => 'col5' )
548
					)
549
				),
550
551
				array(
552
					'id' => 'gutter_percent',
553
					'value' => 'no-gutter',
554
					'new' => array(
555
						array ( 'id' => 'gutter_percent', 'value' => 'fg-gutter-none' )
556
					)
557
				),
558
559
				array(
560
					'id' => 'gutter_percent',
561
					'value' => 'large-gutter',
562
					'new' => array(
563
						array ( 'id' => 'gutter_percent', 'value' => 'fg-gutter-large' )
564
					)
565
				),
566
567
				array(
568
					'id' => 'center_align',
569
					'value' => 'default',
570
					'new' => array(
571
						array ( 'id' => 'alignment', 'value' => '' )
572
					)
573
				),
574
575
				array(
576
					'id' => 'center_align',
577
					'value' => 'center',
578
					'new' => array(
579
						array ( 'id' => 'alignment', 'value' => 'fg-center' )
580
					)
581
				),
582
583
				array(
584
					'id' => 'hover_zoom',
585
					'value' => 'default',
586
					'new' => array(
587
						array ( 'id' => 'hover_effect_scale', 'value' => 'fg-hover-scale' )
588
					)
589
				),
590
591
				array(
592
					'id' => 'hover_zoom',
593
					'value' => 'none',
594
					'new' => array(
595
						array ( 'id' => 'hover_effect_scale', 'value' => '' )
596
					)
597
				),
598
599
600
				//image viewer upgrades
601
				array(
602
					'id' => 'theme',
603
					'value' => 'fiv-dark',
604
					'new' => array(
605
						array ( 'id' => 'theme', 'value' => 'fg-dark' )
606
					)
607
				),
608
				array(
609
					'id' => 'theme',
610
					'value' => '',
611
					'new' => array(
612
						array ( 'id' => 'theme', 'value' => 'fg-light' )
613
					)
614
				),
615
				array(
616
					'id' => 'theme',
617
					'value' => 'fiv-custom',
618
					'new' => array(
619
						array ( 'id' => 'theme', 'value' => 'fg-light' )
620
					)
621
				),
622
623
				array(
624
					'id' => 'alignment',
625
					'value' => 'alignment-left',
626
					'new' => array(
627
						array ( 'id' => 'alignment', 'value' => 'fg-left' )
628
					)
629
				),
630
				array(
631
					'id' => 'alignment',
632
					'value' => 'alignment-center',
633
					'new' => array(
634
						array ( 'id' => 'alignment', 'value' => 'fg-center' )
635
					)
636
				),
637
				array(
638
					'id' => 'alignment',
639
					'value' => 'alignment-right',
640
					'new' => array(
641
						array ( 'id' => 'alignment', 'value' => 'fg-right' )
642
					)
643
				),
644
645
				//simple portfolio
646
				array(
647
					'id' => 'caption_position',
648
					'value' => 'bf-captions-above',
649
					'new' => array(
650
						array ( 'id' => 'caption_position', 'value' => 'fg-captions-top' )
651
					)
652
				),
653
654
				//single thumbnail
655
				array(
656
					'id' => 'caption_style',
657
					'value' => 'caption-simple',
658
					'new' => array(
659
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
660
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-always' )
661
					)
662
				),
663
				array(
664
					'id' => 'caption_style',
665
					'value' => 'caption-slideup',
666
					'new' => array(
667
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
668
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
669
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-slide-up' ),
670
					)
671
				),
672
673
				array(
674
					'id' => 'caption_style',
675
					'value' => 'caption-fall',
676
					'new' => array(
677
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
678
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
679
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-slide-down' ),
680
					)
681
				),
682
				array(
683
					'id' => 'caption_style',
684
					'value' => 'caption-fade',
685
					'new' => array(
686
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
687
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
688
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
689
					)
690
				),
691
				array(
692
					'id' => 'caption_style',
693
					'value' => 'caption-push',
694
					'new' => array(
695
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
696
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
697
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-push' ),
698
					)
699
				),
700
				array(
701
					'id' => 'caption_style',
702
					'value' => 'caption-scale',
703
					'new' => array(
704
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
705
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
706
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-slide-left' ),
707
					)
708
				),
709
710
				//single thumbnail gallery
711
				array(
712
					'id' => 'position',
713
					'value' => 'position-block',
714
					'new' => array(
715
						array ( 'id' => 'position', 'value' => 'fg-center' ),
716
					)
717
				),
718
				array(
719
					'id' => 'position',
720
					'value' => 'position-float-left',
721
					'new' => array(
722
						array ( 'id' => 'position', 'value' => 'fg-left' ),
723
					)
724
				),
725
				array(
726
					'id' => 'position',
727
					'value' => 'position-float-right',
728
					'new' => array(
729
						array ( 'id' => 'position', 'value' => 'fg-right' ),
730
					)
731
				),
732
733
			);
734
735
			$old_settings = get_post_meta( $foogallery->ID, FOOGALLERY_META_SETTINGS_OLD, true );
736
737
			if ( empty( $old_settings ) ) {
738
			    return $old_settings;
739
            }
740
741
			//start with the old settings
742
			$new_settings = $old_settings;
743
744
			//upgrade all template settings
745
			foreach ( foogallery_gallery_templates() as $template ) {
746
747
				foreach ( $mappings as $mapping ) {
748
749
					$settings_key = "{$template['slug']}_{$mapping['id']}";
750
751
					//check if the settings exists
752
					if ( array_key_exists( $settings_key, $old_settings ) ) {
753
754
						$old_settings_value = $old_settings[$settings_key];
755
756
						if ( $mapping['value'] === $old_settings_value ) {
757
							//we have found a match!
758
759
                            $add_settings = true;
760
761
                            //check if we have any preconditions
762
                            if ( isset( $mapping['preconditions'] ) ) {
763
                                $add_settings = false;
764
                                foreach ($mapping['preconditions'] as $precondition) {
765
                                    $precondition_setting_key = "{$template['slug']}_{$precondition['id']}";
766
                                    $precondition_setting_value = $precondition['value'];
767
768
                                    if ( array_key_exists( $precondition_setting_key, $old_settings ) &&
769
                                        $precondition_setting_value === $old_settings[$precondition_setting_key] ) {
770
                                        //we have found a precondition match
771
                                        $add_settings = true;
772
                                    }
773
                                }
774
                            }
775
776
                            if ( $add_settings ) {
777
                                foreach ($mapping['new'] as $setting_to_create) {
778
                                    $new_setting_key = "{$template['slug']}_{$setting_to_create['id']}";
779
                                    $new_setting_value = $setting_to_create['value'];
780
                                    $new_settings[$new_setting_key] = $new_setting_value;
781
                                }
782
                            }
783
						}
784
					}
785
				}
786
			}
787
788
			//template specific settings overrides
789
			if ( 'image-viewer' === $foogallery->gallery_template ) {
790
				$new_settings['image-viewer_border_size'] = 'fg-border-thin';
791
				$new_settings['image-viewer_drop_shadow'] = 'fg-shadow-outline';
792
				$new_settings['image-viewer_rounded_corners'] = '';
793
				$new_settings['image-viewer_inner_shadow'] = '';
794
                $new_settings['image-viewer_hover_effect_caption_visibility'] = 'fg-caption-always';
795
			}
796
797
			if ( 'justified' === $foogallery->gallery_template ) {
798
				$new_settings['justified_theme'] = 'fg-light';
799
				$new_settings['justified_border_size'] = '';
800
				$new_settings['justified_drop_shadow'] = '';
801
				$new_settings['justified_rounded_corners'] = '';
802
				$new_settings['justified_inner_shadow'] = '';
803
                $new_settings['justified_hover_effect_preset'] = 'fg-custom';
804
                $new_settings['justified_hover_effect_icon'] = '';
805
                $new_settings['justified_hover_effect_caption_visibility'] = '';
806
			}
807
808
			if ( 'masonry' === $foogallery->gallery_template ) {
809
				$new_settings['masonry_theme'] = 'fg-light';
810
				$new_settings['masonry_border_size'] = '';
811
				$new_settings['masonry_drop_shadow'] = '';
812
				$new_settings['masonry_rounded_corners'] = '';
813
				$new_settings['masonry_inner_shadow'] = '';
814
                $new_settings['masonry_hover_effect_preset'] = 'fg-custom';
815
                $new_settings['masonry_hover_effect_icon'] = '';
816
                $new_settings['masonry_hover_effect_caption_visibility'] = '';
817
			}
818
819
            if ( 'simple_portfolio' === $foogallery->gallery_template ) {
820
                $new_settings['simple_portfolio_theme'] = 'fg-light';
821
                $new_settings['simple_portfolio_border_size'] = '';
822
                $new_settings['simple_portfolio_drop_shadow'] = '';
823
                $new_settings['simple_portfolio_rounded_corners'] = '';
824
                $new_settings['simple_portfolio_inner_shadow'] = '';
825
                $new_settings['simple_portfolio_hover_effect_preset'] = '';
826
            }
827
828
			return $new_settings;
829
		}
830
	}
831
}