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/attachment-taxonomies ( 05a68d...355e81 )
by Brad
03:29
created

FooGallery_Plugin   D

Complexity

Total Complexity 32

Size/Duplication

Total Lines 294
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 28

Importance

Changes 0
Metric Value
dl 0
loc 294
rs 4.8
c 0
b 0
f 0
wmc 32
lcom 1
cbo 28

11 Methods

Rating   Name   Duplication   Size   Complexity  
A get_instance() 0 7 3
B __construct() 0 85 4
B add_foogallery_pro_extension() 0 26 1
B check_for_access_denied() 0 10 5
A override_connect_message_on_update() 0 13 1
A add_freemius_activation_menu() 0 16 2
A is_submenu_visible() 0 7 2
A set_default_extensions_for_multisite_network_activated() 0 13 2
B activate() 0 25 6
A single_activate() 0 16 3
A get_blog_ids() 0 20 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 30.

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.

Loading history...
2
/*
3
Plugin Name: FooGallery
4
Description: FooGallery is the most intuitive and extensible gallery management tool ever created for WordPress
5
Version:     1.4.18
6
Author:      FooPlugins
7
Plugin URI:  https://foo.gallery
8
Author URI:  http://fooplugins.com
9
Text Domain: foogallery
10
License:     GPL-2.0+
11
Domain Path: /languages
12
13
@fs_premium_only /pro/
14
 */
