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 — master ( 88f370...1732e9 )
by Brad
06:19
created

make_foobox_default_lightbox()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 2
dl 0
loc 9
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * Adds in better support for FooBox Free and PRO
4
 */
5
6
if ( !class_exists( 'FooGallery_FooBox_Compatibility' ) ) {
7
8
	class FooGallery_FooBox_Compatibility {
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...
9
10
		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...
11
			//we need to make sure outdated versions of FooBox never run in the future
12
			$this->ensure_outdated_foobox_extensions_never_run();
13
14
			//add the FooBox lightbox option no matter if using Free or Pro
15
			add_filter( 'foogallery_gallery_template_field_lightboxes', array($this, 'add_lightbox') );
16
17
			//alter the default lightbox to be foobox
18
			add_filter( 'foogallery_alter_gallery_template_field', array( $this, 'make_foobox_default_lightbox' ), 10, 2 );
19
20
            //allow changing of field values
21
            add_filter( 'foogallery_render_gallery_template_field_value', array( $this, 'check_lightbox_value' ), 10, 4 );
22
23
            if ( class_exists( 'fooboxV2' ) ) {
24
				//FooBox PRO specific functionality
25
26
				//only add FooBox PRO functionality after FooBox version 1.2.29
27
				if ( defined( 'FOOBOX_BASE_VERSION' ) && version_compare( FOOBOX_BASE_VERSION, '1.2.29', '>' ) ) {
28
					add_filter( 'foogallery_attachment_custom_fields', array($this, 'add_panning_fields' ) );
29
					add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'add_panning_attributes' ), 10, 3 );
30
				}
31
32
			} else {
33
				//FooBox Free specific functionality
34
				add_filter( 'foogallery_album_stack_link_class_name', array($this, 'album_stack_link_class_name'));
35
			}
36
		}
37
38
        /***
39
         * Check if we have a lightbox value from FooBox free and change it if foobox free is no longer active
40
         * @param $value
41
         * @param $field
42
         * @param $gallery
43
         * @param $template
44
         *
45
         * @return string
46
         */
47
        function check_lightbox_value($value, $field, $gallery, $template) {
48
49
            if ( isset( $field['lightbox'] ) ) {
50
                if ( 'foobox-free' === $value ) {
51
                    if ( !class_exists( 'Foobox_Free' ) ) {
52
                        return 'foobox';
53
                    }
54
                }
55
            }
56
57
            return $value;
58
        }
59
60
        /**
61
         * Change the default for lightbox if foobox is activated
62
         *
63
         * @param $field
64
         * @param $gallery_template
65
         * @return mixed
66
         */
67
		function make_foobox_default_lightbox( $field, $gallery_template ) {
0 ignored issues
show
Unused Code introduced by
The parameter $gallery_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...
68
		    if ( $this->is_foobox_installed() ) {
69
                if (isset($field['lightbox']) && true === $field['lightbox']) {
70
                    $field['default'] = 'foobox';
71
                }
72
            }
73
74
		    return $field;
75
        }
76
77
		function is_foobox_installed() {
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...
78
		    return class_exists( 'FooBox' ) || class_exists( 'fooboxV2' );
79
        }
80
81
		function ensure_outdated_foobox_extensions_never_run() {
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...
82
			global $foogallery_extensions;
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...
83
84
			//backwards compatibility for older versions of the FooBox Free extension class
85
			if ( class_exists( 'FooGallery_FooBox_Free_Extension' ) ) {
86
				$foogallery_extensions['foobox-image-lightbox'] = $this;
87
			}
88
89
			//backwards compatibility for older versions of the FooBox PRO extension class
90
			if ( class_exists( 'FooGallery_FooBox_Extension' ) ) {
91
				$foogallery_extensions['foobox'] = $this;
92
			}
93
		}
94
95
		function add_lightbox($lightboxes) {
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...
96
			$option_text = __( 'FooBox', 'foogallery' );
97
			if ( !$this->is_foobox_installed() ) {
98
				$option_text .= __( ' (Not installed!)', 'foogallery' );
99
			}
100
101
			$lightboxes['foobox'] = $option_text;
102
			return $lightboxes;
103
		}
104
105
		function album_stack_link_class_name( $class_name ) {
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...
106
			return str_replace( 'foobox-free', 'foobox', $class_name );
107
		}
108
109
		function add_panning_fields( $fields ) {
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...
110
			$fields['foobox_panning'] = array(
111
				'label'       =>  __( 'Panning', 'foogallery' ),
112
				'input'       => 'radio',
113
				'helps'       => __( 'Enable mouse panning for this image in the lightbox.', 'foogallery' ),
114
				'exclusions'  => array( 'audio', 'video' ),
115
				'options'     => array(
116
					'' => __( 'Disabled', 'foogallery' ),
117
					'enabled' => __( 'Enabled', 'foogallery' )
118
				)
119
			);
120
121
			return $fields;
122
		}
123
124
		function add_panning_attributes( $attr, $args, $foogallery_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...
125
126
			$foobox_panning = get_post_meta( $foogallery_attachment->ID, '_foobox_panning', true );
127
128
			if ( !empty( $foobox_panning ) ) {
129
				//add data-overflow="true" + data-proportion="false" attributes to the anchor link
130
				$attr['data-overflow'] = 'true';
131
				$attr['data-proportion'] = 'false';
132
			}
133
134
			return $attr;
135
		}
136
	}
137
}