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... ( c48b9b...6aeec2 )
by Brad
02:33
created

FooGallery_Plugin::get_blog_ids()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 0
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
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.3.23
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.3.23' );
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_addons'        => false,
47
				'has_paid_plans'    => true,
48
				'trial'               => array(
49
					'days'               => 7,
50
					'is_require_payment' => false,
51
				),
52
				'menu'              => array(
53
					'slug'       => 'edit.php?post_type=' . FOOGALLERY_CPT_GALLERY,
54
					'first-path' => 'edit.php?post_type=' . FOOGALLERY_CPT_GALLERY . '&page=' . FOOGALLERY_ADMIN_MENU_HELP_SLUG,
55
					'account'    => true,
56
					'contact'    => false,
57
					'support'    => false,
58
				),
59
			) );
60
		}
61
62
		return $foogallery_fs;
63
	}
64
65
	// Init Freemius.
66
	foogallery_fs();
67
68
	// Signal that SDK was initiated.
69
	do_action( 'foogallery_fs_loaded' );
70
71
72
	require_once( FOOGALLERY_PATH . 'includes/foopluginbase/bootstrapper.php' );
73
74
	/**
75
	 * FooGallery_Plugin class
76
	 *
77
	 * @package   FooGallery
78
	 * @author    Brad Vincent <[email protected]>
79
	 * @license   GPL-2.0+
80
	 * @link      https://github.com/fooplugins/foogallery
81
	 * @copyright 2013 FooPlugins LLC
82
	 */
83
	class FooGallery_Plugin extends Foo_Plugin_Base_v2_4 {
84
85
		private static $instance;
86
87
		public static function get_instance() {
88
			if ( ! isset(self::$instance) && ! (self::$instance instanceof FooGallery_Plugin) ) {
89
				self::$instance = new FooGallery_Plugin();
90
			}
91
92
			return self::$instance;
93
		}
94
95
		/**
96
		 * Initialize the plugin by setting localization, filters, and administration functions.
97
		 */
98
		private function __construct() {
99
100
			//include everything we need!
101
			require_once( FOOGALLERY_PATH . 'includes/includes.php' );
102
103
			register_activation_hook( __FILE__, array( 'FooGallery_Plugin', 'activate' ) );
104
105
			//init FooPluginBase
106
			$this->init( FOOGALLERY_FILE, FOOGALLERY_SLUG, FOOGALLERY_VERSION, 'FooGallery' );
107
108
			//setup text domain
109
			$this->load_plugin_textdomain();
110
111
			//setup gallery post type
112
			new FooGallery_PostTypes();
113
114
			//load any extensions
115
			new FooGallery_Extensions_Loader();
116
117
			if ( is_admin() ) {
118
				new FooGallery_Admin();
119
				add_action( 'wpmu_new_blog', array( $this, 'set_default_extensions_for_multisite_network_activated' ) );
120
				add_action( 'admin_page_access_denied', array( $this, 'check_for_access_denied' ) );
121
				foogallery_fs()->add_filter( 'connect_message_on_update', array( $this, 'override_connect_message_on_update' ), 10, 6 );
122
				add_action( 'foogallery_admin_menu_before', array( $this, 'add_freemius_activation_menu' ) );
123
			} else {
124
				new FooGallery_Public();
125
			}
126
127
			new FooGallery_Thumbnails();
128
129
			new FooGallery_Polylang_Compatibility();
130
131
			new FooGallery_Attachment_Filters();
132
133
			new FooGallery_Retina();
134
135
			new FooGallery_WPThumb_Enhancements();
136
137
			new FooGallery_Animated_Gif_Support();
138
139
			new FooGallery_Cache();
140
141
			new FooGallery_Common_Fields();
142
143
			new FooGallery_LazyLoad();
144
145
			new FooGallery_Paging();
146
147
			new FooGallery_Thumbnail_Dimensions();
148
149
			new FooGallery_FooBox_Support();
150
151
			new FooGallery_Responsive_Lightbox_dFactory_Support();
152
153
			new FooGallery_Attachment_Custom_Class();
154
155
			new FooGallery_Upgrade();
156
157
			new FooGallery_Extensions_Compatibility();
158
159
			$checker = new FooGallery_Version_Check();
160
			$checker->wire_up_checker();
161
162
			if ( foogallery_fs()->is__premium_only() ) {
163
				if ( foogallery_fs()->can_use_premium_code() ) {
164
					require_once FOOGALLERY_PATH . 'pro/foogallery-pro.php';
165
166
					new FooGallery_Pro();
167
				}
168
			}
169
		}
170
171
		/**
172
		 * Checks for the access denied page after we have activated/updated the plugin
173
		 */
174
		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...
175
			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...
176
177
			if ( FOOGALLERY_ADMIN_MENU_HELP_SLUG === $plugin_page ||
178
				FOOGALLERY_ADMIN_MENU_SETTINGS_SLUG === $plugin_page ||
179
				FOOGALLERY_ADMIN_MENU_EXTENSIONS_SLUG === $plugin_page ||
180
				FOOGALLERY_ADMIN_MENU_SYSTEMINFO_SLUG === $plugin_page) {
181
				fs_redirect( 'admin.php?page=' . FOOGALLERY_SLUG );
182
			}
183
		}
