Completed
Push — master ( 79386d...2cfa6f )
by Zack
18:13 queued 12:52
created

gravityview.php (20 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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.17.4
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.9.10' );
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
Expected 1 spaces before closing bracket; 0 found
Loading history...
58
require_once( GRAVITYVIEW_DIR . 'includes/connector-functions.php');
0 ignored issues
show
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
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
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.17.4';
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
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
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-notes.php' );
142
		include_once( GRAVITYVIEW_DIR .'includes/load-plugin-and-theme-hooks.php' );
143
144
		// Load Extensions
145
		// @todo: Convert to a scan of the directory or a method where this all lives
146
		include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' );
147
		include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.php' );
148
		include_once( GRAVITYVIEW_DIR .'includes/extensions/entry-notes/class-gravityview-field-notes.php' );
149
150
		// Load WordPress Widgets
151
		include_once( GRAVITYVIEW_DIR .'includes/wordpress-widgets/register-wordpress-widgets.php' );
152
153
		// Load GravityView Widgets
154
		include_once( GRAVITYVIEW_DIR .'includes/widgets/register-gravityview-widgets.php' );
155
156
		// Add oEmbed
157
		include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' );
158
159
		// Add logging
160
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-logging.php' );
161
162
		include_once( GRAVITYVIEW_DIR . 'includes/class-ajax.php' );
163
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-settings.php' );
164
		include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' );
165
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' );
166
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' );
167
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */
0 ignored issues
show
Expected 1 spaces before closing bracket; 0 found
Loading history...
168
		include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' );
169
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' );
170
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' );
171
		include_once( GRAVITYVIEW_DIR . 'includes/class-gvlogic-shortcode.php' );
172
		include_once( GRAVITYVIEW_DIR . 'includes/presets/register-default-templates.php' );
173
174
	}
175
176
	/**
177
	 * Check whether GravityView is network activated
178
	 * @since 1.7.6
179
	 * @return bool
180
	 */
181
	public static function is_network_activated() {
182
		return is_multisite() && ( function_exists('is_plugin_active_for_network') && is_plugin_active_for_network( 'gravityview/gravityview.php' ) );
0 ignored issues
show
Expected 1 spaces after opening bracket; 0 found
Loading history...
Expected 1 spaces before closing bracket; 0 found
Loading history...
183
	}
184
185
186
	/**
187
	 * Plugin activate function.
188
	 *
189
	 * @access public
190
	 * @static
191
	 * @return void
192
	 */
193
	public static function activate() {
194
195
		// register post types
196
		GravityView_Post_Types::init_post_types();
197
198
		// register rewrite rules
199
		GravityView_Post_Types::init_rewrite();
200
201
		flush_rewrite_rules();
202
203
		// Update the current GV version
204
		update_option( 'gv_version', self::version );
205
206
		// Add the transient to redirect to configuration page
207
		set_transient( '_gv_activation_redirect', true, 60 );
208
209
		// Clear settings transient
210
		delete_transient( 'gravityview_edd-activate_valid' );
211
212
		GravityView_Roles_Capabilities::get_instance()->add_caps();
213
	}
214
215
216
	/**
217
	 * Plugin deactivate function.
218
	 *
219
	 * @access public
220
	 * @static
221
	 * @return void
222
	 */
223
	public static function deactivate() {
224
225
		flush_rewrite_rules();
226
227
	}
228
229
	/**
230
	 * Include the extension class
231
	 *
232
	 * @since 1.5.1
233
	 * @return void
234
	 */
235
	public static function include_extension_framework() {
236
		if ( ! class_exists( 'GravityView_Extension' ) ) {
237
			require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-extension.php' );
238
		}
239
	}
240
241
	/**
242
	 * Load GravityView_Widget class
243
	 *
244
	 * @since 1.7.5.1
245
	 */
246
	public static function include_widget_class() {
247
		include_once( GRAVITYVIEW_DIR .'includes/widgets/class-gravityview-widget.php' );
248
	}
249
250
251
	/**
252
	 * Loads the plugin's translated strings.
253
	 *
254
	 * @access public
255
	 * @return void
256
	 */
