Completed
Push — master ( babeed...92cdcd )
by Zack
11s
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 36 and the first side effect is on line 25.

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