Completed
Push — master ( 1fd6be...155036 )
by Zack
13s
created

GravityView_Plugin   B

Complexity

Total Complexity 36

Size/Duplication

Total Lines 352
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 2.33%

Importance

Changes 0
Metric Value
dl 0
loc 352
ccs 3
cts 129
cp 0.0233
rs 8.8
c 0
b 0
f 0
wmc 36
lcom 1
cbo 3

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A __construct() 0 12 2
A require_files() 0 12 1
A add_hooks() 0 7 1
A include_files() 0 49 2
A is_network_activated() 0 3 3
B activate() 0 52 6
A deactivate() 0 5 2
A include_extension_framework() 0 5 2
A include_widget_class() 0 3 1
A load_plugin_textdomain() 0 17 4
A is_admin() 0 10 4
B frontend_actions() 0 24 3
A get_default_widget_areas() 0 12 1
A log_debug() 0 8 1
A log_error() 0 8 1
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 26 and the first side effect is on line 17.

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:       	GravityView
4
 * Plugin URI:        	https://gravityview.co
5
 * Description:       	The best, easiest way to display Gravity Forms entries on your website.
6
 * Version:          	1.22.2
7
 * Author:            	GravityView
8
 * Author URI:        	https://gravityview.co
9
 * Text Domain:       	gravityview
10
 * License:           	GPLv2 or later
11
 * License URI: 		http://www.gnu.org/licenses/gpl-2.0.html
12
 * Domain Path:			/languages
13
 */
14
15
/** If this file is called directly, abort. */
16
if ( ! defined( 'ABSPATH' ) ) {
17
	die;
18
}
19
20
/** Constants */
21
22
/**
23
 * Full path to the GravityView file
24
 * @define "GRAVITYVIEW_FILE" "./gravityview.php"
25
 */
26
define( 'GRAVITYVIEW_FILE', __FILE__ );
27
28
/**
29
 * The URL to this file, with trailing slash
30
 */
31
define( 'GRAVITYVIEW_URL', plugin_dir_url( __FILE__ ) );
32
33
34
/** @define "GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash */
35
define( 'GRAVITYVIEW_DIR', plugin_dir_path( __FILE__ ) );
36
37
/**
38
 * GravityView requires at least this version of Gravity Forms to function properly.
39
 */
40
define( 'GV_MIN_GF_VERSION', '1.9.14' );
41
42
/**
43
 * GravityView requires at least this version of WordPress to function properly.
44
 * @since 1.12
45
 */
46
define( 'GV_MIN_WP_VERSION', '4.4' );
47
48
/**
49
 * GravityView requires at least this version of PHP to function properly.
50
 * @since 1.12
51
 */
52
define( 'GV_MIN_PHP_VERSION', '5.2.4' );
53
54
/**
55
 * GravityView will require this version of PHP soon. False if no future PHP version changes are planned.
56
 * @since 1.19.2
57
 * @var string|false
58
 */
59
define( 'GV_FUTURE_MIN_PHP_VERSION', '5.3' );
60
61
/**
62
 * GravityView will soon require at least this version of Gravity Forms to function properly.
63
 * @since 1.19.4
64
 */
65
define( 'GV_FUTURE_MIN_GF_VERSION', '2.0.0-rc-1' );
66
67
/** Register hooks that are fired when the plugin is activated and deactivated. */
68
register_activation_hook( __FILE__, array( 'GravityView_Plugin', 'activate' ) );
69
70
register_deactivation_hook( __FILE__, array( 'GravityView_Plugin', 'deactivate' ) );
71
72
/**
73
 * The future is here and now... perhaps.
74
 */
75
require GRAVITYVIEW_DIR . 'future/loader.php';
76
77
/**
78
 * GravityView_Plugin main class.
79
 */
