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 ( 1273dd...b1bef9 )
by Brad
03:26
created

FooGallery_Image_Viewer_Gallery_Template   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 273
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 273
rs 10
c 0
b 0
f 0
wmc 18
lcom 0
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 1
A alter_field_value() 0 10 4
A register_myself() 0 4 1
B add_template() 0 113 1
A add_common_thumbnail_fields() 0 11 3
A enqueue_dependencies() 0 5 1
A get_thumbnail_dimensions() 0 11 2
A override_settings() 0 7 2
A preview_arguments() 0 7 1
A build_thumbnail_dimensions_from_arguments() 0 10 2
1
<?php
2
3
if ( !class_exists( 'FooGallery_Image_Viewer_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Image_Viewer_Gallery_Template {
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...
8
		/**
9
		 * Wire up everything we need to run the extension
10
		 */
11
		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...
12
			add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) );
13
14
			//add extra fields to the templates
15
			add_filter( 'foogallery_override_gallery_template_fields-image-viewer', array( $this, 'add_common_thumbnail_fields' ), 10, 2 );
16
17
			add_action( 'foogallery_located_template-image-viewer', array( $this, 'enqueue_dependencies' ) );
18
19
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
20
21
			add_filter( 'foogallery_template_thumbnail_dimensions-image-viewer', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
22
23
			//override specific settings when saving the gallery
24
			add_filter( 'foogallery_save_gallery_settings-image-viewer', array( $this, 'override_settings'), 10, 3 );
25
26
			//build up any preview arguments
27
			add_filter( 'foogallery_preview_arguments-image-viewer', array( $this, 'preview_arguments' ), 10, 2 );
28
29
			//build up the thumb dimensions from some arguments
30
			add_filter( 'foogallery_calculate_thumbnail_dimensions-image-viewer', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
31
32
            //alter the crop value if needed
33
            add_filter( 'foogallery_render_gallery_template_field_value', array( $this, 'alter_field_value'), 10, 4 );
34
35
        }
36
37
        function alter_field_value( $value, $field, $gallery, $template ) {
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...
38
            //only do something if we are dealing with the thumbnail_dimensions field in this template
39
            if ( 'image-viewer' === $template['slug'] && 'thumbnail_size' === $field['id'] ) {
40
                if ( !array_key_exists( 'crop', $value ) ) {
41
                    $value['crop'] = true;
42
                }
43
            }
44
45
            return $value;
46
        }
47
48
		/**
49
		 * Register myself so that all associated JS and CSS files can be found and automatically included
50
		 * @param $extensions
51
		 *
52
		 * @return array
53
		 */
54
		function register_myself( $extensions ) {
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...
55
			$extensions[] = __FILE__;
56
			return $extensions;
57
		}
58
59
		/**
60
		 * Add our gallery template to the list of templates available for every gallery
61
		 * @param $gallery_templates
62
		 *
63
		 * @return array
64
		 */
65
		function add_template( $gallery_templates ) {
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...
66
67
			$gallery_templates[] = array(
68
				'slug'        => 'image-viewer',
69
				'name'        => __( 'Image Viewer', 'foogallery' ),
70
				'preview_support' => true,
71
				'common_fields_support' => true,
72
				'lazyload_support' => true,
73
				'mandatory_classes' => 'fg-image-viewer',
74
				'thumbnail_dimensions' => true,
75
				'fields'	  => array(
76
                    array(
77
                        'id'      => 'thumbnail-help',
78
                        'title'   => __( 'Thumbnail Help', 'foogallery' ),
79
                        'desc'    => __( 'It is recommended to crop your thumbnails, so that your gallery remains a constant size. If you do not crop, then the size of the gallery could potentially change for each thumbnail.', 'foogallery' ),
80
                        'section' => __( 'General', 'foogallery' ),
81
                        'type'    => 'help'
82
                    ),
83
                    array(
84
                        'id'      => 'thumbnail_size',
85
                        'title'   => __( 'Thumb Size', 'foogallery' ),
86
                        'section' => __( 'General', 'foogallery' ),
87
                        'desc'    => __( 'Choose the size of your thumbnails', 'foogallery' ),
88
                        'type'    => 'thumb_size',
89
                        'default' => array(
90
                            'width' => 640,
91
                            'height' => 360,
92
                            'crop' => true
93
                        ),
94
						'row_data'=> array(
95
							'data-foogallery-change-selector' => 'input',
96
							'data-foogallery-preview' => 'shortcode'
97
						)
98
                    ),
99
                    array(
100
                        'id'      => 'thumbnail_link',
101
                        'title'   => __( 'Thumb Link', 'foogallery' ),
102
                        'section' => __( 'General', 'foogallery' ),
103
                        'default' => 'image' ,
104
                        'type'    => 'thumb_link',
105
                        'desc'	  => __( 'You can choose to either link each thumbnail to the full size image or to the image\'s attachment page', 'foogallery')
106
                    ),
107
                    array(
108
                        'id'      => 'lightbox',
109
                        'title'   => __( 'Lightbox', 'foogallery' ),
110
                        'section' => __( 'General', 'foogallery' ),
111
                        'desc'    => __( 'Choose which lightbox you want to use in the gallery', 'foogallery' ),
112
                        'default' => 'none',
113
                        'type'    => 'lightbox'
114
                    ),
115
                    array(
116
                        'id'      => 'alignment',
117
                        'title'   => __( 'Alignment', 'foogallery' ),
118
						'section' => __( 'General', 'foogallery' ),
119
                        'desc'    => __( 'The horizontal alignment of the thumbnails inside the gallery', 'foogallery' ),
120
                        'default' => 'fg-center',
121
						'type'    => 'radio',
122
						'spacer'  => '<span class="spacer"></span>',
123
                        'choices' => array(
124
                            'fg-left' => __( 'Left', 'foogallery' ),
125
                            'fg-center' => __( 'Center', 'foogallery' ),
126
                            'fg-right' => __( 'Right', 'foogallery' ),
127
                        ),
128
						'row_data'=> array(
129
							'data-foogallery-change-selector' => 'input:radio',
130
							'data-foogallery-preview' => 'class'
131
						)
132
                    ),
133
                    array(
134
                        'id'      => 'language-help',
135
                        'title'   => __( 'Language Help', 'foogallery' ),
136
                        'desc'    => __( 'This gallery template shows the below items of text. Change them to suit your preference or language.', 'foogallery' ),
137
						'section' => __( 'General', 'foogallery' ),
138
                        'type'    => 'help'
139
                    ),
140
					array(
141
						'id'      => 'text-prev',
142
						'title'   => __( '"Prev" Text', 'foogallery' ),
143
						'section' => __( 'General', 'foogallery' ),
144
						'type'    => 'text',
145
						'default' =>  __('Prev', 'foogallery'),
146
						'row_data'=> array(
147
							'data-foogallery-change-selector' => 'input',
148
							'data-foogallery-preview' => 'shortcode'
149
						)
150
					),
151
					array(
152
						'id'      => 'text-of',
153
						'title'   => __( '"of" Text', 'foogallery' ),
154
						'section' => __( 'General', 'foogallery' ),
155
						'type'    => 'text',
156
						'default' =>  __('of', 'foogallery'),
157
						'row_data'=> array(
158
							'data-foogallery-change-selector' => 'input',
159
							'data-foogallery-preview' => 'shortcode'
160
						)
161
					),
162
					array(
163
						'id'      => 'text-next',
164
						'title'   => __( '"Next" Text', 'foogallery' ),
165
						'section' => __( 'General', 'foogallery' ),
166
						'type'    => 'text',
167
						'default' =>  __('Next', 'foogallery'),
168
						'row_data'=> array(
169
							'data-foogallery-change-selector' => 'input',
170
							'data-foogallery-preview' => 'shortcode'
171
						)
172
					)
173
				)
174
			);
175
176
			return $gallery_templates;
177
		}
178
179
		/**
180
		 * Add thumbnail fields to the gallery template
181
		 *
182
		 * @uses "foogallery_override_gallery_template_fields"
183
		 * @param $fields
184
		 * @param $template
185
		 *
186
		 * @return array
187
		 */
188
		function add_common_thumbnail_fields( $fields, $template ) {
0 ignored issues
show
Unused Code introduced by
The parameter $template 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...
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...
189
190
			//update specific fields
191
			foreach ($fields as &$field) {
192
				if ( 'rounded_corners' === $field['id'] ) {
193
					unset( $field['choices']['fg-round-full'] );
194
				}
195
			}
196
197
			return $fields;
198
		}
199
200
		/**
201
		 * Enqueue scripts that the default gallery template relies on
202
		 */
203
		function enqueue_dependencies( $gallery ) {
0 ignored issues
show
Unused Code introduced by
The parameter $gallery 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...
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...
204
			//enqueue core files
205
			foogallery_enqueue_core_gallery_template_style();
206
			foogallery_enqueue_core_gallery_template_script();
207
		}
208
209
		/**
210
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
211
		 *
212
		 * @param array $dimensions
213
		 * @param FooGallery $foogallery
214
		 *
215
		 * @return mixed
216
		 */
217
		function get_thumbnail_dimensions( $dimensions, $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...
218
			$dimensions = $foogallery->get_meta( 'image-viewer_thumbnail_size', array(
219
				'width' => 640,
220
				'height' => 360,
221
                'crop' => true
222
			) );
223
            if ( !array_key_exists( 'crop', $dimensions ) ) {
224
                $dimensions['crop'] = true;
225
            }
226
			return $dimensions;
227
		}
228
229
		/**
230
		 * Override specific settings so that the gallery template will always work
231
		 *
232
		 * @param $settings
233
		 * @param $post_id
234
		 * @param $form_data
235
		 *
236
		 * @return mixed
237
		 */
238
		function override_settings($settings, $post_id, $form_data) {
0 ignored issues
show
Unused Code introduced by
The parameter $post_id 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...
Unused Code introduced by
The parameter $form_data 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...
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...
239
			if ( 'fg-round-full' === $settings['image-viewer_rounded_corners'] ) {
240
				$settings['image-viewer_rounded_corners'] = 'fg-round-large';
241
			}
242
243
			return $settings;
244
		}
245
246
		/**
247
		 * Build up a arguments used in the preview of the gallery
248
		 * @param $args
249
		 * @param $post_data
250
		 *
251
		 * @return mixed
252
		 */
253
		function preview_arguments( $args, $post_data ) {
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...
254
			$args['thumbnail_size'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_thumbnail_size'];
255
			$args['text-prev'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_text-prev'];
256
			$args['text-of'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_text-of'];
257
			$args['text-next'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_text-next'];
258
			return $args;
259
		}
260
261
		/**
262
		 * Builds thumb dimensions from arguments
263
		 *
264
		 * @param array $dimensions
265
		 * @param array $arguments
266
		 *
267
		 * @return mixed
268
		 */
269
		function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) {
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 ( array_key_exists( 'thumbnail_size', $arguments) ) {
271
                return array(
272
                    'height' => intval($arguments['thumbnail_size']['height']),
273
                    'width' => intval($arguments['thumbnail_size']['width']),
274
                    'crop' => $arguments['thumbnail_size']['crop']
275
                );
276
            }
277
            return null;
278
		}
279
	}
280
}