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

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
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' => 'position-block',
97
                        'type'    => 'select',
98
                        'choices' => array(
99
                            'fg-center' => __( 'Full Width (block)', 'foogallery' ),
100
                            'fg-left' => __( 'Float Left', 'foogallery' ),
101
                            'fg-right' => __( 'Float Right', 'foogallery' ),
102
                        ),
103
						'row_data'=> array(
104
							'data-foogallery-change-selector' => 'select',
105
							'data-foogallery-preview' => 'class'
106
						)
107
                    ),
108
                    array(
109
                        'id'      => 'link_custom_url',
110
                        'title'   => __( 'Link To Custom URL', 'foogallery' ),
111
                        'section' => __( 'General', 'foogallery' ),
112
                        'default' => '',
113
                        'type'    => 'checkbox',
114
                        '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' )
115
                    ),
116
                    array(
117
                        'id'      => 'lightbox',
118
                        'title'   => __( 'Lightbox', 'foogallery' ),
119
                        'section' => __( 'General', 'foogallery' ),
120
                        'desc'    => __( 'Choose which lightbox you want to use.', 'foogallery' ),
121
                        'type'    => 'lightbox',
122
                        'default' => 'none',
123
                    ),
124
                    array(
125
                        'id'      => 'caption_title',
126
                        'title'   => __('Override Title', 'foogallery'),
127
						'section' => __( 'Captions', 'foogallery' ),
128
                        'desc'    => __('Leave blank if you do not want a caption title.', 'foogallery'),
129
                        'type'    => 'text',
130
						'row_data'=> array(
131
							'data-foogallery-change-selector' => 'input',
132
							'data-foogallery-preview' => 'shortcode'
133
						)
134
                    ),
135
                    array(
136
                        'id'      => 'caption_description',
137
                        'title'   => __('Override Description', 'foogallery'),
138
						'section' => __( 'Captions', 'foogallery' ),
139
                        'desc'    => __('Leave blank if you do not want a caption description.', 'foogallery'),
140
                        'type'    => 'textarea',
141
						'row_data'=> array(
142
							'data-foogallery-change-selector' => 'textarea',
143
							'data-foogallery-preview' => 'shortcode'
144
						)
145
                    )
146
                )
147
			);
148
149
			return $gallery_templates;
150
		}
151
152
		/**
153
		 * Enqueue scripts that the masonry gallery template relies on
154
		 */
155
		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...
156
			//enqueue core files
157
			foogallery_enqueue_core_gallery_template_style();
158
			foogallery_enqueue_core_gallery_template_script();
159
		}
160
161
		/**
162
		 * Build up a arguments used in the preview of the gallery
163
		 * @param $args
164
		 * @param $post_data
165
		 *
166
		 * @return mixed
167
		 */
168
		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...
169
			$args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_thumbnail_dimensions'];
170
			$args['caption_title'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_caption_title'];
171
			$args['caption_description'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_caption_description'];
172
			return $args;
173
		}
174
175
		/**
176
		 * Builds thumb dimensions from arguments
177
		 *
178
		 * @param array $dimensions
179
		 * @param array $arguments
180
		 *
181
		 * @return mixed
182
		 */
183
		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...
184
            if ( array_key_exists( 'thumbnail_dimensions', $arguments) ) {
185
                return array(
186
                    'height' => intval($arguments['thumbnail_dimensions']['height']),
187
                    'width' => intval($arguments['thumbnail_dimensions']['width']),
188
                    'crop' => $arguments['thumbnail_dimensions']['crop']
189
                );
190
            }
191
            return null;
192
		}
193
194
		/**
195
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
196
		 *
197
		 * @param array $dimensions
198
		 * @param FooGallery $foogallery
199
		 *
200
		 * @return mixed
201
		 */
202
		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...
203
			$dimensions = $foogallery->get_meta( 'thumbnail_thumbnail_dimensions', array(
204
				'width' => get_option( 'thumbnail_size_w' ),
205
				'height' => get_option( 'thumbnail_size_h' ),
206
                'crop' => true
207
			) );
208
			if ( !array_key_exists( 'crop', $dimensions ) ) {
209
			    $dimensions['crop'] = true;
210
            }
211
			return $dimensions;
212
		}
213
	}
214
}