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/gallery-template-clien... ( 52bdc8...4fd2a5 )
by Brad
04:37
created

FooGallery_Plugin   C

Complexity

Total Complexity 25

Size/Duplication

Total Lines 212
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 0
Metric Value
dl 0
loc 212
rs 6.875
c 0
b 0
f 0
wmc 25
lcom 1
cbo 19

8 Methods

Rating   Name   Duplication   Size   Complexity  
A get_instance() 0 7 3
A __construct() 0 55 2
B check_for_access_denied() 0 10 5
A override_connect_message_on_update() 0 13 1
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 21 and the first side effect is on line 28.

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.3.7
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
14
// If this file is called directly, abort.
15
if ( ! defined( 'WPINC' ) ) {
16
	die;
17
}
18
19
if ( ! class_exists( 'FooGallery_Plugin' ) ) {
20
21
	define( 'FOOGALLERY_SLUG', 'foogallery' );
22
	define( 'FOOGALLERY_PATH', plugin_dir_path( __FILE__ ) );
23
	define( 'FOOGALLERY_URL', plugin_dir_url( __FILE__ ) );
24
	define( 'FOOGALLERY_FILE', __FILE__ );
25
	define( 'FOOGALLERY_VERSION', '1.3.7' );
26
	define( 'FOOGALLERY_SETTINGS_VERSION', '2' );
27
28
	require_once( FOOGALLERY_PATH . 'includes/constants.php' );
29
30
	// Create a helper function for easy SDK access.
31
	function foogallery_fs() {
32
		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...
33
34
		if ( ! isset( $foogallery_fs ) ) {
35
			// Include Freemius SDK.
36
			require_once dirname(__FILE__) . '/freemius/start.php';
37
38
			$foogallery_fs = fs_dynamic_init( array(
39
				'id'                => '843',
40
				'slug'              => 'foogallery',
41
				'type'              => 'plugin',
42
				'public_key'        => 'pk_d87616455a835af1d0658699d0192',
43
				'is_premium'        => false,
44
				'has_addons'        => false,
45
				'has_paid_plans'    => false,
46
				'menu'              => array(
47
					'slug'       => 'edit.php?post_type=' . FOOGALLERY_CPT_GALLERY,
48
					'first-path' => 'edit.php?post_type=' . FOOGALLERY_CPT_GALLERY . '&page=' . FOOGALLERY_ADMIN_MENU_HELP_SLUG,
49
					'account'    => false,
50
					'contact'    => false,
51
					'support'    => false,
52
				),
53
			) );
54
		}
55
56
		return $foogallery_fs;
57
	}
58
59
	// Init Freemius.
60
	foogallery_fs();
61
62
	// Signal that SDK was initiated.
63
	do_action( 'foogallery_fs_loaded' );
64
65
66
	require_once( FOOGALLERY_PATH . 'includes/foopluginbase/bootstrapper.php' );
67
68
	/**
69
	 * FooGallery_Plugin class
70
	 *
71
	 * @package   FooGallery
72
	 * @author    Brad Vincent <[email protected]>
73
	 * @license   GPL-2.0+
74
	 * @link      https://github.com/fooplugins/foogallery
75
	 * @copyright 2013 FooPlugins LLC
76
	 */
77
	class FooGallery_Plugin extends Foo_Plugin_Base_v2_3 {
78
79
		private static $instance;
80
81
		public static function get_instance() {
82
			if ( ! isset(self::$instance) && ! (self::$instance instanceof FooGallery_Plugin) ) {
83
				self::$instance = new FooGallery_Plugin();
84
			}
85
86
			return self::$instance;
87
		}
88
89
		/**
90
		 * Initialize the plugin by setting localization, filters, and administration functions.
91
		 */
92
		private function __construct() {
93
94
			//include everything we need!
95
			require_once( FOOGALLERY_PATH . 'includes/includes.php' );
96
97
			register_activation_hook( __FILE__, array( 'FooGallery_Plugin', 'activate' ) );
98
99
			//init FooPluginBase
100
			$this->init( FOOGALLERY_FILE, FOOGALLERY_SLUG, FOOGALLERY_VERSION, 'FooGallery' );
101
102
			//setup text domain
103
			$this->load_plugin_textdomain();
104
105
			//setup gallery post type
106
			new FooGallery_PostTypes();
107
108
			//load any extensions
109
			new FooGallery_Extensions_Loader();
110
111
			if ( is_admin() ) {
112
				new FooGallery_Admin();
113
				add_action( 'wpmu_new_blog', array( $this, 'set_default_extensions_for_multisite_network_activated' ) );
114
				add_action( 'admin_page_access_denied', array( $this, 'check_for_access_denied' ) );
115
				foogallery_fs()->add_filter( 'connect_message_on_update', array( $this, 'override_connect_message_on_update' ), 10, 6 );
116
			} else {
117
				new FooGallery_Public();
118
			}
119
120
			new FooGallery_Thumbnails();
121
122
			new FooGallery_Polylang_Compatibility();
123
124
			new FooGallery_Attachment_Filters();
125
126
			new FooGallery_Retina();
127
128
			new FooGallery_WPThumb_Enhancements();
129
130
			new FooGallery_Animated_Gif_Support();
131
132
			new FooGallery_Cache();
133
134
			new FooGallery_LazyLoad();
135
136
			new FooGallery_Thumbnail_Dimensions();
137
138
			new FooGallery_Responsive_Lightbox_dFactory_Support();
139
140
			new FooGallery_Attachment_Custom_Class();
141
142
			new FooGallery_Upgrade();
143
144
			$checker = new FooGallery_Version_Check();
145
			$checker->wire_up_checker();
146
		}
147
148
		/**
149
		 * Checks for the access denied page after we have activated/updated the plugin
150
		 */
151
		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...
152
			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...
153
154
			if ( FOOGALLERY_ADMIN_MENU_HELP_SLUG === $plugin_page ||
155
				FOOGALLERY_ADMIN_MENU_SETTINGS_SLUG === $plugin_page ||
156
				FOOGALLERY_ADMIN_MENU_EXTENSIONS_SLUG === $plugin_page ||
157
				FOOGALLERY_ADMIN_MENU_SYSTEMINFO_SLUG === $plugin_page) {
158
				fs_redirect( 'admin.php?page=' . FOOGALLERY_SLUG );
159
			}
160
		}
161
162
		/**
163
		 *
164
		 */
165
		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...
166
167
			return
168
				sprintf( __( 'Hey %s', 'foogallery' ), $first_name ) . '<br>' .
169
				sprintf(
170
					__( '<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' ),
171
					'<b>' . $plugin_name . '</b>',
172
					'<b>' . $login . '</b>',
173
					$link,
174
					$freemius_link,
175
					FOOGALLERY_VERSION
176
				);
177
		}
