Completed
Pull Request — master (#827)
by Zack
07:41 queued 04:19
created

gravityview.php (1 issue)

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
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.19.3
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 */
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', '3.5.0' );
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
/** Register hooks that are fired when the plugin is activated and deactivated. */
63
register_activation_hook( __FILE__, array( 'GravityView_Plugin', 'activate' ) );
64
65
register_deactivation_hook( __FILE__, array( 'GravityView_Plugin', 'deactivate' ) );
66
67
/**
68
 * GravityView_Plugin main class.
69
 */
70
final class GravityView_Plugin {
71
72
	const version = '1.19.3';
73
74
	private static $instance;
75
76
	/**
77
	 * Singleton instance
78
	 *
79
	 * @return GravityView_Plugin   GravityView_Plugin object
80
	 */
81
	public static function getInstance() {
82
83
		if( empty( self::$instance ) ) {
84
			self::$instance = new self;
85
		}
86
87
		return self::$instance;
88
	}
89
90
	private function __construct() {
91
92
		self::require_files();
93
94
		if( ! GravityView_Compatibility::is_valid() ) {
95
			return;
96
		}
97
98
		$this->include_files();
99
100
		$this->add_hooks();
101
	}
102
103
	/**
104
	 * Include files that are required by the plugin
105
	 * @since 1.18
106
	 */
107
	private static function require_files() {
108
		require_once( GRAVITYVIEW_DIR . 'includes/helper-functions.php' );
109
		require_once( GRAVITYVIEW_DIR . 'includes/class-common.php');
110
		require_once( GRAVITYVIEW_DIR . 'includes/connector-functions.php');
111
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-compatibility.php' );
112
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-roles-capabilities.php' );
113
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-notices.php' );
114
		require_once( GRAVITYVIEW_DIR .'includes/class-admin.php' );
115
		require_once( GRAVITYVIEW_DIR . 'includes/class-post-types.php');
116
		require_once( GRAVITYVIEW_DIR . 'includes/class-cache.php');
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
		// Load fields
140
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-fields.php' );
141
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' );
142
143
		// Load all field files automatically
144
		foreach ( glob( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field*.php' ) as $gv_field_filename ) {
145
			include_once( $gv_field_filename );
146
		}
147
148
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-approval-status.php' );
149
		include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-approval.php' );
150
151
		include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-notes.php' );
152
		include_once( GRAVITYVIEW_DIR .'includes/load-plugin-and-theme-hooks.php' );
153
154
		// Load Extensions
155
		// @todo: Convert to a scan of the directory or a method where this all lives
156
		include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' );
157
		include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.php' );
158
		include_once( GRAVITYVIEW_DIR .'includes/extensions/entry-notes/class-gravityview-field-notes.php' );
159
160
		// Load WordPress Widgets
161
		include_once( GRAVITYVIEW_DIR .'includes/wordpress-widgets/register-wordpress-widgets.php' );
162
163
		// Load GravityView Widgets
164
		include_once( GRAVITYVIEW_DIR .'includes/widgets/register-gravityview-widgets.php' );
165
166
		// Add oEmbed
167
		include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' );
168
169
		// Add logging
170
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-logging.php' );
171
172
		include_once( GRAVITYVIEW_DIR . 'includes/class-ajax.php' );
173
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-settings.php' );
174
		include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' );
175
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' );
176
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' );
177
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */
178
		include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' );
179
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' );
180
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' );
181
		include_once( GRAVITYVIEW_DIR . 'includes/class-gvlogic-shortcode.php' );
182
		include_once( GRAVITYVIEW_DIR . 'includes/presets/register-default-templates.php' );
183
184
	}
185
186
	/**
187
	 * Check whether GravityView is network activated
188
	 * @since 1.7.6
189
	 * @return bool
190
	 */
191
	public static function is_network_activated() {
192
		return is_multisite() && ( function_exists('is_plugin_active_for_network') && is_plugin_active_for_network( 'gravityview/gravityview.php' ) );
193
	}
194
195
196
	/**
197
	 * Plugin activate function.
198
	 *
199
	 * @access public
200
	 * @static
201
	 * @return void
202
	 */
203
	public static function activate() {
204
205
		self::require_files();
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
		flush_rewrite_rules();
237
	}
238
239
	/**
240
	 * Include the extension class
241
	 *
242
	 * @since 1.5.1
243
	 * @return void
244
	 */
245
	public static function include_extension_framework() {
246
		if ( ! class_exists( 'GravityView_Extension' ) ) {
247
			require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-extension.php' );
248
		}
249
	}
250
251
	/**
252
	 * Load GravityView_Widget class
253
	 *
254
	 * @since 1.7.5.1
255
	 */
256
	public static function include_widget_class() {
257
		include_once( GRAVITYVIEW_DIR .'includes/widgets/class-gravityview-widget.php' );
258
	}
259
260
261
	/**
262
	 * Loads the plugin's translated strings.
263
	 *
264
	 * @access public
265
	 * @return void
266
	 */
267
	public function load_plugin_textdomain() {
268
269
		$loaded = load_plugin_textdomain( 'gravityview', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
270
		
271
		if ( ! $loaded ) {
272
			$loaded = load_muplugin_textdomain( 'gravityview', '/languages/' );
273
		}
274
		if ( ! $loaded ) {
275
			$loaded = load_theme_textdomain( 'gravityview', '/languages/' );
276
		}
277
		if ( ! $loaded ) {
278
			$locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' );
279
			$mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo';
280
			load_textdomain( 'gravityview', $mofile );
281
		}
282
283
	}
284
285
	/**
286
	 * Check if is_admin(), and make sure not DOING_AJAX
287
	 * @since 1.7.5
288
	 * @return bool
289
	 */
290
	public static function is_admin() {
291
292
		$doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
293
294
		return is_admin() && ! $doing_ajax;
295
	}
296
297
	/**
298
	 * Function to launch frontend objects
299
	 *
300
	 * @since 1.17 Added $force param
301
	 *
302
	 * @access public
303
	 *
304
	 * @param bool $force Whether to force loading, even if GravityView_Plugin::is_admin() returns true
305
	 *
306
	 * @return void
307
	 */
308
	public function frontend_actions( $force = false ) {
309
310
		if( self::is_admin() && ! $force ) { return; }
311
312
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' );
313
		include_once( GRAVITYVIEW_DIR .'includes/class-template.php' );
314
		include_once( GRAVITYVIEW_DIR .'includes/class-api.php' );
315
		include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' );
316
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
317
0 ignored issues
show
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
318
319
        /**
320
         * When an entry is created, check if we need to update the custom slug meta
321
         * todo: move this to its own class..
322
         */
323
        add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
324
325
		/**
326
		 * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
327
		 *
328
		 * Nice place to insert extensions' frontend stuff
329
		 */
330
		do_action( 'gravityview_include_frontend_actions' );
331
	}
332
333
	/**
334
	 * helper function to define the default widget areas
335
	 * @todo Move somewhere logical
336
	 * @return array definition for default widget areas
337
	 */
338
	public static function get_default_widget_areas() {
339
		$default_areas = array(
340
			array( '1-1' => array( array( 'areaid' => 'top', 'title' => __('Top', 'gravityview' ) , 'subtitle' => '' ) ) ),
341
			array( '1-2' => array( array( 'areaid' => 'left', 'title' => __('Left', 'gravityview') , 'subtitle' => '' ) ), '2-2' => array( array( 'areaid' => 'right', 'title' => __('Right', 'gravityview') , 'subtitle' => '' ) ) ),
342
		);
343
344
		/**
345
		 * @filter `gravityview_widget_active_areas` Array of zones available for widgets to be dropped into
346
		 * @param array $default_areas Definition for default widget areas
347
		 */
348
		return apply_filters( 'gravityview_widget_active_areas', $default_areas );
349
	}
350
351
	/** DEBUG */
352
353
    /**
354
     * Logs messages using Gravity Forms logging add-on
355
     * @param  string $message log message
356
     * @param mixed $data Additional data to display
357
     * @return void
358
     */
359
    public static function log_debug( $message, $data = null ){
360
	    /**
361
	     * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
362
	     * @param string $message Message to display
363
	     * @param mixed $data Supporting data to print alongside it
364
	     */
365
    	do_action( 'gravityview_log_debug', $message, $data );
366
    }
367
368
    /**
369
     * Logs messages using Gravity Forms logging add-on
370
     * @param  string $message log message
371
     * @return void
372
     */
373
    public static function log_error( $message, $data = null ){
374
	    /**
375
	     * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
376
	     * @param string $message Error message to display
377
	     * @param mixed $data Supporting data to print alongside it
378
	     */
379
    	do_action( 'gravityview_log_error', $message, $data );
380
    }
381
382
} // end class GravityView_Plugin
383
384
add_action('plugins_loaded', array('GravityView_Plugin', 'getInstance'), 1);
385