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.

FooGallery_Thumbnail_Gallery_Template   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 209
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 209
rs 10
c 0
b 0
f 0
wmc 13
lcom 0
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 1
A alter_field_value() 0 10 4
A register_myself() 0 4 1
B add_template() 0 95 1
A enqueue_dependencies() 0 5 1
A preview_arguments() 0 6 1
A build_thumbnail_dimensions_from_arguments() 0 10 2
A get_thumbnail_dimensions() 0 11 2
1
<?php
2
3
if ( !class_exists( 'FooGallery_Thumbnail_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_THUMBNAIL_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Thumbnail_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
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
14
15
			add_filter( 'foogallery_located_template-thumbnail', array( $this, 'enqueue_dependencies' ) );
16
17
			//build up any preview arguments
18
			add_filter( 'foogallery_preview_arguments-thumbnail', array( $this, 'preview_arguments' ), 10, 2 );
19
20
			//build up the thumb dimensions from some arguments
21
			add_filter( 'foogallery_calculate_thumbnail_dimensions-thumbnail', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
22
23
			//build up the thumb dimensions on save
24
			add_filter( 'foogallery_template_thumbnail_dimensions-thumbnail', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
25
26
			//alter the crop value if needed
27
			add_filter( 'foogallery_render_gallery_template_field_value', array( $this, 'alter_field_value'), 10, 4 );
28
        }
29
30
		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...
31
		    //only do something if we are dealing with the thumbnail_dimensions field in this template
32
		    if ( 'thumbnail' === $template['slug'] && 'thumbnail_dimensions' === $field['id'] ) {
33
		        if ( !array_key_exists( 'crop', $value ) ) {
34
                    $value['crop'] = true;
35
                }
36
            }
37
38
		    return $value;
39
        }
40
41
		/**
42
		 * Register myself so that all associated JS and CSS files can be found and automatically included
43
		 * @param $extensions
44
		 *
45
		 * @return array
46
		 */
47
		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...
48
			$extensions[] = __FILE__;
49
			return $extensions;
50
		}
51
52
		/**
53
		 * Add our gallery template to the list of templates available for every gallery
54
		 * @param $gallery_templates
55
		 *
56
		 * @return array
57
		 */
58
		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...
59
			$gallery_templates[] = array(
60
                'slug'        => 'thumbnail',
61
                'name'        => __( 'Single Thumbnail Gallery', 'foogallery' ),
62
				'preview_support' => true,
63
				'common_fields_support' => true,
64
                'lazyload_support' => true,
65
				'mandatory_classes' => 'fg-thumbnail',
66
				'thumbnail_dimensions' => true,
67
                'fields'	  => array(
68
                    array(
69
                        'id'	  => 'help',
70
                        'type'	  => 'html',
71
                        'section' => __( 'General', 'foogallery' ),
72
                        'help'	  => true,
73
                        'desc'	  => __( 'This gallery template only shows a single thumbnail, but the true power shines through when the thumbnail is clicked, because then the lightbox takes over and the user can view all the images in the gallery.', 'foogallery' ),
74
                    ),
75
                    array(
76
                        'id'      => 'thumbnail_dimensions',
77
                        'title'   => __( 'Size', 'foogallery' ),
78
                        'desc'    => __( 'Choose the size of your thumbnail.', 'foogallery' ),
79
                        'section' => __( 'General', 'foogallery' ),
80
                        'type'    => 'thumb_size',
81
                        'default' => array(
82
                            'width' => 250,
83
                            'height' => 200,
84
                            'crop' => true
85
                        ),
86
						'row_data'=> array(
87
							'data-foogallery-change-selector' => 'input',
88
							'data-foogallery-preview' => 'shortcode'
89
						)
90
                    ),
91
                    array(
92
                        'id'      => 'position',
93
                        'title'   => __( 'Position', 'foogallery' ),
94
                        'desc'    => __( 'The position of the thumbnail related to the content around it.', 'foogallery' ),
95
                        'section' => __( 'General', 'foogallery' ),
96
                        'default' => 'fg-center',
97
                        'type'    => 'select',
98
                        'choices' => array(
99
                            'fg-center' => __( 'Full Center', 'foogallery' ),
100
							'fg-left' => __( 'Full Left', 'foogallery' ),
101
							'fg-right' => __( 'Full Right', 'foogallery' ),
102
							'fg-float-left' => __( 'Float Left', 'foogallery' ),
103
                            'fg-float-right' => __( 'Float Right', 'foogallery' ),
104
                        ),
105
						'row_data'=> array(
106
							'data-foogallery-change-selector' => 'select',
107
							'data-foogallery-preview' => 'class'
108
						)
109
                    ),
110
                    array(
111
                        'id'      => 'link_custom_url',
112
                        'title'   => __( 'Link To Custom URL', 'foogallery' ),
113
                        'section' => __( 'General', 'foogallery' ),
114
                        'default' => '',
115
                        'type'    => 'checkbox',
116
                        'desc'	  => __( 'You can link your thumbnails to Custom URL\'s (if they are set on your attachments). Fallback will be to the full size image.', 'foogallery' )
117
                    ),
118
                    array(
119
                        'id'      => 'lightbox',
120
                        'title'   => __( 'Lightbox', 'foogallery' ),
121
                        'section' => __( 'General', 'foogallery' ),
122
                        'desc'    => __( 'Choose which lightbox you want to use.', 'foogallery' ),
123
                        'type'    => 'lightbox',
124
                        'default' => 'none',
125
                    ),
126
                    array(
127
                        'id'      => 'caption_title',
128
                        'title'   => __('Override Title', 'foogallery'),
129
						'section' => __( 'Captions', 'foogallery' ),
130
                        'desc'    => __('Leave blank if you do not want a caption title.', 'foogallery'),
131
                        'type'    => 'text',
132
						'row_data'=> array(
133
							'data-foogallery-change-selector' => 'input',
134
							'data-foogallery-preview' => 'shortcode'
135
						)
136
                    ),
137
                    array(
138
                        'id'      => 'caption_description',
139
                        'title'   => __('Override Description', 'foogallery'),
140
						'section' => __( 'Captions', 'foogallery' ),
141
                        'desc'    => __('Leave blank if you do not want a caption description.', 'foogallery'),
142
                        'type'    => 'textarea',
143
						'row_data'=> array(
144
							'data-foogallery-change-selector' => 'textarea',
145
							'data-foogallery-preview' => 'shortcode'
146
						)
147
                    )
148
                )
149
			);
150
151
			return $gallery_templates;
152
		}