178
179
		/**
180
		 * Set default extensions when a new site is created in multisite and FooGallery is network activated
181
		 *
182
		 * @since 1.2.5
183
		 *
184
		 * @param int $blog_id The ID of the newly created site
185
		 */
186
		public function set_default_extensions_for_multisite_network_activated( $blog_id ) {
187
			switch_to_blog( $blog_id );
188
189
			if ( false === get_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, false ) ) {
190
				$api = new FooGallery_Extensions_API();
191
192
				$api->auto_activate_extensions();
193
194
				update_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, true );
195
			}
196
197
			restore_current_blog();
198
		}
199
200
		/**
201
		 * Fired when the plugin is activated.
202
		 *
203
		 * @since    1.0.0
204
		 *
205
		 * @param    boolean    $network_wide    True if WPMU superadmin uses
206
		 *                                       "Network Activate" action, false if
207
		 *                                       WPMU is disabled or plugin is
208
		 *                                       activated on an individual blog.
209
		 */
210
		public static function activate( $network_wide ) {
211
			if ( function_exists( 'is_multisite' ) && is_multisite() ) {
212
213
				if ( $network_wide  ) {
214
215
					// Get all blog ids
216
					$blog_ids = self::get_blog_ids();
217
					if ( is_array( $blog_ids ) ) {
218
						foreach ( $blog_ids as $blog_id ) {
219
220
							switch_to_blog( $blog_id );
221
							self::single_activate();
222
						}
223
224
						restore_current_blog();
225
					}
226
227
				} else {
228
					self::single_activate();
229
				}
230
231
			} else {
232
				self::single_activate( false );
233
			}
234
		}
235
236
		/**
237
		 * Fired for each blog when the plugin is activated.
238
		 *
239
		 * @since    1.0.0
240
		 */
241
		private static function single_activate( $multisite = true ) {
242
			if ( false === get_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, false ) ) {
243
				$api = new FooGallery_Extensions_API();
244
245
				$api->auto_activate_extensions();
246
247
				update_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, true );
248
			}
249
			if ( false === $multisite ) {
250
				//Make sure we redirect to the welcome page
251
				set_transient( FOOGALLERY_ACTIVATION_REDIRECT_TRANSIENT_KEY, true, 30 );
252
			}
253
254
			//force a version check on activation to make sure housekeeping is performed
255
			foogallery_perform_version_check();
256
		}
257
258
		/**
259
		 * Get all blog ids of blogs in the current network that are:
260
		 * - not archived
261
		 * - not spam
262
		 * - not deleted
263
		 *
264
		 * @since    1.0.0
265
		 *
266
		 * @return   array|false    The blog ids, false if no matches.
267
		 */
268
		private static function get_blog_ids() {
269
270
			if ( function_exists( 'wp_get_sites' ) ) {
271
272
				$sites = wp_get_sites();
273
				$blog_ids = array();
274
				foreach ( $sites as $site ) {
275
					$blog_ids[] = $site['blog_id'];
276
				}
277
				return $blog_ids;
278
			} else {
279
				//pre WP 3.7 - do this the old way!
280
				global $wpdb;
281
282
				// get an array of blog ids
283
				$sql = "SELECT blog_id FROM $wpdb->blogs WHERE archived = '0' AND spam = '0' AND deleted = '0'";
284
285
				return $wpdb->get_col( $sql );
286
			}
287
		}
288
	}
289
}
290
291
FooGallery_Plugin::get_instance();
292