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 ( f3e37c...e64063 )
by Brad
07:56 queued 03:40
created

build_gallery_template_arguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
if ( !class_exists( 'FooGallery_Justified_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_JUSTIFIED_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Justified_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
			add_filter( 'foogallery_template_thumbnail_dimensions-justified', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
15
16
			add_action( 'foogallery_located_template-justified', array( $this, 'enqueue_dependencies' ) );
17
18
			//add the data options needed for justified
19
			add_filter( 'foogallery_build_container_data_options-justified', array( $this, 'add_justified_options' ), 10, 3 );
20
21
			//build up any preview arguments
22
			add_filter( 'foogallery_preview_arguments-justified', array( $this, 'preview_arguments' ), 10, 2 );
23
24
			//build up the thumb dimensions from some arguments
25
			add_filter( 'foogallery_calculate_thumbnail_dimensions-justified', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
26
27
            //build up the arguments needed for rendering this template
28
            add_filter( 'foogallery_gallery_template_arguments-justified', array( $this, 'build_gallery_template_arguments' ) );
29
        }
30
31
		/**
32
		 * Register myself so that all associated JS and CSS files can be found and automatically included
33
		 * @param $extensions
34
		 *
35
		 * @return array
36
		 */
37
		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...
38
			$extensions[] = __FILE__;
39
			return $extensions;
40
		}
41
42
		/**
43
		 * Add our gallery template to the list of templates available for every gallery
44
		 * @param $gallery_templates
45
		 *
46
		 * @return array
47
		 */
48
		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...
49
			$gallery_templates[] = array(
50
                'slug'        => 'justified',
51
                'name'        => __( 'Justified Gallery', 'foogallery' ),
52
				'preview_support' => true,
53
				'common_fields_support' => true,
54
                'lazyload_support' => true,
55
				'paging_support' => true,
56
				'mandatory_classes' => 'fg-justified',
57
				'thumbnail_dimensions' => true,
58
                'fields'	  => array(
59
                    array(
60
                        'id'      => 'thumb_height',
61
                        'title'   => __( 'Thumb Height', 'foogallery' ),
62
                        'desc'    => __( 'Choose the height of your thumbnails. Thumbnails will be generated on the fly and cached once generated', 'foogallery' ),
63
                        'section' => __( 'General', 'foogallery' ),
64
                        'type'    => 'number',
65
                        'class'   => 'small-text',
66
                        'default' => 250,
67
                        'step'    => '10',
68
                        'min'     => '0',
69
						'row_data'=> array(
70
							'data-foogallery-preview' => 'shortcode',
71
							'data-foogallery-change-selector' => 'input',
72
						)
73
                    ),
74
                    array(
75
                        'id'      => 'row_height',
76
                        'title'   => __( 'Row Height', 'foogallery' ),
77
                        'desc'    => __( 'The preferred height of your gallery rows. This can be different from the thumbnail height', 'foogallery' ),
78
                        'section' => __( 'General', 'foogallery' ),
79
                        'type'    => 'number',
80
                        'class'   => 'small-text',
81
                        'default' => 150,
82
                        'step'    => '10',
83
                        'min'     => '0',
84
						'row_data'=> array(
85
							'data-foogallery-change-selector' => 'input',
86
							'data-foogallery-value-selector' => 'input',
87
							'data-foogallery-preview' => 'shortcode',
88
						)
89
                    ),
90
                    array(
91
                        'id'      => 'max_row_height',
92
                        'title'   => __( 'Max Row Height', 'foogallery' ),
93
                        'desc'    => __( 'A number (e.g 200) which specifies the maximum row height in pixels. A negative value for no limits. Alternatively, use a percentage (e.g. 200% which means that the row height cannot exceed 2 * rowHeight)', 'foogallery' ),
94
                        'section' => __( 'General', 'foogallery' ),
95
                        'type'    => 'text',
96
                        'class'   => 'small-text',
97
                        'default' => '200%',
98
						'row_data'=> array(
99
							'data-foogallery-change-selector' => 'input',
100
							'data-foogallery-value-selector' => 'input',
101
							'data-foogallery-preview' => 'shortcode',
102
						)
103
                    ),
104
                    array(
105
                        'id'      => 'margins',
106
                        'title'   => __( 'Margins', 'foogallery' ),
107
                        'desc'    => __( 'The spacing between your thumbnails.', 'foogallery' ),
108
						'section' => __( 'General', 'foogallery' ),
109
                        'type'    => 'number',
110
                        'class'   => 'small-text',
111
                        'default' => 1,
112
                        'step'    => '1',
113
                        'min'     => '0',
114
						'row_data'=> array(
115
							'data-foogallery-change-selector' => 'input',
116
							'data-foogallery-value-selector' => 'input',
117
							'data-foogallery-preview' => 'shortcode',
118
						)
119
                    ),
120
                    array(
121
                        'id'      => 'thumbnail_link',
122
                        'title'   => __( 'Thumbnail Link', 'foogallery' ),
123
                        'section' => __( 'General', 'foogallery' ),
124
                        'default' => 'image' ,
125
                        'type'    => 'thumb_link',
126
                        'desc'	  => __( 'You can choose to link each thumbnail to the full size image, or to the image\'s attachment page, or you can choose to not link to anything.', 'foogallery' ),
127
                    ),
128
                    array(
129
                        'id'      => 'lightbox',
130
                        'title'   => __( 'Lightbox', 'foogallery' ),
131
                        'desc'    => __( 'Choose which lightbox you want to display images with. The lightbox will only work if you set the thumbnail link to "Full Size Image".', 'foogallery' ),
132
                        'section' => __( 'General', 'foogallery' ),
133
                        'default' => 'none',
134
                        'type'    => 'lightbox',
135
                    ),
136
                    array(
137
                        'id'      => 'lastrow',
138
                        'title'   => __( 'Last Row', 'foogallery' ),
139
                        'desc'    => __( 'What should be done with the last row in the gallery?', 'foogallery' ),
140
                        'section' => __( 'General', 'foogallery' ),
141
                        'type'    => 'radio',
142
                        'spacer'  => '<span class="spacer"></span>',
143
                        'default' => 'center',
144
                        'choices' => array(
145
                            'hide' => __( 'Hide', 'foogallery' ),
146
                            'justify' => __( 'Justify', 'foogallery' ),
147
                            'nojustify' => __( 'No Justify', 'foogallery' ),
148
                            'right' => __( 'Right', 'foogallery' ),
149
                            'center' => __( 'Center', 'foogallery' ),
150
                            'left' => __( 'Left', 'foogallery' ),
151
                        ),
152
                        'row_data'=> array(
153
                            'data-foogallery-change-selector' => 'input:radio',
154
                            'data-foogallery-value-selector' => 'input:checked',
155
                            'data-foogallery-preview' => 'shortcode',
156
                        )
157
                    ),
158
                ),
159
			);
160
161
			return $gallery_templates;
162
		}
163
164
		/**
165
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
166
		 *
167
		 * @param array $dimensions
168
		 * @param FooGallery $foogallery
169
		 *
170
		 * @return mixed
171
		 */
172
		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...
173
			$height = $foogallery->get_meta( 'justified_thumb_height', false );
174
			return array(
175
				'height' => intval( $height ),
176
				'width'  => 0,
177
				'crop'   => false
178
			);
179
		}