153
154
		/**
155
		 * Enqueue scripts that the masonry gallery template relies on
156
		 */
157
		function enqueue_dependencies() {
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...
158
			//enqueue core files
159
			foogallery_enqueue_core_gallery_template_style();
160
			foogallery_enqueue_core_gallery_template_script();
161
		}
162
163
		/**
164
		 * Build up a arguments used in the preview of the gallery
165
		 * @param $args
166
		 * @param $post_data
167
		 *
168
		 * @return mixed
169
		 */
170
		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...
171
			$args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_thumbnail_dimensions'];
172
			$args['caption_title'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_caption_title'];
173
			$args['caption_description'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_caption_description'];
174
			return $args;
175
		}
176
177
		/**
178
		 * Builds thumb dimensions from arguments
179
		 *
180
		 * @param array $dimensions
181
		 * @param array $arguments
182
		 *
183
		 * @return mixed
184
		 */
185
		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...
186
            if ( array_key_exists( 'thumbnail_dimensions', $arguments) ) {
187
                return array(
188
                    'height' => intval($arguments['thumbnail_dimensions']['height']),
189
                    'width' => intval($arguments['thumbnail_dimensions']['width']),
190
                    'crop' => $arguments['thumbnail_dimensions']['crop']
191
                );
192
            }
193
            return null;
194
		}
195
196
		/**
197
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
198
		 *
199
		 * @param array $dimensions
200
		 * @param FooGallery $foogallery
201
		 *
202
		 * @return mixed
203
		 */
204
		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...
205
			$dimensions = $foogallery->get_meta( 'thumbnail_thumbnail_dimensions', array(
206
				'width' => get_option( 'thumbnail_size_w' ),
207
				'height' => get_option( 'thumbnail_size_h' ),
208
                'crop' => true
209
			) );
210
			if ( !array_key_exists( 'crop', $dimensions ) ) {
211
			    $dimensions['crop'] = true;
212
            }
213
			return $dimensions;
214
		}
215
	}
216
}