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/video-support ( 96814b...15721f )
by Brad
02:48
created

FooGallery_FooVideo_Compatibility::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * Offers FooVideo users a discount on FooGallery PRO
4
 */
5
if ( ! class_exists( 'FooGallery_FooVideo_Compatibility' ) ) {
6
7
	class FooGallery_FooVideo_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...
8
9
		const option_discount_key = 'foogallery_video_discount';
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
			//check if the old FooVideo is still activated
13
			if ( is_admin() && $this->show_discount_message() ) {
14
				add_action( 'admin_notices', array( $this, 'display_discount_notice') );
15
				add_action( 'admin_menu',  array( $this, 'add_discount_menu' ) );
16
17
				// Ajax calls
18
				add_action( 'wp_ajax_foogallery_video_discount_offer', array( $this, 'ajax_foogallery_video_discount_offer' ) );
19
				add_action( 'wp_ajax_foogallery_video_discount_offer_support', array( $this, 'ajax_foogallery_video_discount_offer_support' ) );
20
				add_action( 'wp_ajax_foogallery_video_discount_offer_hide', array( $this, 'ajax_foogallery_video_discount_offer_hide' ) );
21
22
				add_action( 'wp_ajax_foogallery_video_discount_dismiss', array( $this, 'admin_notice_dismiss' ) );
23
			}
24
		}
25
26
		/**
27
		 * Determines if the discount message should be shown
28
		 *
29
		 * @return bool
30
		 */
31
		function show_discount_message() {
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...
32
			//first try to get the saved option
33
			$show_message = get_option( FooGallery_FooVideo_Compatibility::option_discount_key, 0 );
34
35
			if ( '3' === $show_message ) {
36
				return false;
37
			}
38
39
			//we must show the message - get out early
40
			if ( 0 !== $show_message ) {
41
				return true;
42
			}
43
44
			if ( class_exists('Foo_Video') ) {
45
				//the legacy plugin is installed, so set the option for future use
46
				$show_message = true;
47
48
				update_option( FooGallery_FooVideo_Compatibility::option_discount_key, '1' );
49
			}
50
51
			//we have no option saved and no legacy plugin, so no discount available
52
			if ( 0 === $show_message ) {
53
				$show_message = false;
54
			}
55
56
			return $show_message;
57
		}
58
59
		/**
60
		 * Display a message if the FooVideo extension is also installed
61
		 */
62
		function display_discount_notice() {
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...
63
			$show_message = get_option( FooGallery_FooVideo_Compatibility::option_discount_key, 0 );
64
			if ( '1' === $show_message ) {
65
66
				$notice_title   = apply_filters( 'foogallery_foovideo_discount_offer_notice_title', __( 'FooGallery PRO Discount Available!', 'foogallery' ) );
67
				$notice_message = apply_filters( 'foogallery_foovideo_discount_offer_notice_message', __( 'We noticed that you own a license for the older FooVideo extension but not for FooGallery PRO, which has all the awesome features of FooVideo, plus more! And because you already own FooVideo, you are eligible for a discount when upgrading to FooGallery PRO.', 'foogallery' ) );
68
69
				$url = admin_url( add_query_arg( array( 'page' => 'foogallery-video-offer' ), foogallery_admin_menu_parent_slug() ) );
70
				?>
71
				<script type="text/javascript">
72
					(function ($) {
73
						$(document).ready(function () {
74
							$('.foogallery-foovideo-discount-notice.is-dismissible')
75
								.on('click', '.notice-dismiss', function (e) {
76
									e.preventDefault();
77
									$.post(ajaxurl, {
78
										action  : 'foogallery_video_discount_dismiss',
79
										url     : '<?php echo admin_url( 'admin-ajax.php' ); ?>',
80
										_wpnonce: '<?php echo wp_create_nonce( 'foogallery_video_discount_dismiss' ); ?>'
81
									});
82
								});
83
						});
84
					})(jQuery);
85
				</script>
86
				<div class="foogallery-foovideo-discount-notice notice notice-info is-dismissible">
87
					<p>
88
						<strong><?php echo $notice_title; ?></strong><br />
89
						<?php echo $notice_message; ?><br />
90
						<br />
91
						<a class="button button-primary button-large" href="<?php echo $url; ?>"><?php _e( 'Redeem Now!', 'foogallery' ); ?></a>
92
					</p>
93
				</div>
94
				<?php
95
			}
96
		}