257
	public function load_plugin_textdomain() {
258
259
		$loaded = load_plugin_textdomain( 'gravityview', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
260
		
261
		if ( ! $loaded ) {
262
			$loaded = load_muplugin_textdomain( 'gravityview', '/languages/' );
263
		}
264
		if ( ! $loaded ) {
265
			$loaded = load_theme_textdomain( 'gravityview', '/languages/' );
266
		}
267
		if ( ! $loaded ) {
268
			$locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' );
269
			$mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo';
270
			load_textdomain( 'gravityview', $mofile );
271
		}
272
273
	}
274
275
	/**
276
	 * Check if is_admin(), and make sure not DOING_AJAX
277
	 * @since 1.7.5
278
	 * @return bool
279
	 */
280
	public static function is_admin() {
281
282
		$doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
283
284
		return is_admin() && ! $doing_ajax;
285
	}
286
287
	/**
288
	 * Function to launch frontend objects
289
	 *
290
	 * @since 1.17 Added $force param
291
	 *
292
	 * @access public
293
	 *
294
	 * @param bool $force Whether to force loading, even if GravityView_Plugin::is_admin() returns true
295
	 *
296
	 * @return void
297
	 */
298
	public function frontend_actions( $force = false ) {
299
300
		if( self::is_admin() && ! $force ) { return; }
301
302
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' );
303
		include_once( GRAVITYVIEW_DIR .'includes/class-template.php' );
304
		include_once( GRAVITYVIEW_DIR .'includes/class-api.php' );
305
		include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' );
306
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
307
0 ignored issues
show
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
308
309
        /**
310
         * When an entry is created, check if we need to update the custom slug meta
311
         * todo: move this to its own class..
312
         */
313
        add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
314
315
		/**
316
		 * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
317
		 *
318
		 * Nice place to insert extensions' frontend stuff
319
		 */
320
		do_action( 'gravityview_include_frontend_actions' );
321
	}
322
323
	/**
324
	 * helper function to define the default widget areas
325
	 * @todo Move somewhere logical
326
	 * @return array definition for default widget areas
327
	 */
328
	public static function get_default_widget_areas() {
329
		$default_areas = array(
330
			array( '1-1' => array( array( 'areaid' => 'top', 'title' => __('Top', 'gravityview' ) , 'subtitle' => '' ) ) ),
0 ignored issues
show
Expected 1 spaces after opening bracket; 0 found
Loading history...
Expected 0 spaces between ")" and comma; 1 found
Loading history...
331
			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
Expected 1 spaces after opening bracket; 0 found
Loading history...
Expected 1 spaces before closing bracket; 0 found
Loading history...
Expected 0 spaces between ")" and comma; 1 found
Loading history...
332
		);
333
334
		/**
335
		 * @filter `gravityview_widget_active_areas` Array of zones available for widgets to be dropped into
336
		 * @param array $default_areas Definition for default widget areas
337
		 */
338
		return apply_filters( 'gravityview_widget_active_areas', $default_areas );
339
	}
340
341
	/** DEBUG */
342
343
    /**
344
     * Logs messages using Gravity Forms logging add-on
345
     * @param  string $message log message
346
     * @param mixed $data Additional data to display
347
     * @return void
348
     */
349
    public static function log_debug( $message, $data = null ){
350
	    /**
351
	     * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
352
	     * @param string $message Message to display
353
	     * @param mixed $data Supporting data to print alongside it
354
	     */
355
    	do_action( 'gravityview_log_debug', $message, $data );
356
    }
357
358
    /**
359
     * Logs messages using Gravity Forms logging add-on
360
     * @param  string $message log message
361
     * @return void
362
     */
363
    public static function log_error( $message, $data = null ){
364
	    /**
365
	     * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
366
	     * @param string $message Error message to display
367
	     * @param mixed $data Supporting data to print alongside it
368
	     */
369
    	do_action( 'gravityview_log_error', $message, $data );
370
    }
371
372
} // end class GravityView_Plugin
373
374
add_action('plugins_loaded', array('GravityView_Plugin', 'getInstance'), 1);
0 ignored issues
show
Expected 1 spaces after opening bracket; 0 found
Loading history...
Expected 1 spaces before closing bracket; 0 found
Loading history...
No space after opening parenthesis of array is bad style
Loading history...
No space before closing parenthesis of array is bad style
Loading history...
375