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