Completed
Push — develop ( 1b9b3e...5c91dc )
by Zack
04:18
created

GravityView_Plugin   A

Complexity

Total Complexity 28

Size/Duplication

Total Lines 298
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 298
rs 10
c 0
b 0
f 0
wmc 28
lcom 1
cbo 3

15 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A __construct() 0 11 2
A add_hooks() 0 7 1
A include_files() 0 50 2
A is_network_activated() 0 3 3
A activate() 0 21 1
A deactivate() 0 5 1
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 6 3
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 27 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.18-beta
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
21
/** Constants */
22
23
/**
24
 * Full path to the GravityView file
25
 * @define "GRAVITYVIEW_FILE" "./gravityview.php"
26
 */
27
define( 'GRAVITYVIEW_FILE', __FILE__ );
28
29
/**
30
 * The URL to this file
31
 */
32
define( 'GRAVITYVIEW_URL', plugin_dir_url( __FILE__ ) );
33
34
35
/** @define "GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory */
36
define( 'GRAVITYVIEW_DIR', plugin_dir_path( __FILE__ ) );
37
38
/**
39
 * GravityView requires at least this version of Gravity Forms to function properly.
40
 */
41
define( 'GV_MIN_GF_VERSION', '1.9.14' );
42
43
/**
44
 * GravityView requires at least this version of WordPress to function properly.
45
 * @since 1.12
46
 */
47
define( 'GV_MIN_WP_VERSION', '3.3' );
48
49
/**
50
 * GravityView requires at least this version of PHP to function properly.
51
 * @since 1.12
52
 */
53
define( 'GV_MIN_PHP_VERSION', '5.2.4' );
54
55
/** Load common & connector functions */
56
require_once( GRAVITYVIEW_DIR . 'includes/helper-functions.php' );
57
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...
58
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...
59
require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-compatibility.php' );
60
require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-roles-capabilities.php' );
61
require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-notices.php' );
62
63
/** Register Post Types and Rewrite Rules */
64
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...
65
66
/** Add Cache Class */
67
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...
68
69
/** Register hooks that are fired when the plugin is activated and deactivated. */
70
if( is_admin() ) {
71
	register_activation_hook( __FILE__, array( 'GravityView_Plugin', 'activate' ) );
72
	register_deactivation_hook( __FILE__, array( 'GravityView_Plugin', 'deactivate' ) );
73
}
74
75
/**
76
 * GravityView_Plugin main class.
77
 */
78
final class GravityView_Plugin {
79
80
	const version = '1.18-beta';
81
82
	private static $instance;
83
84
	/**
85
	 * Singleton instance
86
	 *
87
	 * @return GravityView_Plugin   GravityView_Plugin object
88
	 */
89
	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...
90
91
		if( empty( self::$instance ) ) {
92
			self::$instance = new self;
93
		}
94
95
		return self::$instance;
96
	}
97
98
	private function __construct() {
99
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
100
101
		if( ! GravityView_Compatibility::is_valid() ) {
102
			return;
103
		}
104
105
		$this->include_files();
106
107
		$this->add_hooks();
108
	}
109
110
	/**
111
	 * Add hooks to set up the plugin
112
	 *
113
	 * @since 1.12
114
	 */
115
	private function add_hooks() {
116
		// Load plugin text domain
117
		add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 );
118
119
		// Load frontend files
120
		add_action( 'init', array( $this, 'frontend_actions' ), 20 );
121
	}
122
123
	/**
124
	 * Include global plugin files
125
	 *
126
	 * @since 1.12
127
	 */