180
181
		/**
182
		 * Enqueue scripts that the default gallery template relies on
183
		 */
184
		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...
185
			//enqueue core files
186
			foogallery_enqueue_core_gallery_template_style();
187
			foogallery_enqueue_core_gallery_template_script();
188
		}
189
190
		/**
191
		 * Add the required justified options if needed
192
		 *
193
		 * @param $options
194
		 * @param $gallery    FooGallery
195
		 *
196
		 * @param $attributes array
197
		 *
198
		 * @return array
199
		 */
200
		function add_justified_options($options, $gallery, $attributes) {
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...
Unused Code introduced by
The parameter $attributes 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...
201
202
			$row_height = foogallery_gallery_template_setting( 'row_height', '150' );
203
			$max_row_height = foogallery_gallery_template_setting( 'max_row_height', '200%' );
204
			if ( strpos( $max_row_height, '%' ) === false ) {
205
				$max_row_height = intval( $max_row_height );
206
			}
207
			$margins = foogallery_gallery_template_setting( 'margins', '1' );
208
			$lastRow = foogallery_gallery_template_setting( 'lastrow', 'center' );
209
210
			$options['template']['rowHeight'] = intval($row_height);
211
			$options['template']['maxRowHeight'] = $max_row_height;
212
			$options['template']['margins'] = intval($margins);
213
            $options['template']['lastRow'] = $lastRow;
214
215
			return $options;
216
		}
217
218
		/**
219
		 * Build up a arguments used in the preview of the gallery
220
		 * @param $args
221
		 * @param $post_data
222
		 *
223
		 * @return mixed
224
		 */
225
		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...
226
			$args['thumbnail_height'] = $post_data[FOOGALLERY_META_SETTINGS]['justified_thumb_height'];
227
			$args['row_height'] = $post_data[FOOGALLERY_META_SETTINGS]['justified_row_height'];
228
			$args['max_row_height'] = $post_data[FOOGALLERY_META_SETTINGS]['justified_max_row_height'];
229
			$args['margins'] = $post_data[FOOGALLERY_META_SETTINGS]['justified_margins'];
230
            $args['lastrow'] = $post_data[FOOGALLERY_META_SETTINGS]['justified_lastrow'];
231
			return $args;
232
		}
233
234
		/**
235
		 * Builds thumb dimensions from arguments
236
		 *
237
		 * @param array $dimensions
238
		 * @param array $arguments
239
		 *
240
		 * @return mixed
241
		 */
242
		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...
243
		    if ( array_key_exists( 'thumbnail_height', $arguments) ) {
244
                return array(
245
                    'height' => intval($arguments['thumbnail_height']),
246
                    'width' => 0,
247
                    'crop' => false
248
                );
249
            }
250
251
            return null;
252
		}
253
254
        /**
255
         * Build up the arguments needed for rendering this gallery template
256
         *
257
         * @param $args
258
         * @return array
259
         */
260
        function build_gallery_template_arguments( $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args 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...
261
            $height = foogallery_gallery_template_setting( 'thumb_height', '250' );
262
            $args = array(
263
                'height' => $height,
264
                'link' => foogallery_gallery_template_setting( 'thumbnail_link', 'image' )
265
            );
266
267
            return $args;
268
        }
269
	}
270
}