15
16
// If this file is called directly, abort.
17
if ( ! defined( 'WPINC' ) ) {
18
	die;
19
}
20
21
if ( ! class_exists( 'FooGallery_Plugin' ) ) {
22
23
	define( 'FOOGALLERY_SLUG', 'foogallery' );
24
	define( 'FOOGALLERY_PATH', plugin_dir_path( __FILE__ ) );
25
	define( 'FOOGALLERY_URL', plugin_dir_url( __FILE__ ) );
26
	define( 'FOOGALLERY_FILE', __FILE__ );
27
	define( 'FOOGALLERY_VERSION', '1.4.18' );
28
	define( 'FOOGALLERY_SETTINGS_VERSION', '2' );
29
30
	require_once( FOOGALLERY_PATH . 'includes/constants.php' );
31
32
	// Create a helper function for easy SDK access.
33
	function foogallery_fs() {
34
		global $foogallery_fs;
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...
35
36
		if ( ! isset( $foogallery_fs ) ) {
37
			// Include Freemius SDK.
38
			require_once dirname(__FILE__) . '/freemius/start.php';
39
40
			$foogallery_fs = fs_dynamic_init( array(
41
				'id'                => '843',
42
				'slug'              => 'foogallery',
43
				'type'              => 'plugin',
44
				'public_key'        => 'pk_d87616455a835af1d0658699d0192',
45
				'is_premium'        => true,
46
				'has_paid_plans'    => true,
47
				'trial'               => array(
48
					'days'               => 7,
49
					'is_require_payment' => false,
50
				),
51
				'menu'              => array(
52
					'slug'       => 'edit.php?post_type=' . FOOGALLERY_CPT_GALLERY,
53
					'first-path' => 'edit.php?post_type=' . FOOGALLERY_CPT_GALLERY . '&page=' . FOOGALLERY_ADMIN_MENU_HELP_SLUG,
54
					'account'    => true,
55
					'contact'    => false,
56
					'support'    => false,
57
				),
58
			) );
59
		}
60
61
		return $foogallery_fs;
62
	}
63
64
	// Init Freemius.
65
	foogallery_fs();
66
67
	// Signal that SDK was initiated.
68
	do_action( 'foogallery_fs_loaded' );
69
70
71
	require_once( FOOGALLERY_PATH . 'includes/foopluginbase/bootstrapper.php' );
72
73
	/**
74
	 * FooGallery_Plugin class
75
	 *
76
	 * @package   FooGallery
77
	 * @author    Brad Vincent <[email protected]>
78
	 * @license   GPL-2.0+
79
	 * @link      https://github.com/fooplugins/foogallery
80
	 * @copyright 2013 FooPlugins LLC
81
	 */
82
	class FooGallery_Plugin extends Foo_Plugin_Base_v2_4 {
83
84
		private static $instance;
85
86
		public static function get_instance() {
87
			if ( ! isset(self::$instance) && ! (self::$instance instanceof FooGallery_Plugin) ) {
88
				self::$instance = new FooGallery_Plugin();
89
			}
90
91
			return self::$instance;
92
		}
93
94
		/**
95
		 * Initialize the plugin by setting localization, filters, and administration functions.
96
		 */
97
		private function __construct() {
98
99
			//include everything we need!
100
			require_once( FOOGALLERY_PATH . 'includes/includes.php' );
101
102
			register_activation_hook( __FILE__, array( 'FooGallery_Plugin', 'activate' ) );
103
104
			//init FooPluginBase
105
			$this->init( FOOGALLERY_FILE, FOOGALLERY_SLUG, FOOGALLERY_VERSION, 'FooGallery' );
106
107
			//setup text domain
108
			$this->load_plugin_textdomain();
109
110
			//setup gallery post type
111
			new FooGallery_PostTypes();
112
113
			//load any extensions
114
			new FooGallery_Extensions_Loader();
115
116
			if ( is_admin() ) {
117
				new FooGallery_Admin();
118
				add_action( 'wpmu_new_blog', array( $this, 'set_default_extensions_for_multisite_network_activated' ) );
119
				add_action( 'admin_page_access_denied', array( $this, 'check_for_access_denied' ) );
120
				foogallery_fs()->add_filter( 'connect_message_on_update', array( $this, 'override_connect_message_on_update' ), 10, 6 );
121
				foogallery_fs()->add_filter( 'is_submenu_visible', array( $this, 'is_submenu_visible' ), 10, 2 );
122
				foogallery_fs()->add_filter( 'hide_account_tabs', '__return_true' );
123
				add_action( 'foogallery_admin_menu_before', array( $this, 'add_freemius_activation_menu' ) );
124
			} else {
125
				new FooGallery_Public();
126
			}
127
128
			new FooGallery_Thumbnails();
129
130
			new FooGallery_Polylang_Compatibility();
131
132
			new FooGallery_Attachment_Filters();
133
134
			new FooGallery_Retina();
135
136
			new FooGallery_WPThumb_Enhancements();
137
138
			new FooGallery_Animated_Gif_Support();
139
140
			new FooGallery_Cache();
141
142
			new FooGallery_Common_Fields();
143
144
			new FooGallery_LazyLoad();
145
146
			new FooGallery_Paging();
147
148
			new FooGallery_Thumbnail_Dimensions();
149
150
			new FooGallery_FooBox_Support();
151
152
			new FooGallery_Responsive_Lightbox_dFactory_Support();
153
154
			new FooGallery_Attachment_Custom_Class();
155
156
			new FooGallery_Upgrade();
157
158
			new FooGallery_Extensions_Compatibility();
159
160
			new FooGallery_Default_Crop_Position();
161
162
			$checker = new FooGallery_Version_Check();
163
			$checker->wire_up_checker();
164
165
            new FooGallery_Widget_Init();
166
167
            //include the default templates no matter what!
168
            new FooGallery_Default_Templates();
169
170
            new FooGallery_Attachment_Taxonomies();
171
172
			if ( foogallery_fs()->is__premium_only() ) {
173
				if ( foogallery_fs()->can_use_premium_code() ) {
174
					require_once FOOGALLERY_PATH . 'pro/foogallery-pro.php';
175
176
					new FooGallery_Pro();
177
				}
178
			} else {
179
				add_filter( 'foogallery_extensions_for_view', array( $this, 'add_foogallery_pro_extension' ) );
180
			}
181
		}
182
183
		function add_foogallery_pro_extension( $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...
184
185
			$extension = array(
186
				'slug' => 'foogallery-pro',
187
				'class' => 'FooGallery_Pro',
188
				'categories' => array( 'Featured', 'Premium' ),
189
				'title' => 'FooGallery Pro',
190
				'description' => 'The best gallery plugin for WordPress just got even better!',
191
				'price' => '$49',
192
				'author' => 'FooPlugins',
193
				'author_url' => 'http://fooplugins.com',
194
				'thumbnail' => 'https://s3.amazonaws.com/foogallery/extensions/foogallerypro.png',
195
				'tags' => array( 'premium' ),
196
				'source' => 'fooplugins',
197
				"download_button" => array(
198
					"text" => "Start FREE Trial",
199
					"target" => "_self",
200
					"href" => foogallery_fs()->checkout_url( WP_FS__PERIOD_ANNUALLY, true ),
201
					"confirm" => false
202
				)
203
			);
204
205
			array_unshift( $extensions, $extension );
206
207
			return $extensions;
208
		}
209
210
		/**
211
		 * Checks for the access denied page after we have activated/updated the plugin
212
		 */
213
		function check_for_access_denied() {
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...
214
			global $plugin_page;
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...
215
216
			if ( FOOGALLERY_ADMIN_MENU_HELP_SLUG === $plugin_page ||
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
217
				FOOGALLERY_ADMIN_MENU_SETTINGS_SLUG === $plugin_page ||
218
				FOOGALLERY_ADMIN_MENU_EXTENSIONS_SLUG === $plugin_page ||
219
				FOOGALLERY_ADMIN_MENU_SYSTEMINFO_SLUG === $plugin_page) {
220
				//fs_redirect( 'admin.php?page=' . FOOGALLERY_SLUG );
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
221
			}
222
		}
223
224
		/**
225
		 *
226
		 */
227
		function override_connect_message_on_update( $original, $first_name, $plugin_name, $login, $link, $freemius_link ) {
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...
228
229
			return
230
				sprintf( __( 'Hey %s', 'foogallery' ), $first_name ) . '<br>' .
231
				sprintf(
232
					__( '<h2>Thank you for updating to %1$s v%5$s!</h2>Our goal with this update is to make %1$s the best gallery plugin for WordPress, but we need your help!<br><br>We have introduced this opt-in so that you can help us improve %1$s by simply clicking <strong>Allow &amp; Continue</strong>.<br><br>If you opt-in, some data about your usage of %1$s will be sent to %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'foogallery' ),
233
					'<b>' . $plugin_name . '</b>',
234
					'<b>' . $login . '</b>',
235
					$link,
236
					$freemius_link,
237
					FOOGALLERY_VERSION
238
				);
239
		}
240
241
		function add_freemius_activation_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...
242
			global $foogallery_fs;
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...
243
244
			$parent_slug = foogallery_admin_menu_parent_slug();
245
246
			if ( ! $foogallery_fs->is_registered() ) {
247
				add_submenu_page(
248
					$parent_slug,
249
					__( 'FooGallery Opt-In', 'foogallery' ),
250
					__( 'Activation', 'foogallery' ),
251
					'manage_options',
252
					'foogallery-optin',
253
					array( $foogallery_fs, '_connect_page_render' )
254
				);
255
			}
256
		}
257
258
		function is_submenu_visible( $visible, $id ) {
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...
259
			if ( 'addons' === $id ) {
260
				//hide addons submenu for now
261
				$visible = false;
262
			}
263
			return $visible;
264
		}
265
266
		/**
267
		 * Set default extensions when a new site is created in multisite and FooGallery is network activated
268
		 *
269
		 * @since 1.2.5
270
		 *
271
		 * @param int $blog_id The ID of the newly created site
272
		 */
273
		public function set_default_extensions_for_multisite_network_activated( $blog_id ) {
274
			switch_to_blog( $blog_id );
275
276
			if ( false === get_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, false ) ) {
277
				$api = new FooGallery_Extensions_API();
278
279
				$api->auto_activate_extensions();
280
281
				update_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, true );
282
			}
283
284
			restore_current_blog();
285
		}
