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 — feature/retina-support ( 1f9704...9ff796 )
by Brad
02:21
created

FooGallery_Admin_Settings::ajax_thumb_generation_test()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if ( ! class_exists( 'FooGallery_Admin_Settings' ) ) {
4
5
	/**
6
	 * Class FooGallery_Admin_Settings
7
	 */
8
	class FooGallery_Admin_Settings {
9
10
		function __construct() {
11
			add_filter( 'foogallery_admin_settings', array( $this, 'create_settings' ), 10, 2 );
12
			add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_custom_setting_types' ) );
13
			add_action( 'foogallery_admin_settings_after_render_setting', array( $this, 'after_render_setting' ) );
14
15
			// Ajax calls for clearing CSS optimization cache
16
			add_action( 'wp_ajax_foogallery_clear_css_optimizations', array( $this, 'ajax_clear_css_optimizations' ) );
17
			add_action( 'wp_ajax_foogallery_thumb_generation_test', array( $this, 'ajax_thumb_generation_test' ) );
18
			add_action( 'wp_ajax_foogallery_apply_retina_defaults', array( $this, 'ajax_apply_retina_defaults' ) );
19
		}
20
21
		/**
22
		 * Create the settings for FooGallery
23
		 * @return array
24
		 */
25
		function create_settings() {
26
27
			//region General Tab
28
			$tabs['general'] = __( 'General', 'foogallery' );
29
30
			$settings[] = array(
31
				'id'      => 'clear_css_optimizations',
32
				'title'   => __( 'Clear CSS Cache', 'foogallery' ),
33
				'desc'    => sprintf( __( '%s optimizes the way it loads gallery stylesheets to improve page performance. This can lead to the incorrect CSS being loaded in some cases. Use this button to clear all the CSS optimizations that have been cached across all galleries.', 'foogallery' ), foogallery_plugin_name() ),
34
				'type'    => 'clear_optimization_button',
35
				'tab'     => 'general',
36
				'section' => __( 'Cache', 'foogallery' )
37
			);
38
39
	        $gallery_templates = foogallery_gallery_templates();
40
			$gallery_templates_choices = array();
41
			foreach ( $gallery_templates as $template ) {
42
				$gallery_templates_choices[ $template['slug'] ] = $template['name'];
43
			}
44
45
			$settings[] = array(
46
				'id'      => 'gallery_template',
47
				'title'   => __( 'Default Gallery Template', 'foogallery' ),
48
				'desc'    => __( 'The default gallery template to use for new galleries', 'foogallery' ),
49
				'default' => foogallery_get_default( 'gallery_template' ) ,
50
				'type'    => 'select',
51
				'choices' => $gallery_templates_choices,
52
				'tab'     => 'general',
53
				'section' => __( 'Gallery Defaults', 'foogallery' )
54
			);
55
56
			$settings[] = array(
57
				'id'      => 'gallery_sorting',
58
				'title'   => __( 'Default Gallery Sorting', 'foogallery' ),
59
				'desc'    => __( 'The default attachment sorting to use for new galleries', 'foogallery' ),
60
				'default' => '',
61
				'type'    => 'select',
62
				'choices' => foogallery_sorting_options(),
63
				'tab'     => 'general',
64
				'section' => __( 'Gallery Defaults', 'foogallery' )
65
			);
66
67
			$galleries = foogallery_get_all_galleries();
68
			$gallery_choices = array();
69
			$gallery_choices[] = __( 'No default', 'foogallery' );
70
			foreach ( $galleries as $gallery ) {
71
				$gallery_choices[ $gallery->ID ] = $gallery->name;
72
			}
73
74
			$settings[] = array(
75
				'id'      => 'default_gallery_settings',
76
				'title'   => __( 'Default Gallery Settings', 'foogallery' ),
77
				'desc'    => __( 'When creating a new gallery, it can use the settings from an existing gallery as the default settings. This will save you time when creating many galleries that all have the same look and feel.', 'foogallery' ),
78
				'type'    => 'select',
79
				'choices' => $gallery_choices,
80
				'tab'     => 'general',
81
				'section' => __( 'Gallery Defaults', 'foogallery' )
82
			);
83
84
			$settings[] = array(
85
				'id'      => 'caption_title_source',
86
				'title'   => __( 'Caption Title Source', 'foogallery' ),
87
				'desc'    => __( 'By default, image caption titles are pulled from the attachment "Caption" field. Alternatively, you can also choose to pull from the attachment "Title" field.', 'foogallery' ),
88
				'type'    => 'select',
89
				'choices' => array(
90
					'caption' => __('Attachment Caption Field', 'foogallery'),
91
					'title' => __('Attachment Title Field', 'foogallery')
92
				),
93
				'default' => 'caption',
94
				'tab'     => 'general',
95
				'section' => __( 'Captions', 'foogallery' ),
96
				'spacer'  => '<span class="spacer"></span>'
97
			);
98
99
			$settings[] = array(
100
					'id'      => 'caption_desc_source',
101
					'title'   => __( 'Caption Description Source', 'foogallery' ),
102
					'desc'    => __( 'By default, image caption descriptions are pulled from the attachment "Description" field. Alternatively, you can choose to use other fields.', 'foogallery' ),
103
					'type'    => 'select',
104
					'choices' => array(
105
							'desc' => __('Attachment Description Field', 'foogallery'),
106
							'title' => __('Attachment Title Field', 'foogallery'),
107
							'caption' => __('Attachment Caption Field', 'foogallery'),
108
							'alt' => __('Attachment Alt Field', 'foogallery')
109
					),
110
					'default' => 'desc',
111
					'tab'     => 'general',
112
					'section' => __( 'Captions', 'foogallery' ),
113
					'spacer'  => '<span class="spacer"></span>'
114
			);
115
116
			$settings[] = array(
117
				'id'      => 'hide_gallery_template_help',
118
				'title'   => __( 'Hide Gallery Template Help', 'foogallery' ),
119
				'desc'    => __( 'Some gallery templates show helpful tips, which are useful for new users. You can choose to hide these tips.', 'foogallery' ),
120
				'type'    => 'checkbox',
121
				'tab'     => 'general',
122
				'section' => __( 'Admin', 'foogallery' )
123
			);
124
125
			$settings[] = array(
126
				'id'      => 'hide_editor_button',
127
				'title'   => __( 'Hide WYSIWYG Editor Button', 'foogallery' ),
128
				'desc'    => sprintf( __( 'If enabled, this will hide the "Add %s" button in the WYSIWYG editor.', 'foogallery' ), foogallery_plugin_name() ),
129
				'type'    => 'checkbox',
130
				'tab'     => 'general',
131
				'section' => __( 'Admin', 'foogallery' )
132
			);
133
134
			//endregion General
135
136
	        //region Extensions Tab
137
	        $tabs['extensions'] = __( 'Extensions', 'foogallery' );
138
139
	        $settings[] = array(
140
		        'id'      => 'use_future_endpoint',
141
		        'title'   => __( 'Use Beta Endpoint', 'foogallery' ),
142
		        'desc'    => __( 'The list of available extensions are pulled from an external URL. You can also pull from a "beta" endpoint which will sometimes contain beta extensions that are not publicly available.', 'foogallery' ),
143
		        'type'    => 'checkbox',
144
		        'tab'     => 'extensions',
145
	        );
146
			//endregion Extensions Tab
147
148
			//region Images Tab
149
			$tabs['thumb'] = __( 'Images', 'foogallery' );
150
151
			$settings[] = array(
152
				'id'      => 'thumb_jpeg_quality',
153
				'title'   => __( 'Thumbnail JPEG Quality', 'foogallery' ),
154
				'desc'    => __( 'The image quality to be used when resizing JPEG images.', 'foogallery' ),
155
				'type'    => 'text',
156
				'default' => '80',
157
				'tab'     => 'thumb'
158
			);
159
160
			$settings[] = array(
161
				'id'      => 'default_retina_support',
162
				'title'   => __( 'Default Retina Support', 'foogallery' ),
163
				'desc'    => __( 'Default retina support for all new galleries that are created. This can also be overridden for each gallery.', 'foogallery' ),
164
				'type'    => 'checkboxlist',
165
				'choices' => foogallery_retina_options(),
166
				'tab'     => 'thumb'
167
			);
168
169
			$settings[] = array(
170
					'id'      => 'use_original_thumbs',
171
					'title'   => __( 'Use Original Thumbnails', 'foogallery' ),
172
					'desc'    => __( 'Allow for the original thumbnails to be used when possible. This can be useful if your thumbs are animated gifs.', 'foogallery' ),
173
					'type'    => 'checkbox',
174
					'tab'     => 'thumb'
175
			);
176
177
			$settings[] = array(
178
				'id'      => 'thumb_resize_animations',
179
				'title'   => __( 'Resize Animated GIFs', 'foogallery' ),
180
				'desc'    => __( 'Should animated gifs be resized or not. If enabled, only the first frame is used in the resize.', 'foogallery' ),
181
				'type'    => 'checkbox',
182
				'tab'     => 'thumb'
183
			);
184
185
			$settings[] = array(
186
				'id'      => 'thumb_generation_test',
187
				'title'   => __( 'Thumbnail Generation Test', 'foogallery' ),
188
				'desc'    => sprintf( __( 'Test to see if %s can generate the thumbnails it needs.', 'foogallery' ), foogallery_plugin_name() ),
189
				'type'    => 'thumb_generation_test',
190
				'tab'     => 'thumb'
191
			);
192
193
			//endregion Thumbnail Tab
194
195
//	        //region Advanced Tab
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
196
//	        $tabs['advanced'] = __( 'Advanced', 'foogallery' );
197
//
198
//	        $example_url = '<code>' . trailingslashit( site_url() ) . foogallery_permalink() . '/my-cool-gallery</code>';
199
//
200
//	        $settings[] = array(
201
//		        'id'      => 'gallery_permalinks_enabled',
202
//		        'title'   => __( 'Enable Friendly URL\'s', 'foogallery' ),
203
//		        'desc'    => sprintf( __( 'If enabled, you will be able to access your galleries from a friendly URL e.g. %s', 'foogallery' ), $example_url ),
204
//		        'default' => foogallery_get_default( 'gallery_permalinks_enabled' ),
205
//		        'type'    => 'checkbox',
206
//		        'tab'     => 'advanced',
207
//	        );
208
//
209
//	        $settings[] = array(
210
//		        'id'      => 'gallery_permalink',
211
//		        'title'   => __( 'Gallery Permalink', 'foogallery' ),
212
//		        'desc'    => __( 'If friendly URL\'s are enabled, this is used in building up a friendly URL', 'foogallery' ),
213
//		        'default' => foogallery_get_default( 'gallery_permalink' ),
214
//		        'type'    => 'text',
215
//		        'tab'     => 'advanced',
216
//	        );
217
//	        //endregion Advanced
218
219
			//region Language Tab
220
			$tabs['language'] = __( 'Language', 'foogallery' );
221
222
			$settings[] = array(
223
				'id'      => 'language_images_count_none_text',
224
				'title'   => __( 'Image Count None Text', 'foogallery' ),
225
				'type'    => 'text',
226
				'default' => __( 'No images', 'foogallery' ),
227
				'tab'     => 'language'
228
			);
229
230
			$settings[] = array(
231
				'id'      => 'language_images_count_single_text',
232
				'title'   => __( 'Image Count Single Text', 'foogallery' ),
233
				'type'    => 'text',
234
				'default' => __( '1 image', 'foogallery' ),
235
				'tab'     => 'language'
236
			);
237
238
			$settings[] = array(
239
				'id'      => 'language_images_count_plural_text',
240
				'title'   => __( 'Image Count Many Text', 'foogallery' ),
241
				'type'    => 'text',
242
				'default' => __( '%s images', 'foogallery' ),
243
				'tab'     => 'language'
244
			);
245
			//endregion Language Tab
246
247
			return apply_filters( 'foogallery_admin_settings_override', array(
248
				'tabs'     => $tabs,
249
				'sections' => array(),
250
				'settings' => $settings,
251
			) );
252
		}
253
254
		/**
255
		 * Render any custom setting types to the settings page
256
		 */
257
		function render_custom_setting_types( $args ) {
258
			if ( 'clear_optimization_button' === $args['type'] ) { ?>
259
				<input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_clear_css_optimizations' ) ); ?>" class="button-primary foogallery_clear_css_optimizations" value="<?php _e( 'Clear CSS Optimization Cache', 'foogallery' ); ?>">
260
				<span id="foogallery_clear_css_cache_spinner" style="position: absolute" class="spinner"></span>
261
			<?php } else if ( 'thumb_generation_test' === $args['type'] ) { ?>
262
				<div id="foogallery_thumb_generation_test_container">
263
					<input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_thumb_generation_test' ) ); ?>" class="button-primary foogallery_thumb_generation_test" value="<?php _e( 'Run Tests', 'foogallery' ); ?>">
264
					<span id="foogallery_thumb_generation_test_spinner" style="position: absolute" class="spinner"></span>
265
				</div>
266
			<?php }
267
		}
268
269
		function after_render_setting( $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...
270
			if ( 'default_retina_support' === $args['id'] ) {
271
272
				//build up a list of retina options and add them to a hidden input
273
				// so we can get the values on the client
274
				$input_
275
				foreach( foogallery_retina_options() as $retina_option ) {
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_FOREACH
Loading history...
Unused Code introduced by
This foreach statement is empty and can be removed.

This check looks for foreach loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
276
277
				}
278
279
				?><div id="foogallery_apply_retina_support_container">
280
					<input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_apply_retina_support' ) ); ?>" class="button-primary foogallery_apply_retina_support" value="<?php _e( 'Apply Defaults to all Galleries', 'foogallery' ); ?>">
281
					<span id="foogallery_apply_retina_support_spinner" style="position: absolute" class="spinner"></span>
282
				</div>
283
			<?php }
284
		}
285
286
		/**
287
		 * AJAX endpoint for clearing all CSS optimizations
288
		 */
289
		function ajax_clear_css_optimizations() {
290
			if ( check_admin_referer( 'foogallery_clear_css_optimizations' ) ) {
291
				foogallery_clear_all_css_load_optimizations();
292
293
				_e('The CSS optimization cache was successfully cleared!', 'foogallery' );
294
				die();
295
			}
296
		}
297
298
		/**
299
		 * AJAX endpoint for testing thumbnail generation using WPThumb
300
		 */
301
		function ajax_thumb_generation_test() {
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...
302
			if ( check_admin_referer( 'foogallery_thumb_generation_test' ) ) {
303
				foogallery_output_thumbnail_generation_results();
304
				die();
305
			}
306
		}
307
308
		/**
309
		 * AJAX endpoint for applying the retina defaults to all galleries
310
		 */
311
		function ajax_apply_retina_defaults() {
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...
312
			if ( check_admin_referer( 'foogallery_apply_retina_defaults' ) ) {
313
314
				die();
315
			}
316
		}
317
	}
318
}
319