This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * Adds video support within FooGallery |
||
4 | */ |
||
5 | |||
6 | if ( ! class_exists( 'FooGallery_Pro_Video' ) ) { |
||
7 | |||
8 | define( 'FOOGALLERY_VIDEO_POST_META', '_foogallery_video_data' ); |
||
9 | define( 'FOOGALLERY_VIDEO_POST_META_VIDEO_COUNT', '_foogallery_video_count' ); |
||
10 | |||
11 | require_once plugin_dir_path( __FILE__ ) . 'functions.php'; |
||
12 | require_once plugin_dir_path( __FILE__ ) . 'class-foogallery-pro-video-query.php'; |
||
13 | require_once plugin_dir_path( __FILE__ ) . 'class-foogallery-pro-video-import.php'; |
||
14 | |||
15 | class FooGallery_Pro_Video { |
||
0 ignored issues
–
show
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. ![]() |
|||
16 | /** |
||
17 | * Wire up everything we need |
||
18 | */ |
||
19 | function __construct() { |
||
0 ignored issues
–
show
|
|||
20 | new FooGallery_Pro_Video_Query(); |
||
21 | new FooGallery_Pro_Video_Import(); |
||
22 | |||
23 | //setup script includes |
||
24 | add_action( 'wp_enqueue_media', array( $this, 'enqueue_assets' ) ); |
||
25 | |||
26 | //make sure the gallery items render with a video icon |
||
27 | add_filter( 'foogallery_admin_render_gallery_item_extra_classes', array( $this, 'render_gallery_item_with_video_icon' ), 10, 2 ); |
||
28 | |||
29 | //add attachment custom fields |
||
30 | add_filter( 'foogallery_attachment_custom_fields', array( $this, 'attachment_custom_fields' ) ); |
||
31 | |||
32 | //add extra fields to all templates |
||
33 | add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'all_template_fields' ) ); |
||
34 | |||
35 | // add additional templates |
||
36 | add_action( 'admin_footer', array( $this, 'add_media_templates' ) ); |
||
37 | |||
38 | //load all video info into the attachment, so that it is only done once |
||
39 | add_action( 'foogallery_attachment_instance_after_load', array( $this, 'set_video_flag_on_attachment' ), 10, 2 ); |
||
40 | |||
41 | //add attributes to front-end anchor |
||
42 | add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'alter_video_link_attributes' ), 24, 3 ); |
||
43 | |||
44 | //add class to front-end item |
||
45 | add_filter( 'foogallery_attachment_html_item_classes', array( $this, 'alter_video_item_attributes' ), 24, 3 ); |
||
46 | |||
47 | //add video icon class to galleries |
||
48 | add_filter( 'foogallery_build_class_attribute', array( $this, 'foogallery_build_class_attribute' ) ); |
||
49 | |||
50 | //intercept gallery save and calculate how many videos are in the gallery |
||
51 | add_action( 'foogallery_after_save_gallery', array( $this, 'calculate_video_count' ) ); |
||
52 | |||
53 | //change the image count to include videos if they are present in the gallery |
||
54 | add_filter( 'foogallery_image_count', array( $this, 'include_video_count' ), 11, 2 ); |
||
55 | |||
56 | //check if the gallery is using foobox free and also has a video and if so, enqueue foobox video scripts. |
||
57 | add_action( 'foogallery_loaded_template', array( $this, 'enqueue_foobox_free_dependencies' ) ); |
||
58 | |||
59 | //check if the album is using foobox free and also has a video and if so, enqueue foobox video scripts. |
||
60 | add_action( 'foogallery_loaded_album_template', array( $this, 'enqueue_foobox_free_dependencies_for_album' ) ); |
||
61 | |||
62 | //add settings for video |
||
63 | add_filter( 'foogallery_admin_settings_override', array( $this, 'include_video_settings' ) ); |
||
64 | |||
65 | //output the embeds after the gallery if needed |
||
66 | add_action( 'foogallery_loaded_template', array( $this, 'include_video_embeds' ) ); |
||
67 | |||
68 | //output the embeds after the album if needed |
||
69 | add_action( 'foogallery_loaded_album_template', array( $this, 'include_video_embeds_for_album' ) ); |
||
70 | |||
71 | //ajax call to save the Vimeo access token |
||
72 | add_action('wp_ajax_fgi_save_access_token', array($this, 'save_vimeo_access_token')); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Enqueue styles and scripts |
||
77 | */ |
||
78 | function enqueue_assets() { |
||
0 ignored issues
–
show
|
|||
79 | foogallery_enqueue_media_views_script(); |
||
80 | foogallery_enqueue_media_views_style(); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Include the templates into the page if they are needed |
||
85 | */ |
||
86 | public function add_media_templates() { |
||
87 | if ( wp_script_is( 'foogallery-media-views' ) ) { |
||
88 | foogallery_include_media_views_templates(); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Add an extra class so that a video icon shows for videos |
||
94 | * |
||
95 | * @param $extra_class |
||
96 | * @param $attachment_post |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | function render_gallery_item_with_video_icon( $extra_class, $attachment_post ) { |
||
0 ignored issues
–
show
|
|||
101 | //check if the attachment is a video and append a class |
||
102 | if ( foogallery_is_attachment_video( $attachment_post ) ) { |
||
103 | if ( ! isset( $extra_class ) ) { |
||
104 | $extra_class = ''; |
||
105 | } |
||
106 | $extra_class .= ' subtype-foogallery'; |
||
107 | } |
||
108 | |||
109 | return $extra_class; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Add video specific custom fields. |
||
114 | * |
||
115 | * @uses "foogallery_attachment_custom_fields" filter |
||
116 | * |
||
117 | * @param array $fields |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | public function attachment_custom_fields( $fields ) { |
||
122 | $fields['data-width'] = array( |
||
123 | 'label' => __( 'Override Width', 'foogallery' ), |
||
124 | 'input' => 'text', |
||
125 | 'application' => 'image/foogallery', |
||
126 | ); |
||
127 | $fields['data-height'] = array( |
||
128 | 'label' => __( 'Override Height', 'foogallery' ), |
||
129 | 'input' => 'text', |
||
130 | 'application' => 'image/foogallery', |
||
131 | ); |
||
132 | |||
133 | return $fields; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Add fields to all galleries. |
||
138 | * |
||
139 | * @uses "foogallery_override_gallery_template_fields" |
||
140 | * |
||
141 | * @param $fields |
||
142 | * |
||
143 | * @return mixed |
||
144 | */ |
||
145 | public function all_template_fields( $fields ) { |
||
146 | $fields[] = array( |
||
147 | 'id' => 'video_hover_icon', |
||
148 | 'section' => __( 'Video', 'foogallery' ), |
||
149 | 'title' => __( 'Video Hover Icon', 'foogallery' ), |
||
150 | 'type' => 'htmlicon', |
||
151 | 'default' => 'fg-video-default', |
||
152 | 'choices' => apply_filters( |
||
153 | 'foogallery_gallery_template_video_hover_icon_choices', array( |
||
154 | '' => array( 'label' => __( 'None', 'foogallery' ), 'html' => '<div class="foogallery-setting-video_overlay"></div>' ), |
||
155 | 'fg-video-default' => array( 'label' => __( 'Default Icon', 'foogallery' ), 'html' => '<div class="foogallery-setting-video_overlay fg-video-default"></div>' ), |
||
156 | 'fg-video-1' => array( 'label' => __( 'Icon 1', 'foogallery' ), 'html' => '<div class="foogallery-setting-video_overlay fg-video-1"></div>' ), |
||
157 | 'fg-video-2' => array( 'label' => __( 'Icon 2', 'foogallery' ), 'html' => '<div class="foogallery-setting-video_overlay fg-video-2"></div>' ), |
||
158 | 'fg-video-3' => array( 'label' => __( 'Icon 3', 'foogallery' ), 'html' => '<div class="foogallery-setting-video_overlay fg-video-3"></div>' ), |
||
159 | 'fg-video-4' => array( 'label' => __( 'Icon 4', 'foogallery' ), 'html' => '<div class="foogallery-setting-video_overlay fg-video-4"></div>' ), |
||
160 | ) |
||
161 | ), |
||
162 | 'row_data' => array( |
||
163 | 'data-foogallery-change-selector' => 'input:radio', |
||
164 | 'data-foogallery-preview' => 'class' |
||
165 | ) |
||
166 | ); |
||
167 | $fields[] = array( |
||
168 | 'id' => 'video_sticky_icon', |
||
169 | 'section' => __( 'Video', 'foogallery' ), |
||
170 | 'title' => __( 'Sticky Video Icon', 'foogallery' ), |
||
171 | 'desc' => __( 'Always show the video icon for videos in the gallery, and not only when you hover.', 'foogallery' ), |
||
172 | 'type' => 'radio', |
||
173 | 'default' => '', |
||
174 | 'spacer' => '<span class="spacer"></span>', |
||
175 | 'choices' => array( |
||
176 | 'fg-video-sticky' => __( 'Yes', 'foogallery' ), |
||
177 | '' => __( 'No', 'foogallery' ), |
||
178 | ), |
||
179 | 'row_data' => array( |
||
180 | 'data-foogallery-change-selector' => 'input:radio', |
||
181 | 'data-foogallery-preview' => 'class' |
||
182 | ) |
||
183 | ); |
||
184 | |||
185 | $fields[] = array( |
||
186 | 'id' => 'video_size_help', |
||
187 | 'title' => __( 'Video Size Help', 'foogallery' ), |
||
188 | 'desc' => __( 'The lightbox video size can be overridden on each individual video by editing the attachment info, and changing the Override Width and Override Height properties.', 'foogallery' ), |
||
189 | 'section' => __( 'Video', 'foogallery' ), |
||
190 | 'type' => 'help', |
||
191 | ); |
||
192 | |||
193 | $fields[] = array( |
||
194 | 'id' => 'video_size', |
||
195 | 'section' => __( 'Video', 'foogallery' ), |
||
196 | 'title' => __( 'Lightbox Video Size', 'foogallery' ), |
||
197 | 'desc' => __( 'The default video size when opening videos in the lightbox.', 'foogallery' ), |
||
198 | 'type' => 'select', |
||
199 | 'default' => '640x360', |
||
200 | 'choices' => array( |
||
201 | '640x360' => __( '640 x 360', 'foogallery' ), |
||
202 | '854x480' => __( '854 x 480', 'foogallery' ), |
||
203 | '960x540' => __( '960 x 540', 'foogallery' ), |
||
204 | '1024x576' => __( '1024 x 576', 'foogallery' ), |
||
205 | '1280x720' => __( '1280 x 720 (HD)', 'foogallery' ), |
||
206 | '1366x768' => __( '1366 x 768', 'foogallery' ), |
||
207 | '1600x900' => __( '1600 x 900', 'foogallery' ), |
||
208 | '1920x1080' => __( '1920 x 1080 (Full HD)', 'foogallery' ), |
||
209 | ), |
||
210 | ); |
||
211 | |||
212 | $fields[] = array( |
||
213 | 'id' => 'video_autoplay', |
||
214 | 'section' => __( 'Video', 'foogallery' ), |
||
215 | 'title' => __( 'Lightbox Autoplay', 'foogallery' ), |
||
216 | 'desc' => __( 'Try to autoplay the video when opened in a lightbox. This will only work with videos hosted on Youtube or Vimeo.', 'foogallery' ), |
||
217 | 'type' => 'radio', |
||
218 | 'default' => 'yes', |
||
219 | 'spacer' => '<span class="spacer"></span>', |
||
220 | 'choices' => array( |
||
221 | 'yes' => __( 'Yes', 'foogallery' ), |
||
222 | 'no' => __( 'No', 'foogallery' ), |
||
223 | ), |
||
224 | ); |
||
225 | |||
226 | return $fields; |
||
227 | } |
||
228 | |||
229 | public function set_video_flag_on_attachment( $foogallery_attachment, $post ) { |
||
0 ignored issues
–
show
|
|||
230 | $foogallery_attachment->is_video = false; |
||
231 | |||
232 | if ( foogallery_is_attachment_video( $foogallery_attachment ) ) { |
||
233 | $foogallery_attachment->is_video = true; |
||
234 | } |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * @uses "foogallery_attachment_html_item_classes" filter |
||
239 | * |
||
240 | * @param $classes |
||
241 | * @param $args |
||
242 | * @param object|FooGalleryAttachment $attachment |
||
243 | * |
||
244 | * @return mixed |
||
245 | */ |
||
246 | public function alter_video_item_attributes( $classes, $attachment, $args ) { |
||
0 ignored issues
–
show
|
|||
247 | if ( $attachment->is_video ) { |
||
248 | $classes[] = 'fg-video'; |
||
249 | } |
||
250 | |||
251 | return $classes; |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * @uses "foogallery_attachment_html_link_attributes" filter |
||
256 | * |
||
257 | * @param $attr |
||
258 | * @param $args |
||
259 | * @param object|FooGalleryAttachment $attachment |
||
260 | * |
||
261 | * @return mixed |
||
262 | */ |
||
263 | public function alter_video_link_attributes( $attr, $args, $attachment ) { |
||
264 | global $current_foogallery; |
||
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
265 | global $current_foogallery_template; |
||
266 | global $current_foogallery_album; |
||
267 | |||
268 | if ( $attachment->is_video ) { |
||
269 | $video_data = get_post_meta( $attachment->ID, FOOGALLERY_VIDEO_POST_META, true ); |
||
270 | |||
271 | if ( empty( $video_data ) ) { |
||
272 | //get out early if we have no video data |
||
273 | return $attr; |
||
274 | } |
||
275 | |||
276 | $current_foogallery->has_videos = true; |
||
277 | |||
278 | $is_embed = false; |
||
279 | |||
280 | if ( isset( $video_data['type'] ) ) { |
||
281 | |||
282 | $is_embed = 'embed' === $video_data['type']; |
||
283 | |||
284 | $template_supports_embeds = false; |
||
285 | |||
286 | if ( isset( $current_foogallery_template ) ) { |
||
287 | //check that the gallery template supports embeds |
||
288 | $template_data = foogallery_get_gallery_template( $current_foogallery_template ); |
||
289 | |||
290 | $template_supports_embeds = $template_data && array_key_exists( 'embed_support', $template_data ) && true === $template_data['embed_support']; |
||
291 | } |
||
292 | |||
293 | //check the template supports embeds |
||
294 | if ( $template_supports_embeds ) { |
||
295 | //do nothing |
||
296 | $attr['data-type'] = $is_embed ? 'embed' : 'video'; |
||
297 | } else { |
||
298 | //should be for templates that do not support embeds natively e.g. responsive gallery |
||
299 | //we need to check that the lightbox is FooBox, because embeds will only then work with FooBox |
||
300 | |||
301 | $lightbox = ''; |
||
302 | if ( isset( $current_foogallery_template ) ) { |
||
303 | $lightbox = foogallery_gallery_template_setting( 'lightbox' ); |
||
304 | } else if ( isset( $current_foogallery_album ) ) { |
||
305 | $lightbox = foogallery_album_template_setting( 'lightbox' ); |
||
306 | } |
||
307 | |||
308 | $is_embed = $is_embed && ( 'foobox' === $lightbox ); |
||
309 | if ( $is_embed ) { |
||
310 | $attr['data-type'] = 'embed'; |
||
311 | } |
||
312 | } |
||
313 | } |
||
314 | |||
315 | //set the cover image for the video |
||
316 | $attr['data-cover'] = $attachment->url; |
||
317 | |||
318 | //if we have no widths or heights then use video default size |
||
319 | if ( ! isset( $attr['data-width'] ) ) { |
||
320 | $size = foogallery_gallery_template_setting( 'video_size', '640x360' ); |
||
321 | list( $width, $height ) = explode( 'x', $size ); |
||
322 | $attr['data-width'] = $width; |
||
323 | $attr['data-height'] = $height; |
||
324 | } |
||
325 | |||
326 | //override width |
||
327 | $override_width = get_post_meta( $attachment->ID, '_data-width', true ); |
||
328 | if ( ! empty( $override_width ) ) { |
||
329 | $attr['data-width'] = intval( $override_width ); |
||
330 | } |
||
331 | |||
332 | //override height |
||
333 | $override_height = get_post_meta( $attachment->ID, '_data-height', true ); |
||
334 | if ( ! empty( $override_height ) ) { |
||
335 | $attr['data-height'] = intval( $override_height ); |
||
336 | } |
||
337 | |||
338 | //make some changes for embeds |
||
339 | if ( $is_embed ) { |
||
340 | |||
341 | $args = array(); |
||
342 | if ( isset( $attr['data-width'] ) ) { |
||
343 | $args['width'] = $attr['data-width']; |
||
344 | } |
||
345 | |||
346 | $oembed_data = foogallery_oembed_get_data( $attachment->custom_url, $args ); |
||
347 | |||
348 | $data = array( |
||
349 | 'id' => 'foogallery_embed_'.$current_foogallery->ID . '-' . $attachment->ID, |
||
350 | 'attachment_id' => $attachment->ID, |
||
351 | 'url' => $attachment->custom_url, |
||
352 | 'provider' => $video_data['provider'], |
||
353 | 'html' => $oembed_data->html |
||
354 | ); |
||
355 | |||
356 | $current_foogallery->video_embeds[] = $data; |
||
357 | |||
358 | $attr['href'] = '#' . $data['id']; |
||
359 | //make sure FooBox opens the embed |
||
360 | $attr['target'] = 'foobox'; |
||
361 | } else { |
||
362 | $attr['href'] = foogallery_get_video_url_from_attachment( $attachment ); |
||
363 | } |
||
364 | |||
365 | if ( isset( $current_foogallery_template ) ) { |
||
366 | $lightbox = foogallery_gallery_template_setting( 'lightbox', 'unknown' ); |
||
367 | //if no lightbox is being used then force to open in new tab |
||
368 | if ( 'unknown' === $lightbox || 'none' === $lightbox ) { |
||
369 | $attr['target'] = '_blank'; |
||
370 | } |
||
371 | |||
372 | //remove the targets for slider and grid pro galleries |
||
373 | if ( array_key_exists( 'target', $attr ) && 'slider' === $current_foogallery_template || 'foogridpro' === $current_foogallery_template ) { |
||
374 | unset( $attr['target'] ); |
||
375 | } |
||
376 | } |
||
377 | } |
||
378 | |||
379 | return $attr; |
||
380 | } |
||
381 | |||
382 | public function foogallery_build_class_attribute( $classes ) { |
||
383 | global $current_foogallery; |
||
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
384 | |||
385 | //first determine if the gallery has any videos |
||
386 | if ( 0 === foogallery_get_gallery_video_count( $current_foogallery->ID ) ) { |
||
387 | return $classes; |
||
388 | } |
||
389 | |||
390 | $current_foogallery->has_videos = true; |
||
391 | |||
392 | //get the selected video icon |
||
393 | $classes[] = foogallery_gallery_template_setting( 'video_hover_icon', 'fg-video-default' ); |
||
394 | |||
395 | //include the video sticky class |
||
396 | $classes[] = foogallery_gallery_template_setting( 'video_sticky_icon', '' );; |
||
397 | |||
398 | return $classes; |
||
399 | } |
||
400 | |||
401 | /** |
||
402 | * Enqueue any script or stylesheet file dependencies that FooGallery_Pro_Video relies on |
||
403 | * |
||
404 | * @param $foogallery FooGallery |
||
405 | */ |
||
406 | function enqueue_foobox_free_dependencies( $foogallery ) { |
||
0 ignored issues
–
show
|
|||
407 | if ( $foogallery ) { |
||
408 | $video_count = foogallery_get_gallery_video_count( $foogallery->ID ); |
||
409 | |||
410 | if ( $video_count > 0 ) { |
||
411 | |||
412 | $lightbox = foogallery_gallery_template_setting( 'lightbox', 'unknown' ); |
||
413 | //we want to add some JS to the front-end ONLY if we are using FooBox Free |
||
414 | |||
415 | if ( class_exists( 'Foobox_Free' ) && ( 'foobox' == $lightbox || 'foobox-free' == $lightbox ) ) { |
||
416 | $js = FOOGALLERY_PRO_URL . 'js/foobox.video.min.js'; |
||
417 | wp_enqueue_script( |
||
418 | 'foogallery-foobox-video', |
||
419 | $js, |
||
420 | array( 'jquery', 'foobox-free-min' ), |
||
421 | FOOGALLERY_VERSION |
||
422 | ); |
||
423 | } |
||
424 | } |
||
425 | } |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Enqueue any script or stylesheet file dependencies that FooGallery_Pro_Video relies on for an album |
||
430 | * |
||
431 | * @param $foogallery_album FooGalleryAlbum |
||
432 | */ |
||
433 | function enqueue_foobox_free_dependencies_for_album( $foogallery_album ) { |
||
0 ignored issues
–
show
|
|||
434 | if ( $foogallery_album ) { |
||
435 | if ( apply_filters( 'foogallery_albums_supports_video-' . $foogallery_album->album_template, false ) ) { |
||
436 | $video_count = 0; |
||
437 | foreach ( $foogallery_album->gallery_ids as $gallery_id ) { |
||
438 | $video_count += foogallery_get_gallery_video_count( $gallery_id ); |
||
439 | } |
||
440 | if ( $video_count > 0 ) { |
||
441 | $lightbox = foogallery_album_template_setting( 'lightbox', 'unknown' ); |
||
442 | //we want to add some JS to the front-end ONLY if we are using FooBox Free |
||
443 | if ( class_exists( 'Foobox_Free' ) && ( 'foobox' == $lightbox || 'foobox-free' == $lightbox ) ) { |
||
444 | $js = FOOGALLERY_PRO_URL . 'js/foobox.video.min.js'; |
||
445 | wp_enqueue_script( |
||
446 | 'foogallery-foobox-video', |
||
447 | $js, |
||
448 | array( 'jquery', 'foobox-free-min' ), |
||
449 | FOOGALLERY_VERSION |
||
450 | ); |
||
451 | } |
||
452 | } |
||
453 | } |
||
454 | } |
||
455 | } |
||
456 | |||
457 | public function calculate_video_count( $post_id ) { |
||
458 | foogallery_set_gallery_video_count( $post_id ); |
||
459 | } |
||
460 | |||
461 | public function include_video_count( $image_count_text, $gallery ) { |
||
462 | $count = sizeof( $gallery->attachment_ids ); |
||
463 | $video_count = foogallery_get_gallery_video_count( $gallery->ID ); |
||
464 | $image_count = $count - $video_count; |
||
465 | |||
466 | return foogallery_gallery_image_count_text( $count, $image_count, $video_count ); |
||
467 | } |
||
468 | |||
469 | public function include_video_settings( $settings ) { |
||
470 | |||
471 | $settings['tabs']['video'] = __( 'Video', 'foogallery' ); |
||
472 | |||
473 | $settings['settings'][] = array( |
||
474 | 'id' => 'video_default_target', |
||
475 | 'title' => __( 'Default Video Target', 'foogallery' ), |
||
476 | 'desc' => __( 'The default target set for a video when it is imported into the gallery.', 'foogallery' ), |
||
477 | 'type' => 'select', |
||
478 | 'default' => '_blank', |
||
479 | 'tab' => 'video', |
||
480 | 'choices' => array( |
||
481 | 'default' => __( 'Default', 'foogallery' ), |
||
482 | '_blank' => __( 'New tab (_blank)', 'foogallery' ), |
||
483 | '_self' => __( 'Same tab (_self)', 'foogallery' ), |
||
484 | 'foobox' => __( 'FooBox', 'foogallery' ), |
||
485 | ), |
||
486 | ); |
||
487 | |||
488 | $settings['settings'][] = array( |
||
489 | 'id' => 'vimeo_access_token', |
||
490 | 'title' => __( 'Vimeo Access Token', 'foogallery' ), |
||
491 | 'desc' => __( 'An access token is required by the Vimeo API in order to import multiple videos from channels, albums or a user. This is not required to import a single video.', 'foogallery' ), |
||
492 | 'type' => 'text', |
||
493 | 'default' => '', |
||
494 | 'tab' => 'video', |
||
495 | ); |
||
496 | |||
497 | $settings['settings'][] = array( |
||
498 | 'id' => 'language_video_count_none_text', |
||
499 | 'title' => __( 'Video Count None Text', 'foogallery' ), |
||
500 | 'type' => 'text', |
||
501 | 'default' => __( 'No images or videos', 'foogallery' ), |
||
502 | 'tab' => 'language', |
||
503 | ); |
||
504 | $settings['settings'][] = array( |
||
505 | 'id' => 'language_video_count_single_text', |
||
506 | 'title' => __( 'Video Count Single Text', 'foogallery' ), |
||
507 | 'type' => 'text', |
||
508 | 'default' => __( '1 video', 'foogallery' ), |
||
509 | 'tab' => 'language', |
||
510 | ); |
||
511 | $settings['settings'][] = array( |
||
512 | 'id' => 'language_video_count_plural_text', |
||
513 | 'title' => __( 'Video Count Many Text', 'foogallery' ), |
||
514 | 'type' => 'text', |
||
515 | 'default' => __( '%s videos', 'foogallery' ), |
||
516 | 'tab' => 'language', |
||
517 | ); |
||
518 | |||
519 | return $settings; |
||
520 | } |
||
521 | |||
522 | |||
523 | /** |
||
524 | * Renders any video embeds for the gallery |
||
525 | * |
||
526 | * @param FooGallery $gallery |
||
527 | */ |
||
528 | function include_video_embeds( $gallery ) { |
||
0 ignored issues
–
show
|
|||
529 | if ( isset( $gallery->has_videos ) && $gallery->has_videos && isset( $gallery->video_embeds ) ) { |
||
530 | |||
531 | ?> |
||
532 | <div style="display: none;"><?php |
||
533 | |||
534 | foreach ( $gallery->video_embeds as $embed ) { |
||
535 | ?> |
||
536 | <div id="<?php echo $embed['id']; ?>" data-provider="<?php echo $embed['provider']; ?>"> |
||
537 | <?php echo $embed['html']; ?> |
||
538 | </div> |
||
539 | <?php |
||
540 | } |
||
541 | |||
542 | ?></div><?php |
||
543 | } |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * Renders any video embeds for the album |
||
548 | * |
||
549 | * @param FooGalleryAlbum $album |
||
550 | */ |
||
551 | function include_video_embeds_for_album( $album ) { |
||
0 ignored issues
–
show
|
|||
552 | foreach ( $album->galleries() as $gallery ) { |
||
553 | $this->include_video_embeds( $gallery ); |
||
554 | } |
||
555 | } |
||
556 | |||
557 | /** |
||
558 | * Save the Vimeo Access Token to the foogallery settings |
||
559 | */ |
||
560 | function save_vimeo_access_token() { |
||
0 ignored issues
–
show
|
|||
561 | $nonce = !empty($_POST["fgi_nonce"]) ? $_POST["fgi_nonce"] : null; |
||
562 | |||
563 | if (wp_verify_nonce($nonce, "fgi_nonce")) { |
||
564 | $access_token = !empty( $_POST["access_token"] ) ? $_POST["access_token"] : null; |
||
565 | |||
566 | foogallery_settings_set_vimeo_access_token( $access_token ); |
||
567 | wp_send_json_success( __('Saved successfully.', 'foogallery' ) ); |
||
568 | } |
||
569 | die(); |
||
570 | } |
||
571 | } |
||
572 | } |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.