286
287
		/**
288
		 * Fired when the plugin is activated.
289
		 *
290
		 * @since    1.0.0
291
		 *
292
		 * @param    boolean    $network_wide    True if WPMU superadmin uses
293
		 *                                       "Network Activate" action, false if
294
		 *                                       WPMU is disabled or plugin is
295
		 *                                       activated on an individual blog.
296
		 */
297
		public static function activate( $network_wide ) {
298
			if ( function_exists( 'is_multisite' ) && is_multisite() ) {
299
300
				if ( $network_wide  ) {
301
302
					// Get all blog ids
303
					$blog_ids = self::get_blog_ids();
304
					if ( is_array( $blog_ids ) ) {
305
						foreach ( $blog_ids as $blog_id ) {
306
307
							switch_to_blog( $blog_id );
308
							self::single_activate();
309
						}
310
311
						restore_current_blog();
312
					}
313
314
				} else {
315
					self::single_activate();
316
				}
317
318
			} else {
319
				self::single_activate( false );
320
			}
321
		}
322
323
		/**
324
		 * Fired for each blog when the plugin is activated.
325
		 *
326
		 * @since    1.0.0
327
		 */
328
		private static function single_activate( $multisite = true ) {
329
			if ( false === get_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, false ) ) {
330
				$api = new FooGallery_Extensions_API();
331
332
				$api->auto_activate_extensions();
333
334
				update_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, true );
335
			}
336
			if ( false === $multisite ) {
337
				//Make sure we redirect to the welcome page
338
				set_transient( FOOGALLERY_ACTIVATION_REDIRECT_TRANSIENT_KEY, true, 30 );
339
			}
340
341
			//force a version check on activation to make sure housekeeping is performed
342
			foogallery_perform_version_check();
343
		}
344
345
		/**
346
		 * Get all blog ids of blogs in the current network that are:
347
		 * - not archived
348
		 * - not spam
349
		 * - not deleted
350
		 *
351
		 * @since    1.0.0
352
		 *
353
		 * @return   array|false    The blog ids, false if no matches.
354
		 */
355
		private static function get_blog_ids() {
356
357
			if ( function_exists( 'get_sites' ) ) {
358
359
				$sites = get_sites();
360
				$blog_ids = array();
361
                foreach ( $sites as $site ) {
362
                    $blog_ids[] = $site->blog_id;
363
				}
364
				return $blog_ids;
365
			} else {
366
				//pre WP 3.7 - do this the old way!
367
				global $wpdb;
368
369
				// get an array of blog ids
370
				$sql = "SELECT blog_id FROM $wpdb->blogs WHERE archived = '0' AND spam = '0' AND deleted = '0'";
371
372
				return $wpdb->get_col( $sql );
373
			}
374
		}
375
	}
376
}
377
378
FooGallery_Plugin::get_instance();
379