80
final class GravityView_Plugin {
81
82
	const version = '1.22.2';
83
84
	private static $instance;
85
86
	/**
87
	 * Singleton instance
88
	 *
89
	 * @return GravityView_Plugin   GravityView_Plugin object
90
	 */
91
	public static function getInstance() {
0 ignored issues
show
Coding Style introduced by
The function name getInstance is in camel caps, but expected get_instance instead as per the coding standard.
Loading history...
92
93
		if( empty( self::$instance ) ) {
94
			self::$instance = new self;
95
		}
96
97
		return self::$instance;
98
	}
99
100
	private function __construct() {
101
102
		self::require_files();
103
104
		if( ! GravityView_Compatibility::is_valid() ) {
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_Compatibility::is_valid() has been deprecated with message: 1.19.4

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
105
			return;
106
		}
107
108
		$this->include_files();
109
110
		$this->add_hooks();
111
	}
112
113
	/**
114
	 * Include files that are required by the plugin
115
	 * @since 1.18
116
	 */
117
	private static function require_files() {
118
		require_once( GRAVITYVIEW_DIR . 'includes/helper-functions.php' );
119
		require_once( GRAVITYVIEW_DIR . 'includes/class-common.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
120
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-html-elements.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
121
		require_once( GRAVITYVIEW_DIR . 'includes/connector-functions.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
122
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-compatibility.php' );
123
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-roles-capabilities.php' );
124
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-notices.php' );
125
		require_once( GRAVITYVIEW_DIR . 'includes/class-admin.php' );
126
		require_once( GRAVITYVIEW_DIR . 'includes/class-post-types.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
127
		require_once( GRAVITYVIEW_DIR . 'includes/class-cache.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
128
	}
129
130
	/**
131
	 * Add hooks to set up the plugin
132
	 *
133
	 * @since 1.12
134
	 */
135
	private function add_hooks() {
136
		// Load plugin text domain
137
		add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 );
138
139
		// Load frontend files
140
		add_action( 'init', array( $this, 'frontend_actions' ), 20 );
141
	}
142
143
	/**
144
	 * Include global plugin files
145
	 *
146
	 * @since 1.12
147
	 */
148
	public function include_files() {
149
150
		// Load fields
151
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-fields.php' );
152
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' );
153
154
		// Load all field files automatically
155
		foreach ( glob( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field*.php' ) as $gv_field_filename ) {
156
			include_once( $gv_field_filename );
157
		}
158
159
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-approval-status.php' );
160
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-approval.php' );
161
162
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-notes.php' );
163
		include_once( GRAVITYVIEW_DIR . 'includes/load-plugin-and-theme-hooks.php' );
164
165
		// Load Extensions
166
		// @todo: Convert to a scan of the directory or a method where this all lives
167
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php' );
168
		include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' );
169
		include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.php' );
170
		include_once( GRAVITYVIEW_DIR .'includes/extensions/entry-notes/class-gravityview-field-notes.php' );
171
172
		// Load WordPress Widgets
173
		include_once( GRAVITYVIEW_DIR . 'includes/wordpress-widgets/register-wordpress-widgets.php' );
174
175
		// Load GravityView Widgets
176
		include_once( GRAVITYVIEW_DIR . 'includes/widgets/register-gravityview-widgets.php' );
177
178
		// Add oEmbed
179
		include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' );
180
181
		// Add logging
182
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-logging.php' );
183
184
		include_once( GRAVITYVIEW_DIR . 'includes/class-ajax.php' );
185
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-settings.php' );
186
		include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' );
187
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' );
188
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' );
189
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
190
		include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' );
191
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' );
192
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' );
193
		include_once( GRAVITYVIEW_DIR . 'includes/class-gvlogic-shortcode.php' );
194
		include_once( GRAVITYVIEW_DIR . 'includes/presets/register-default-templates.php' );
195
196
	}
197
198
	/**
199
	 * Check whether GravityView is network activated
200
	 * @since 1.7.6
201
	 * @return bool
202
	 */
203
	public static function is_network_activated() {
204
		return is_multisite() && ( function_exists('is_plugin_active_for_network') && is_plugin_active_for_network( 'gravityview/gravityview.php' ) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
205
	}
206
207
208
	/**
209
	 * Plugin activate function.
210
	 *
211
	 * @access public
212
	 * @static
213
	 * @return void
214
	 */
215
	public static function activate() {
216
217
		/**
218
		 * Do not allow activation if PHP version is lower than 5.3.
219
		 */
220
		$version = phpversion();
221
		if ( version_compare( $version, '5.3', '<' ) ) {
222
223
			if ( php_sapi_name() == 'cli' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
224
				printf( __( "GravityView requires PHP Version %s or newer. You're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ),
225
					GV_FUTURE_MIN_PHP_VERSION , phpversion() );
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
226
			} else {
227
				printf( '<body style="padding: 0; margin: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">' );
228
				printf( '<img src="' . plugins_url( 'assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ) . '" alt="The GravityView Astronaut Says:" style="float: left; height: 60px; margin-right : 10px;" />' );
229
				printf( __( "%sGravityView requires PHP Version %s or newer.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ),
230
					'<h3 style="font-size:16px; margin: 0 0 8px 0;">', GV_FUTURE_MIN_PHP_VERSION , "</h3>\n\n", $version );
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
231
				printf( '</body>' );
232
			}
233
234
			exit; /** Die without activating. Sorry. */
0 ignored issues
show
Coding Style Compatibility introduced by
The method activate() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
235
		}
236
237
		self::require_files();
238
239
		/** Deprecate in favor of \GV\View::register_post_type. */
240
		if ( ! defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
241
			// register post types
242
			GravityView_Post_Types::init_post_types();
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_Post_Types::init_post_types() has been deprecated.

This method has been deprecated.

Loading history...
243
		}
244
245
		/** Deprecate in favor of \GV\View::add_rewrite_endpoint. */
246
		if ( ! defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
247
			// register rewrite rules
248
			GravityView_Post_Types::init_rewrite();
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_Post_Types::init_rewrite() has been deprecated.

This method has been deprecated.

Loading history...
249
		}
250
251
		/** Deprecate. Handled in \GV\Plugin::activate now. */
252
		if ( ! defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
253
			flush_rewrite_rules();
254
255
			// Update the current GV version
256
			update_option( 'gv_version', self::version );
257
		}
258
259
		// Add the transient to redirect to configuration page
260
		set_transient( '_gv_activation_redirect', true, 60 );
261
262
		// Clear settings transient
263
		delete_transient( 'gravityview_edd-activate_valid' );
264
265
		GravityView_Roles_Capabilities::get_instance()->add_caps();
266
	}
267
268
269
	/**
270
	 * Plugin deactivate function.
271
	 *
272
	 * @access public
273
	 * @deprecated
274
	 * @return void
275
	 */
276
	public static function deactivate() {
277
		if ( ! defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
278
			flush_rewrite_rules();
279
		}
280
	}
281
282
	/**
283
	 * Include the extension class
284
	 *
285
	 * @since 1.5.1
286
	 * @return void
287
	 */
288
	public static function include_extension_framework() {
289
		if ( ! class_exists( 'GravityView_Extension' ) ) {
290
			require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-extension.php' );
291
		}
292
	}
293
294
	/**
295
	 * Load GravityView_Widget class
296
	 *
297
	 * @since 1.7.5.1
298
	 */
299
	public static function include_widget_class() {
300
		include_once( GRAVITYVIEW_DIR .'includes/widgets/class-gravityview-widget.php' );
301
	}
302
303
304
	/**
305
	 * Loads the plugin's translated strings.
306
	 *
307
	 * @access public
308
	 * @return void
309
	 */
310
	public function load_plugin_textdomain() {
311
312
		$loaded = load_plugin_textdomain( 'gravityview', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
313
		
314
		if ( ! $loaded ) {
315
			$loaded = load_muplugin_textdomain( 'gravityview', '/languages/' );
316
		}
317
		if ( ! $loaded ) {
318
			$loaded = load_theme_textdomain( 'gravityview', '/languages/' );
319
		}
320
		if ( ! $loaded ) {
321
			$locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' );
322
			$mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo';
323
			load_textdomain( 'gravityview', $mofile );
324
		}
325
326
	}
327
328
	/**
329
	 * Check if is_admin(), and make sure not DOING_AJAX
330
	 * @since 1.7.5
331
	 * @deprecated
332
	 * @see \GV\Frontend_Request::is_admin via gravityview()->request->is_admin()
333
	 * @return bool
334
	 */
335 2
	public static function is_admin() {
336
337 2
		if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
338 2
			return gravityview()->request->is_admin();
339
		}
340
341
		$doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
342
343
		return is_admin() && ! $doing_ajax;
344
	}
345
346
	/**
347
	 * Function to launch frontend objects
348
	 *
349
	 * @since 1.17 Added $force param
350
	 *
351
	 * @access public
352
	 *
353
	 * @param bool $force Whether to force loading, even if GravityView_Plugin::is_admin() returns true
354
	 *
355
	 * @return void
356
	 */
357
	public function frontend_actions( $force = false ) {
358
359
		if( self::is_admin() && ! $force ) { return; }
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_Plugin::is_admin() has been deprecated.

This method has been deprecated.

Loading history...
360
361
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' );
362
		include_once( GRAVITYVIEW_DIR .'includes/class-template.php' );
363
		include_once( GRAVITYVIEW_DIR .'includes/class-api.php' );
364
		include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' );
365
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
366
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
367
368
        /**
369
         * When an entry is created, check if we need to update the custom slug meta
370
         * todo: move this to its own class..
371
         */
372
        add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
373
374
		/**
375
		 * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
376
		 *
377
		 * Nice place to insert extensions' frontend stuff
378
		 */
379
		do_action( 'gravityview_include_frontend_actions' );
380
	}
381
382
	/**
383
	 * helper function to define the default widget areas
384
	 * @todo Move somewhere logical
385
	 * @return array definition for default widget areas
386
	 */
387
	public static function get_default_widget_areas() {
388
		$default_areas = array(
389
			array( '1-1' => array( array( 'areaid' => 'top', 'title' => __('Top', 'gravityview' ) , 'subtitle' => '' ) ) ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
introduced by
Expected 0 spaces between ")" and comma; 1 found
Loading history...
390
			array( '1-2' => array( array( 'areaid' => 'left', 'title' => __('Left', 'gravityview') , 'subtitle' => '' ) ), '2-2' => array( array( 'areaid' => 'right', 'title' => __('Right', 'gravityview') , 'subtitle' => '' ) ) ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
Expected 0 spaces between ")" and comma; 1 found
Loading history...
391
		);
392
393
		/**
394
		 * @filter `gravityview_widget_active_areas` Array of zones available for widgets to be dropped into
395
		 * @param array $default_areas Definition for default widget areas
396
		 */
397
		return apply_filters( 'gravityview_widget_active_areas', $default_areas );
398
	}
399
400
	/** DEBUG */
401
402
    /**
403
     * Logs messages using Gravity Forms logging add-on
404
     * @param  string $message log message
405
     * @param mixed $data Additional data to display
406
     * @return void
407
     */
408
    public static function log_debug( $message, $data = null ){
409
	    /**
410
	     * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
411
	     * @param string $message Message to display
412
	     * @param mixed $data Supporting data to print alongside it
413
	     */
414
    	do_action( 'gravityview_log_debug', $message, $data );
415
    }
416
417
    /**
418
     * Logs messages using Gravity Forms logging add-on
419
     * @param  string $message log message
420
     * @return void
421
     */
422
    public static function log_error( $message, $data = null ){
423
	    /**
424
	     * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
425
	     * @param string $message Error message to display
426
	     * @param mixed $data Supporting data to print alongside it
427
	     */
428
    	do_action( 'gravityview_log_error', $message, $data );
429
    }
430
431
} // end class GravityView_Plugin
432
433
add_action('plugins_loaded', array('GravityView_Plugin', 'getInstance'), 1);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
434