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