97
98
		/**
99
		 * Dismiss the admin notice
100
		 */
101
		function admin_notice_dismiss() {
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...
102
			if ( check_admin_referer( 'foogallery_video_discount_dismiss' ) ) {
103
				update_option( FooGallery_FooVideo_Compatibility::option_discount_key, '2' );
104
			}
105
		}
106
107
		/**
108
		 * Outputs the video discount offer view
109
		 */
110
		function render_video_offer_view() {
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...
111
			require_once 'view-foovideo-offer.php';
112
		}
113
114
		/**
115
		 * Add a new menu item for running the migration
116
		 */
117
		function add_discount_menu() {
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...
118
			$menu = apply_filters( 'foogallery_foovideo_discount_offer_menu', __( 'Discount Offer', 'foogallery' ) );
119
120
			foogallery_add_submenu_page( $menu, 'manage_options', 'foogallery-video-offer', array( $this, 'render_video_offer_view', ) );
121
		}
122
123
		function ajax_foogallery_video_discount_offer() {
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
			if ( check_admin_referer( 'foogallery_video_discount_offer' ) ) {
125
				$license_key = get_site_option( 'foo-video_licensekey' );
126
127
				if ( empty( $license_key ) ) {
128
					_e('There is no FooVideo license key set for this site. Please set it via the FooGallery Settings page under the extensions tab and try again.', 'foogallery');
129
				} else {
130
					$license_url = "http://fooplugins.com/api/{$license_key}/licensekey/";
131
132
					//fetch the license info from FooPlugins.com
133
					$response = wp_remote_get( $license_url, array( 'sslverify' => false ) );
134
135
					if( ! is_wp_error( $response ) ) {
136
137
						if ( $response['response']['code'] == 200 ) {
138
							$license_details = @json_decode( $response['body'], true );
139
140
							if ( isset( $license_details ) ) {
141
								$coupon = $license_details['coupon'];
142
143
								if ( $coupon['valid'] ) {
144
									echo '<h3>' . __( 'Your discount code is : ', 'foogallery' ) . $coupon['code'] . '</h3><br />';
145
									echo 'You can copy the discount code and use it when purchasing FooGallery PRO from the "FooGallery -> Pricing" page.';
146
								} else {
147
									echo '<h4>' .$coupon['code'] . '</h4>';
148
								}
149
150
							}
151
						}
152
					} else {
153
						echo __('Sorry! There was an error retrieving your discount code from our servers. Please log a support ticket and we will help.', 'foogallery');
154
					}
155
156
				}
157
			}
158
			die();
159
		}
160
161
		function ajax_foogallery_video_discount_offer_support() {
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...
162
			if ( check_admin_referer( 'foogallery_video_discount_offer_support' ) ) {
163
				//send the support email!
164
				$message = $_POST['message'];
165
				if ( wp_mail( '[email protected]', 'FooGallery/FooVideo Discount Offer Query', $message ) ) {
166
					echo __('Support email logged successfully!', 'foogallery' );
167
				} else {
168
					echo __('We could not log the ticket. Please email [email protected] directly.', 'foogallery' );
169
				}
170
			}
171
			die();
172
		}
173
174
		function ajax_foogallery_video_discount_offer_hide() {
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...
175
			if ( check_admin_referer( 'foogallery_video_discount_offer_hide' ) ) {
176
				update_option( FooGallery_FooVideo_Compatibility::option_discount_key, '3' );
177
			}
178
			die();
179
		}
180
	}
181
}