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/thumb-dimensions ( 3a26b7...7f492d )
by Brad
02:20
created

get_thumbnail_dimensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
14
			add_action( 'foogallery_render_gallery_template_field_custom', array( $this, 'render_thumbnail_preview' ), 10, 3 );
15
			add_filter( 'foogallery_attachment_html_image_attributes', array( $this, 'strip_size' ), 99, 3 );
16
17
			add_filter( 'foogallery_template_thumbnail_dimensions-image-viewer', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
18
		}
19
20
		/**
21
		 * Register myself so that all associated JS and CSS files can be found and automatically included
22
		 * @param $extensions
23
		 *
24
		 * @return array
25
		 */
26
		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...
27
			$extensions[] = __FILE__;
28
			return $extensions;
29
		}
30
31
		/**
32
		 * Add our gallery template to the list of templates available for every gallery
33
		 * @param $gallery_templates
34
		 *
35
		 * @return array
36
		 */
37
		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...
38
39
			$gallery_templates[] = array(
40
				'slug'        => 'image-viewer',
41
				'name'        => __( 'Image Viewer', 'foogallery-image-viewer'),
42
				'preview_css' => FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL . 'css/gallery-image-viewer.css',
43
				'admin_js'	  => FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL . 'js/admin-gallery-image-viewer.js',
44
				'fields'	  => array(
45
					array(
46
						'id'      => 'alignment',
47
						'title'   => __( 'Alignment', 'foogallery' ),
48
						'desc'    => __( 'The horizontal alignment of the thumbnails inside the gallery.', 'foogallery' ),
49
						'default' => 'alignment-center',
50
						'type'    => 'select',
51
						'choices' => array(
52
							'alignment-left' => __( 'Left', 'foogallery' ),
53
							'alignment-center' => __( 'Center', 'foogallery' ),
54
							'alignment-right' => __( 'Right', 'foogallery' ),
55
						)
56
					),
57
					array(
58
						'id'      => 'lightbox',
59
						'title'   => __('Lightbox', 'foogallery-image-viewer'),
60
						'desc'    => __('Choose which lightbox you want to use in the gallery.', 'foogallery-image-viewer'),
61
						'type'    => 'lightbox'
62
					),
63
					array(
64
						'id'      => 'theme',
65
						'title'   => __('Theme', 'foogallery'),
66
						'default' => '',
67
						'type'    => 'radio',
68
						'spacer'  => '<span class="spacer"></span>',
69
						'choices' => array(
70
							'' => __( 'Light', 'foogallery' ),
71
							'fiv-dark' => __( 'Dark', 'foogallery' ),
72
							'fiv-custom' => __( 'Custom', 'foogallery' )
73
						)
74
					),
75
					array(
76
						'id'      => 'theme_custom_bgcolor',
77
						'title'   => __('Background Color', 'foogallery'),
78
						'section' => __( 'Custom Theme Colors', 'foogallery' ),
79
						'type'    => 'colorpicker',
80
						'default' => '#FFFFFF',
81
						'opacity' => true
82
					),
83
					array(
84
						'id'      => 'theme_custom_textcolor',
85
						'title'   => __('Text Color', 'foogallery'),
86
						'section' => __( 'Custom Theme Colors', 'foogallery' ),
87
						'type'    => 'colorpicker',
88
						'default' => '#1b1b1b',
89
						'opacity' => true
90
					),
91
					array(
92
						'id'      => 'theme_custom_hovercolor',
93
						'title'   => __('Hover BG Color', 'foogallery'),
94
						'section' => __( 'Custom Theme Colors', 'foogallery' ),
95
						'type'    => 'colorpicker',
96
						'default' => '#F2F2F2',
97
						'opacity' => true
98
					),
99
					array(
100
						'id'      => 'theme_custom_bordercolor',
101
						'title'   => __('Border Color', 'foogallery'),
102
						'section' => __( 'Custom Theme Colors', 'foogallery' ),
103
						'type'    => 'colorpicker',
104
						'default' => '#e6e6e6',
105
						'opacity' => true
106
					),
107
					array(
108
						'id'      => 'thumbnail_size',
109
						'title'   => __('Thumbnail Size', 'foogallery-image-viewer'),
110
						'section' => __( 'Thumbnail Settings', 'foogallery' ),
111
						'desc'    => __('Choose the size of your thumbs.', 'foogallery-image-viewer'),
112
						'type'    => 'thumb_size',
113
						'default' => array(
114
							'width' => 640,
115
							'height' => 360,
116
							'crop' => true
117
						)
118
					),
119
					array(
120
						'id'      => 'thumbnail_link',
121
						'title'   => __('Thumbnail Link', 'foogallery-image-viewer'),
122
						'section' => __( 'Thumbnail Settings', 'foogallery' ),
123
						'default' => 'image' ,
124
						'type'    => 'thumb_link',
125
						'spacer'  => '<span class="spacer"></span>',
126
						'desc'	  => __('You can choose to either link each thumbnail to the full size image or to the image\'s attachment page.', 'foogallery-image-viewer')
127
					),
128
					array(
129
						'id'      => 'hover-effect-type',
130
						'title'   => __( 'Hover Effect Type', 'foogallery' ),
131
						'section' => __( 'Thumbnail Settings', 'foogallery' ),
132
						'default' => '',
133
						'type'    => 'radio',
134
						'choices' => apply_filters( 'foogallery_gallery_template_hover-effect-types', array(
135
							''  => __( 'Icon', 'foogallery' ),
136
							'hover-effect-tint'   => __( 'Dark Tint', 'foogallery' ),
137
							'hover-effect-color' => __( 'Colorize', 'foogallery' ),
138
							'hover-effect-none' => __( 'None', 'foogallery' )
139
						) ),
140
						'spacer'  => '<span class="spacer"></span>',
141
						'desc'	  => __( 'The type of hover effect the thumbnails will use.', 'foogallery' )
142
					),
143
					array(
144
						'id'      => 'hover-effect',
145
						'title'   => __( 'Icon Hover Effect', 'foogallery' ),
146
						'desc'    => __( 'When the hover effect type of Icon is chosen, you can choose which icon is shown when you hover over each thumbnail.', 'foogallery' ),
147
						'section' => __( 'Thumbnail Settings', 'foogallery' ),
148
						'type'    => 'icon',
149
						'default' => 'hover-effect-zoom',
150
						'choices' => array(
151
							'hover-effect-zoom' => array( 'label' => __( 'Zoom' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-zoom.png' ),
152
							'hover-effect-zoom2' => array( 'label' => __( 'Zoom 2' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-zoom2.png' ),
153
							'hover-effect-zoom3' => array( 'label' => __( 'Zoom 3' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-zoom3.png' ),
154
							'hover-effect-plus' => array( 'label' => __( 'Plus' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-plus.png' ),
155
							'hover-effect-circle-plus' => array( 'label' => __( 'Circle Plus' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-circle-plus.png' ),
156
							'hover-effect-eye' => array( 'label' => __( 'Eye' , 'foogallery' ), 'img' => FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'img/admin/hover-effect-icon-eye.png' )
157
						),
158
					),
159
					array(
160
						'id'      => 'caption-content',
161
						'title'   => __( 'Caption Content', 'foogallery' ),
162
						'section' => __( 'Thumbnail Settings', 'foogallery' ),
163
						'default' => 'title',
164
						'type'    => 'radio',
165
						'choices' => apply_filters( 'foogallery_gallery_template_caption-content', array(
166
							'none'  => __( 'None', 'foogallery' ),
167
							'title'  => __( 'Title Only', 'foogallery' ),
168
							'desc'   => __( 'Description Only', 'foogallery' ),
169
							'both' => __( 'Title and Description', 'foogallery' )
170
						) ),
171
						'spacer'  => '<span class="spacer"></span>'
172
					),
173
					array(
174
						'id' => 'thumb_preview',
175
						'title' => __( 'Preview', 'foogallery' ),
176
						'desc' => __( 'This is what your gallery will look like.', 'foogallery' ),
177
						'section' => __( 'Thumbnail Settings', 'foogallery' ),
178
						'type' => 'image_viewer_preview',
179
					),
180
					array(
181
						'id'      => 'text-prev',
182
						'title'   => __( '"Prev" Text', 'foogallery' ),
183
						'section' => __( 'Language Settings', 'foogallery' ),
184
						'type'    => 'text',
185
						'default' =>  __('Prev', 'foogallery')
186
					),
187
					array(
188
						'id'      => 'text-of',
189
						'title'   => __( '"of" Text', 'foogallery' ),
190
						'section' => __( 'Language Settings', 'foogallery' ),
191
						'type'    => 'text',
192
						'default' =>  __('of', 'foogallery')
193
					),
194
					array(
195
						'id'      => 'text-next',
196
						'title'   => __( '"Next" Text', 'foogallery' ),
197
						'section' => __( 'Language Settings', 'foogallery' ),
198
						'type'    => 'text',
199
						'default' =>  __('Next', 'foogallery')
200
					)
201
				)
202
			);
203
204
			return $gallery_templates;
205
		}
206
207
		function render_thumbnail_preview( $field, $gallery, $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...
208
			if ( 'image_viewer_preview' == $field['type'] ) {
209
				$args = $gallery->get_meta( 'thumbnail_size', array(
210
						'width' => 640,
211
						'height' => 360,
212
						'crop' => true
213
				) );
214
				//override the link so that it does not actually open an image
215
				$args['link'] = 'custom';
216
				$args['custom_link'] = '#preview';
217
				$args['link_attributes'] = array(
218
						'class' => 'fiv-active'
219
				);
220
221
				$hover_effect = $gallery->get_meta( 'image-viewer_hover-effect', 'hover-effect-zoom' );
222
				$hover_effect_type = $gallery->get_meta( 'image-viewer_hover-effect-type', '' );
223
				$text_prev = $gallery->get_meta( 'image-viewer_text-prev', __('Prev', 'foogallery') );
224
				$text_of = $gallery->get_meta( 'image-viewer_text-of', __('of', 'foogallery') );
225
				$text_next = $gallery->get_meta( 'image-viewer_text-next', __('Next', 'foogallery') );
226
227
				$featured = $gallery->featured_attachment();
228
229
				if ( false === $featured ) {
230
					$featured = new FooGalleryAttachment();
231
					$featured->url = FOOGALLERY_URL . 'assets/test_thumb_1.jpg';
232
				}
233
234
				?><div class="foogallery-image-viewer-preview <?php echo foogallery_build_class_attribute( $gallery, $hover_effect, $hover_effect_type ); ?>">
235
				<div class="fiv-inner">
236
					<div class="fiv-inner-container">
237
						<?php
238
						echo $featured->html( $args, true, false );
239
						echo $featured->html_caption( 'both' );
240
						echo '</a>';
241
						?>
242
					</div>
243
					<div class="fiv-ctrls">
244
						<div class="fiv-prev"><span><?php echo $text_prev; ?></span></div>
245
						<label class="fiv-count"><span class="fiv-count-current">1</span><?php echo $text_of; ?><span>1</span></label>
246
						<div class="fiv-next"><span><?php echo $text_next; ?></span></div>
247
					</div>
248
				</div>
249
				</div><?php
250
			}
251
		}
252
253
		/**
254
		 * Image viewer relies on there being no width or height attributes on the IMG element so strip them out here.
255
		 *
256
		 * @param $attr
257
		 * @param $args
258
		 * @param $attachment
259
		 *
260
		 * @return mixed
261
		 */
262
		function strip_size($attr, $args, $attachment){
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...
263
			global $current_foogallery_template;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
264
265
			if ( 'image-viewer' === $current_foogallery_template ) {
266
				if ( isset($attr['width']) ){
267
					unset($attr['width']);
268
				}
269
				if ( isset($attr['height']) ){
270
					unset($attr['height']);
271
				}
272
			}
273
274
			return $attr;
275
		}
276
277
		/**
278
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
279
		 *
280
		 * @param array $dimensions
281
		 * @param FooGallery $foogallery
282
		 *
283
		 * @return mixed
284
		 */
285
		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...
286
			$dimensions = $foogallery->get_meta( 'thumbnail_size', false );
287
			return $dimensions;
288
		}
289
	}
290
}