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 ( 563189...ded6c2 )
by Brad
02:25
created

add_foobox_help_field()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 2
dl 0
loc 39
rs 8.9848
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
            add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_foobox_help_field' ), 99, 2 );
24
25
            if ( class_exists( 'fooboxV2' ) ) {
26
				//FooBox PRO specific functionality
27
28
				//only add FooBox PRO functionality after FooBox version 1.2.29
29
				if ( defined( 'FOOBOX_BASE_VERSION' ) && version_compare( FOOBOX_BASE_VERSION, '1.2.29', '>' ) ) {
30
					add_filter( 'foogallery_attachment_custom_fields', array($this, 'add_panning_fields' ) );
31
					add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'add_panning_attributes' ), 10, 3 );
32
				}
33
34
			} else {
35
				//FooBox Free specific functionality
36
				add_filter( 'foogallery_album_stack_link_class_name', array($this, 'album_stack_link_class_name'));
37
			}
38
		}
39
40
		function add_foobox_help_field( $fields, $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...
41
			//see if the template has a lightbox field
42
			$found_lightbox = false;
43
			$position = 0;
44
			foreach ($fields as $key => &$field) {
45
				if ( 'lightbox' === $field['id'] ) {
46
					$found_lightbox = true;
47
					break;
48
				}
49
				$position++;
50
			}
51
			if ( $found_lightbox && !$this->is_foobox_installed() ) {
52
				$action = 'install-plugin';
53
				$slug = 'foobox-image-lightbox';
54
				$install_url = wp_nonce_url(
55
					add_query_arg(
56
						array(
57
							'action' => $action,
58
							'plugin' => $slug
59
						),
60
						admin_url( 'update.php' )
61
					),
62
					$action.'_'.$slug
63
				);
64
65
				$foobox_help_field = array(
66
					array(
67
						'id'       => 'lightbox_foobox_help',
68
						'title'    => __( 'FooBox Help', 'foogallery' ),
69
						'desc'     => sprintf( __( 'Install our separate FooBox Lightbox plugin so that your gallery images will open in a beautiful responsive lightbox. %s', 'foogallery' ), '<a href="' . $install_url . '" target="_blank">' . __('Install it now!', 'foogallery'). '</a>' ) ,
70
						'section'  => __( 'General', 'foogallery' ),
71
						'type'     => 'help'
72
					)
73
				);
74
75
				array_splice( $fields, $position, 0, $foobox_help_field );
76
			}
77
			return $fields;
78
		}
79
80
        /***
81
         * Check if we have a lightbox value from FooBox free and change it if foobox free is no longer active
82
         * @param $value
83
         * @param $field
84
         * @param $gallery
85
         * @param $template
86
         *
87
         * @return string
88
         */
89
        function check_lightbox_value($value, $field, $gallery, $template) {
90
91
            if ( isset( $field['lightbox'] ) ) {
92
                if ( 'foobox-free' === $value ) {
93
                    if ( !class_exists( 'Foobox_Free' ) ) {
94
                        return 'foobox';
95
                    }
96
                }
97
            }
98
99
            return $value;
100
        }
101
102
        /**
103
         * Change the default for lightbox if foobox is activated
104
         *
105
         * @param $field
106
         * @param $gallery_template
107
         * @return mixed
108
         */
109
		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...
110
		    if ( $this->is_foobox_installed() ) {
111
                if (isset($field['lightbox']) && true === $field['lightbox']) {
112
                    $field['default'] = 'foobox';
113
                }
114
            }
115
116
		    return $field;
117
        }
118
119
		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...
120
		    return class_exists( 'FooBox' ) || class_exists( 'fooboxV2' );
121
        }
122
123
		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...
124
			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...
125
126
			//backwards compatibility for older versions of the FooBox Free extension class
127
			if ( class_exists( 'FooGallery_FooBox_Free_Extension' ) ) {
128
				$foogallery_extensions['foobox-image-lightbox'] = $this;
129
			}
130
131
			//backwards compatibility for older versions of the FooBox PRO extension class
132
			if ( class_exists( 'FooGallery_FooBox_Extension' ) ) {
133
				$foogallery_extensions['foobox'] = $this;
134
			}
135
		}
136
137
		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...
138
			$option_text = __( 'FooBox', 'foogallery' );
139
			if ( !$this->is_foobox_installed() ) {
140
				$option_text .= __( ' (Not installed!)', 'foogallery' );
141
			}
142
143
			$lightboxes['foobox'] = $option_text;
144
			return $lightboxes;
145
		}
146
147
		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...
148
			return str_replace( 'foobox-free', 'foobox', $class_name );
149
		}
150
151
		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...
152
			$fields['foobox_panning'] = array(
153
				'label'       =>  __( 'Panning', 'foogallery' ),
154
				'input'       => 'radio',
155
				'helps'       => __( 'Enable mouse panning for this image in the lightbox.', 'foogallery' ),
156
				'exclusions'  => array( 'audio', 'video' ),
157
				'options'     => array(
158
					'' => __( 'Disabled', 'foogallery' ),
159
					'enabled' => __( 'Enabled', 'foogallery' )
160
				)
161
			);
162
163
			return $fields;
164
		}
165
166
		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...
167
168
			$foobox_panning = get_post_meta( $foogallery_attachment->ID, '_foobox_panning', true );
169
170
			if ( !empty( $foobox_panning ) ) {
171
				//add data-overflow="true" + data-proportion="false" attributes to the anchor link
172
				$attr['data-overflow'] = 'true';
173
				$attr['data-proportion'] = 'false';
174
			}
175
176
			return $attr;
177
		}
178
	}
179
}