Completed
Push — develop ( b4ca81...4e0664 )
by Zack
09:41
created

gravityview.php (2 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
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.22
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, with trailing slash */
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', '4.4' );
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
 * GravityView will soon require at least this version of Gravity Forms to function properly.
63
 * @since 1.19.4
64
 */
65
define( 'GV_FUTURE_MIN_GF_VERSION', '2.0.0-rc-1' );
66
67
/** Register hooks that are fired when the plugin is activated and deactivated. */
68
register_activation_hook( __FILE__, array( 'GravityView_Plugin', 'activate' ) );
69
70
register_deactivation_hook( __FILE__, array( 'GravityView_Plugin', 'deactivate' ) );
71
72
/**
73
 * The future is here and now... perhaps.
74
 */
75
require GRAVITYVIEW_DIR . 'future/loader.php';
76
77
/**
78
 * GravityView_Plugin main class.
79
 */
80
final class GravityView_Plugin {
81
82
	const version = '1.22.1';
83
84
	private static $instance;
85
86
	/**
87
	 * Singleton instance
88
	 *
89
	 * @return GravityView_Plugin   GravityView_Plugin object
90
	 */
91
	public static function getInstance() {
92
93
		if( empty( self::$instance ) ) {
94
			self::$instance = new self;
95
		}
96
97
		return self::$instance;
98
	}
99
100
	private function __construct() {
101
102
		self::require_files();
103
104
		if( ! GravityView_Compatibility::is_valid() ) {
105
			return;
106
		}
107
108
		$this->include_files();
109
110
		$this->add_hooks();
111
	}
112
113
	/**
114
	 * Include files that are required by the plugin
115
	 * @since 1.18
116
	 */
117
	private static function require_files() {
118
		require_once( GRAVITYVIEW_DIR . 'includes/helper-functions.php' );
119
		require_once( GRAVITYVIEW_DIR . 'includes/class-common.php');
120
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-html-elements.php');
0 ignored issues
show
Expected 1 spaces before closing bracket; 0 found
Loading history...
121
		require_once( GRAVITYVIEW_DIR . 'includes/connector-functions.php');
122
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-compatibility.php' );
123
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-roles-capabilities.php' );
124
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-notices.php' );
125
		require_once( GRAVITYVIEW_DIR . 'includes/class-admin.php' );
126
		require_once( GRAVITYVIEW_DIR . 'includes/class-post-types.php');
127
		require_once( GRAVITYVIEW_DIR . 'includes/class-cache.php');
0 ignored issues
show
Expected 1 spaces before closing bracket; 0 found
Loading history...
128
	}
129
130
	/**
131
	 * Add hooks to set up the plugin
132
	 *
133
	 * @since 1.12
134
	 */
135
	private function add_hooks() {
136
		// Load plugin text domain
137
		add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 );
138
139
		// Load frontend files
140
		add_action( 'init', array( $this, 'frontend_actions' ), 20 );
141
	}
142
143
	/**
144
	 * Include global plugin files
145
	 *
146
	 * @since 1.12
147
	 */
148
	public function include_files() {
149
150
		// Load fields
151
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-fields.php' );
152
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' );
153
154
		// Load all field files automatically
155
		foreach ( glob( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field*.php' ) as $gv_field_filename ) {
156
			include_once( $gv_field_filename );
157
		}
158
159
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-approval-status.php' );
160
		include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-approval.php' );
161
162
		include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-notes.php' );
163
		include_once( GRAVITYVIEW_DIR .'includes/load-plugin-and-theme-hooks.php' );
164
165
		// Load Extensions
166
		// @todo: Convert to a scan of the directory or a method where this all lives
167
		include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' );
168
		include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.php' );
169
		include_once( GRAVITYVIEW_DIR .'includes/extensions/entry-notes/class-gravityview-field-notes.php' );
170
171
		// Load WordPress Widgets
172
		include_once( GRAVITYVIEW_DIR .'includes/wordpress-widgets/register-wordpress-widgets.php' );
173
174
		// Load GravityView Widgets
175
		include_once( GRAVITYVIEW_DIR .'includes/widgets/register-gravityview-widgets.php' );
176
177
		// Add oEmbed
178
		include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' );
179
180
		// Add logging
181
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-logging.php' );
182
183
		include_once( GRAVITYVIEW_DIR . 'includes/class-ajax.php' );
184
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-settings.php' );
185
		include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' );
186
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' );
187
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' );
188
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */
189
		include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' );
190
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' );
191
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' );
192
		include_once( GRAVITYVIEW_DIR . 'includes/class-gvlogic-shortcode.php' );
193
		include_once( GRAVITYVIEW_DIR . 'includes/presets/register-default-templates.php' );
194
195
	}
196
197
	/**
198
	 * Check whether GravityView is network activated
199
	 * @since 1.7.6
200
	 * @return bool
201
	 */
202
	public static function is_network_activated() {
203
		return is_multisite() && ( function_exists('is_plugin_active_for_network') && is_plugin_active_for_network( 'gravityview/gravityview.php' ) );
204
	}
205
206
207
	/**
208
	 * Plugin activate function.
209
	 *
210
	 * @access public
211
	 * @static
212
	 * @return void
213
	 */
214
	public static function activate() {
215
216
		/**
217
		 * Do not allow activation if PHP version is lower than 5.3.
218
		 */
219
		$version = phpversion();
220
		if ( version_compare( $version, '5.3', '<' ) ) {
221
222
			if ( php_sapi_name() == 'cli' ) {
223
				printf( __( "GravityView requires PHP Version %s or newer. You're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ),
224
					GV_FUTURE_MIN_PHP_VERSION , phpversion() );
225
			} else {
226
				printf( '<body style="padding: 0; margin: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">' );
227
				printf( '<img src="' . plugins_url( 'assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ) . '" alt="The GravityView Astronaut Says:" style="float: left; height: 60px; margin-right : 10px;" />' );
228
				printf( __( "%sGravityView requires PHP Version %s or newer.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ),
229
					'<h3 style="font-size:16px; margin: 0 0 8px 0;">', GV_FUTURE_MIN_PHP_VERSION , "</h3>\n\n", $version );
230
				printf( '</body>' );
231
			}
232
233
			exit; /** Die without activating. Sorry. */
234
		}
235
236
		self::require_files();
237
238
		/** Deprecate in favor of \GV\View::register_post_type. */
239
		if ( ! defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
240
			// register post types
241
			GravityView_Post_Types::init_post_types();
242
		}
243
244
		/** Deprecate in favor of \GV\View::add_rewrite_endpoint. */
245
		if ( ! defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
246
			// register rewrite rules
247
			GravityView_Post_Types::init_rewrite();
248
		}
249
250
		/** Deprecate. Handled in \GV\Plugin::activate now. */
251
		if ( ! defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
252
			flush_rewrite_rules();
253
254
			// Update the current GV version
255
			update_option( 'gv_version', self::version );
256
		}
257
258
		// Add the transient to redirect to configuration page
259
		set_transient( '_gv_activation_redirect', true, 60 );
260
261
		// Clear settings transient
262
		delete_transient( 'gravityview_edd-activate_valid' );
263
264
		GravityView_Roles_Capabilities::get_instance()->add_caps();
265
	}
266
267
268
	/**
269
	 * Plugin deactivate function.
270
	 *
271
	 * @access public
272
	 * @deprecated
273
	 * @return void
274
	 */
275
	public static function deactivate() {
276
		if ( ! defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
277
			flush_rewrite_rules();
278
		}
279
	}
280
281
	/**
282
	 * Include the extension class
283
	 *
284
	 * @since 1.5.1
285
	 * @return void
286
	 */
287
	public static function include_extension_framework() {
288
		if ( ! class_exists( 'GravityView_Extension' ) ) {
289
			require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-extension.php' );
290
		}
291
	}
292
293
	/**
294
	 * Load GravityView_Widget class
295
	 *
296
	 * @since 1.7.5.1
297
	 */
298
	public static function include_widget_class() {
299
		include_once( GRAVITYVIEW_DIR .'includes/widgets/class-gravityview-widget.php' );
300
	}
301
302
303
	/**
304
	 * Loads the plugin's translated strings.
305
	 *
306
	 * @access public
307
	 * @return void
308
	 */
309
	public function load_plugin_textdomain() {
310
311
		$loaded = load_plugin_textdomain( 'gravityview', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
312
		
313
		if ( ! $loaded ) {
314
			$loaded = load_muplugin_textdomain( 'gravityview', '/languages/' );
315
		}
316
		if ( ! $loaded ) {
317
			$loaded = load_theme_textdomain( 'gravityview', '/languages/' );
318
		}
319
		if ( ! $loaded ) {
320
			$locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' );
321
			$mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo';
322
			load_textdomain( 'gravityview', $mofile );
323
		}
324
325
	}
326
327
	/**
328
	 * Check if is_admin(), and make sure not DOING_AJAX
329
	 * @since 1.7.5
330
	 * @deprecated
331
	 * @see \GV\Frontend_Request::is_admin via gravityview()->request->is_admin()
332
	 * @return bool
333
	 */
334 2
	public static function is_admin() {
335
336 2
		if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
337 2
			return gravityview()->request->is_admin();
338
		}
339
340
		$doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
341
342
		return is_admin() && ! $doing_ajax;
343
	}
344
345
	/**
346
	 * Function to launch frontend objects
347
	 *
348
	 * @since 1.17 Added $force param
349
	 *
350
	 * @access public
351
	 *
352
	 * @param bool $force Whether to force loading, even if GravityView_Plugin::is_admin() returns true
353
	 *
354
	 * @return void
355
	 */
356
	public function frontend_actions( $force = false ) {
357
358
		if( self::is_admin() && ! $force ) { return; }
359
360
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' );
361
		include_once( GRAVITYVIEW_DIR .'includes/class-template.php' );
362
		include_once( GRAVITYVIEW_DIR .'includes/class-api.php' );
363
		include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' );
364
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
365
366
367
        /**
368
         * When an entry is created, check if we need to update the custom slug meta
369
         * todo: move this to its own class..
370
         */
371
        add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
372
373
		/**
374
		 * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
375
		 *
376
		 * Nice place to insert extensions' frontend stuff
377
		 */
378
		do_action( 'gravityview_include_frontend_actions' );
379
	}
380
381
	/**
382
	 * helper function to define the default widget areas
383
	 * @todo Move somewhere logical
384
	 * @return array definition for default widget areas
385
	 */
386
	public static function get_default_widget_areas() {
387
		$default_areas = array(
388
			array( '1-1' => array( array( 'areaid' => 'top', 'title' => __('Top', 'gravityview' ) , 'subtitle' => '' ) ) ),
389
			array( '1-2' => array( array( 'areaid' => 'left', 'title' => __('Left', 'gravityview') , 'subtitle' => '' ) ), '2-2' => array( array( 'areaid' => 'right', 'title' => __('Right', 'gravityview') , 'subtitle' => '' ) ) ),
390
		);
391
392
		/**
393
		 * @filter `gravityview_widget_active_areas` Array of zones available for widgets to be dropped into
394
		 * @param array $default_areas Definition for default widget areas
395
		 */
396
		return apply_filters( 'gravityview_widget_active_areas', $default_areas );
397
	}
398
399
	/** DEBUG */
400
401
    /**
402
     * Logs messages using Gravity Forms logging add-on
403
     * @param  string $message log message
404
     * @param mixed $data Additional data to display
405
     * @return void
406
     */
407
    public static function log_debug( $message, $data = null ){
408
	    /**
409
	     * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
410
	     * @param string $message Message to display
411
	     * @param mixed $data Supporting data to print alongside it
412
	     */
413
    	do_action( 'gravityview_log_debug', $message, $data );
414
    }
415
416
    /**
417
     * Logs messages using Gravity Forms logging add-on
418
     * @param  string $message log message
419
     * @return void
420
     */
421
    public static function log_error( $message, $data = null ){
422
	    /**
423
	     * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
424
	     * @param string $message Error message to display
425
	     * @param mixed $data Supporting data to print alongside it
426
	     */
427
    	do_action( 'gravityview_log_error', $message, $data );
428
    }
429
430
} // end class GravityView_Plugin
431
432
add_action('plugins_loaded', array('GravityView_Plugin', 'getInstance'), 1);
433