184
185
		/**
186
		 *
187
		 */
188
		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...
189
190
			return
191
				sprintf( __( 'Hey %s', 'foogallery' ), $first_name ) . '<br>' .
192
				sprintf(
193
					__( '<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' ),
194
					'<b>' . $plugin_name . '</b>',
195
					'<b>' . $login . '</b>',
196
					$link,
197
					$freemius_link,
198
					FOOGALLERY_VERSION
199
				);
200
		}
201
202
		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...
203
			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...
204
205
			$parent_slug = foogallery_admin_menu_parent_slug();
206
207
			if ( ! $foogallery_fs->is_registered() ) {
208
				add_submenu_page(
209
					$parent_slug,
210
					__( 'FooGallery Opt-In', 'foogallery' ),
211
					__( 'Activation', 'foogallery' ),
212
					'manage_options',
213
					'foogallery-optin',
214
					array( $foogallery_fs, '_connect_page_render' )
215
				);
216
			}
217
		}
218
219
		/**
220
		 * Set default extensions when a new site is created in multisite and FooGallery is network activated
221
		 *
222
		 * @since 1.2.5
223
		 *
224
		 * @param int $blog_id The ID of the newly created site
225
		 */
226
		public function set_default_extensions_for_multisite_network_activated( $blog_id ) {
227
			switch_to_blog( $blog_id );
228
229
			if ( false === get_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, false ) ) {
230
				$api = new FooGallery_Extensions_API();
231
232
				$api->auto_activate_extensions();
233
234
				update_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, true );
235
			}
236
237
			restore_current_blog();
238
		}
239
240
		/**
241
		 * Fired when the plugin is activated.
242
		 *
243
		 * @since    1.0.0
244
		 *
245
		 * @param    boolean    $network_wide    True if WPMU superadmin uses
246
		 *                                       "Network Activate" action, false if
247
		 *                                       WPMU is disabled or plugin is
248
		 *                                       activated on an individual blog.
249
		 */
250
		public static function activate( $network_wide ) {
251
			if ( function_exists( 'is_multisite' ) && is_multisite() ) {
252
253
				if ( $network_wide  ) {
254
255
					// Get all blog ids
256
					$blog_ids = self::get_blog_ids();
257
					if ( is_array( $blog_ids ) ) {
258
						foreach ( $blog_ids as $blog_id ) {
259
260
							switch_to_blog( $blog_id );
261
							self::single_activate();
262
						}
263
264
						restore_current_blog();
265
					}
266
267
				} else {
268
					self::single_activate();
269
				}
270
271
			} else {
272
				self::single_activate( false );
273
			}
274
		}
275
276
		/**
277
		 * Fired for each blog when the plugin is activated.
278
		 *
279
		 * @since    1.0.0
280
		 */
281
		private static function single_activate( $multisite = true ) {
282
			if ( false === get_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, false ) ) {
283
				$api = new FooGallery_Extensions_API();
284
285
				$api->auto_activate_extensions();
286
287
				update_option( FOOGALLERY_EXTENSIONS_AUTO_ACTIVATED_OPTIONS_KEY, true );
288
			}
289
			if ( false === $multisite ) {
290
				//Make sure we redirect to the welcome page
291
				set_transient( FOOGALLERY_ACTIVATION_REDIRECT_TRANSIENT_KEY, true, 30 );
292
			}
293
294
			//force a version check on activation to make sure housekeeping is performed
295
			foogallery_perform_version_check();
296
		}
297
298
		/**
299
		 * Get all blog ids of blogs in the current network that are:
300
		 * - not archived
301
		 * - not spam
302
		 * - not deleted
303
		 *
304
		 * @since    1.0.0
305
		 *
306
		 * @return   array|false    The blog ids, false if no matches.
307
		 */
308
		private static function get_blog_ids() {
309
310
			if ( function_exists( 'wp_get_sites' ) ) {
311
312
				$sites = wp_get_sites();
313
				$blog_ids = array();
314
				foreach ( $sites as $site ) {
315
					$blog_ids[] = $site['blog_id'];
316
				}
317
				return $blog_ids;
318
			} else {
319
				//pre WP 3.7 - do this the old way!
320
				global $wpdb;
321
322
				// get an array of blog ids
323
				$sql = "SELECT blog_id FROM $wpdb->blogs WHERE archived = '0' AND spam = '0' AND deleted = '0'";
324
325
				return $wpdb->get_col( $sql );
326
			}
327
		}
328
	}
329
}
330
331
FooGallery_Plugin::get_instance();
332