128
	public function include_files() {
129
130
		include_once( GRAVITYVIEW_DIR .'includes/class-admin.php' );
131
132
		// Load fields
133
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-fields.php' );
134
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' );
135
136
		// Load all field files automatically
137
		foreach ( glob( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field*.php' ) as $gv_field_filename ) {
138
			include_once( $gv_field_filename );
139
		}
140
141
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-approval-status.php' );
142
		include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-approval.php' );
143
144
		include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-notes.php' );
145
		include_once( GRAVITYVIEW_DIR .'includes/load-plugin-and-theme-hooks.php' );
146
147
		// Load Extensions
148
		// @todo: Convert to a scan of the directory or a method where this all lives
149
		include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' );
150
		include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.php' );
151
		include_once( GRAVITYVIEW_DIR .'includes/extensions/entry-notes/class-gravityview-field-notes.php' );
152
153
		// Load WordPress Widgets
154
		include_once( GRAVITYVIEW_DIR .'includes/wordpress-widgets/register-wordpress-widgets.php' );
155
156
		// Load GravityView Widgets
157
		include_once( GRAVITYVIEW_DIR .'includes/widgets/register-gravityview-widgets.php' );
158
159
		// Add oEmbed
160
		include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' );
161
162
		// Add logging
163
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-logging.php' );
164
165
		include_once( GRAVITYVIEW_DIR . 'includes/class-ajax.php' );
166
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-settings.php' );
167
		include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' );
168
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' );
169
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' );
170
		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...
171
		include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' );
172
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' );
173
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' );
174
		include_once( GRAVITYVIEW_DIR . 'includes/class-gvlogic-shortcode.php' );
175
		include_once( GRAVITYVIEW_DIR . 'includes/presets/register-default-templates.php' );
176
177
	}
178
179
	/**
180
	 * Check whether GravityView is network activated
181
	 * @since 1.7.6
182
	 * @return bool
183
	 */
184
	public static function is_network_activated() {
185
		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...
186
	}
187
188
189
	/**
190
	 * Plugin activate function.
191
	 *
192
	 * @access public
193
	 * @static
194
	 * @return void
195
	 */
196
	public static function activate() {
197
198
		// register post types
199
		GravityView_Post_Types::init_post_types();
200
201
		// register rewrite rules
202
		GravityView_Post_Types::init_rewrite();
203
204
		flush_rewrite_rules();
205
206
		// Update the current GV version
207
		update_option( 'gv_version', self::version );
208
209
		// Add the transient to redirect to configuration page
210
		set_transient( '_gv_activation_redirect', true, 60 );
211
212
		// Clear settings transient
213
		delete_transient( 'gravityview_edd-activate_valid' );
214
215
		GravityView_Roles_Capabilities::get_instance()->add_caps();
216
	}
217
218
219
	/**
220
	 * Plugin deactivate function.
221
	 *
222
	 * @access public
223
	 * @static
224
	 * @return void
225
	 */
226
	public static function deactivate() {
227
228
		flush_rewrite_rules();
229
230
	}
231
232
	/**
233
	 * Include the extension class
234
	 *
235
	 * @since 1.5.1
236
	 * @return void
237
	 */
238
	public static function include_extension_framework() {
239
		if ( ! class_exists( 'GravityView_Extension' ) ) {
240
			require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-extension.php' );
241
		}
242
	}
243
244
	/**
245
	 * Load GravityView_Widget class
246
	 *
247
	 * @since 1.7.5.1
248
	 */
249
	public static function include_widget_class() {
250
		include_once( GRAVITYVIEW_DIR .'includes/widgets/class-gravityview-widget.php' );
251
	}
252
253
254
	/**
255
	 * Loads the plugin's translated strings.
256
	 *
257
	 * @access public
258
	 * @return void
259
	 */
260
	public function load_plugin_textdomain() {
261
262
		$loaded = load_plugin_textdomain( 'gravityview', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
263
		
264
		if ( ! $loaded ) {
265
			$loaded = load_muplugin_textdomain( 'gravityview', '/languages/' );
266
		}
267
		if ( ! $loaded ) {
268
			$loaded = load_theme_textdomain( 'gravityview', '/languages/' );
269
		}
270
		if ( ! $loaded ) {
271
			$locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' );
272
			$mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo';
273
			load_textdomain( 'gravityview', $mofile );
274
		}
275
276
	}
277
278
	/**
279
	 * Check if is_admin(), and make sure not DOING_AJAX
280
	 * @since 1.7.5
281
	 * @return bool
282
	 */
283
	public static function is_admin() {
284
285
		$doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
286
287
		return is_admin() && ! $doing_ajax;
288
	}
289
290
	/**
291
	 * Function to launch frontend objects
292
	 *
293
	 * @since 1.17 Added $force param
294
	 *
295
	 * @access public
296
	 *
297
	 * @param bool $force Whether to force loading, even if GravityView_Plugin::is_admin() returns true
298
	 *
299
	 * @return void
300
	 */
301
	public function frontend_actions( $force = false ) {
302
303
		if( self::is_admin() && ! $force ) { return; }
304
305
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' );
306
		include_once( GRAVITYVIEW_DIR .'includes/class-template.php' );
307
		include_once( GRAVITYVIEW_DIR .'includes/class-api.php' );
308
		include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' );
309
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
310
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
311
312
        /**
313
         * When an entry is created, check if we need to update the custom slug meta
314
         * todo: move this to its own class..
315
         */
316
        add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
317
318
		/**
319
		 * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
320
		 *
321
		 * Nice place to insert extensions' frontend stuff
322
		 */
323
		do_action( 'gravityview_include_frontend_actions' );
324
	}
325
326
	/**
327
	 * helper function to define the default widget areas
328
	 * @todo Move somewhere logical
329
	 * @return array definition for default widget areas
330
	 */
331
	public static function get_default_widget_areas() {
332
		$default_areas = array(
333
			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...
334
			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...
335
		);
336
337
		/**
338
		 * @filter `gravityview_widget_active_areas` Array of zones available for widgets to be dropped into
339
		 * @param array $default_areas Definition for default widget areas
340
		 */
341
		return apply_filters( 'gravityview_widget_active_areas', $default_areas );
342
	}
343
344
	/** DEBUG */
345
346
    /**
347
     * Logs messages using Gravity Forms logging add-on
348
     * @param  string $message log message
349
     * @param mixed $data Additional data to display
350
     * @return void
351
     */
352
    public static function log_debug( $message, $data = null ){
353
	    /**
354
	     * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
355
	     * @param string $message Message to display
356
	     * @param mixed $data Supporting data to print alongside it
357
	     */
358
    	do_action( 'gravityview_log_debug', $message, $data );
359
    }
360
361
    /**
362
     * Logs messages using Gravity Forms logging add-on
363
     * @param  string $message log message
364
     * @return void
365
     */
366
    public static function log_error( $message, $data = null ){
367
	    /**
368
	     * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
369
	     * @param string $message Error message to display
370
	     * @param mixed $data Supporting data to print alongside it
371
	     */
372
    	do_action( 'gravityview_log_error', $message, $data );
373
    }
374
375
} // end class GravityView_Plugin
376
377
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...
378