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