These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
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 2014, 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.15.2 |
||
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'); |
||
70 | require_once( GRAVITYVIEW_DIR . 'includes/connector-functions.php'); |
||
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'); |
||
77 | |||
78 | /** Add Cache Class */ |
||
79 | require_once( GRAVITYVIEW_DIR . 'includes/class-cache.php'); |
||
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.15.2'; |
||
93 | |||
94 | private static $instance; |
||
95 | |||
96 | /** |
||
97 | * Singleton instance |
||
98 | * |
||
99 | * @return GravityView_Plugin GravityView_Plugin object |
||
100 | */ |
||
101 | public static function getInstance() { |
||
102 | |||
103 | if( empty( self::$instance ) ) { |
||
104 | self::$instance = new self; |
||
105 | } |
||
106 | |||
107 | return self::$instance; |
||
108 | } |
||
109 | |||
110 | private function __construct() { |
||
111 | |||
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 | function add_hooks() { |
||
0 ignored issues
–
show
|
|||
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 | function include_files() { |
||
0 ignored issues
–
show
|
|||
141 | |||
142 | include_once( GRAVITYVIEW_DIR .'includes/class-admin.php' ); |
||
143 | |||
144 | // Load fields |
||
145 | include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' ); |
||
146 | |||
147 | // Load all field files automatically |
||
148 | foreach ( glob( GRAVITYVIEW_DIR . 'includes/fields/*.php' ) as $gv_field_filename ) { |
||
149 | include_once( $gv_field_filename ); |
||
150 | } |
||
151 | |||
152 | include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-notes.php' ); |
||
153 | include_once( GRAVITYVIEW_DIR .'includes/load-plugin-and-theme-hooks.php' ); |
||
154 | |||
155 | // Load Extensions |
||
156 | // @todo: Convert to a scan of the directory or a method where this all lives |
||
157 | include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' ); |
||
158 | include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.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-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 | * @param mixed $network_wide |
||
202 | * @return void |
||
203 | */ |
||
204 | public static function activate( $network_wide = false ) { |
||
0 ignored issues
–
show
|
|||
205 | |||
206 | // register post types |
||
207 | GravityView_Post_Types::init_post_types(); |
||
208 | |||
209 | // register rewrite rules |
||
210 | GravityView_Post_Types::init_rewrite(); |
||
211 | |||
212 | flush_rewrite_rules(); |
||
213 | |||
214 | // Update the current GV version |
||
215 | update_option( 'gv_version', self::version ); |
||
216 | |||
217 | // Add the transient to redirect to configuration page |
||
218 | set_transient( '_gv_activation_redirect', true, 60 ); |
||
219 | |||
220 | // Clear settings transient |
||
221 | delete_transient( 'redux_edd_license_license_valid' ); |
||
222 | |||
223 | GravityView_Roles_Capabilities::get_instance()->add_caps(); |
||
224 | } |
||
225 | |||
226 | |||
227 | /** |
||
228 | * Plugin deactivate function. |
||
229 | * |
||
230 | * @access public |
||
231 | * @static |
||
232 | * @param mixed $network_wide |
||
233 | * @return void |
||
234 | */ |
||
235 | public static function deactivate( $network_wide ) { |
||
0 ignored issues
–
show
|
|||
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, '/languages/' ); |
||
272 | if ( ! $loaded ) { |
||
273 | $loaded = load_muplugin_textdomain( 'gravityview', '/languages/' ); |
||
274 | } |
||
275 | if ( ! $loaded ) { |
||
276 | $loaded = load_theme_textdomain( 'gravityview', '/languages/' ); |
||
277 | } |
||
278 | if ( ! $loaded ) { |
||
279 | $locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' ); |
||
280 | $mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo'; |
||
281 | load_textdomain( 'gravityview', $mofile ); |
||
282 | } |
||
283 | |||
284 | } |
||
285 | |||
286 | /** |
||
287 | * Check if is_admin(), and make sure not DOING_AJAX |
||
288 | * @since 1.7.5 |
||
289 | * @return bool |
||
290 | */ |
||
291 | public static function is_admin() { |
||
292 | |||
293 | $doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false; |
||
294 | |||
295 | return is_admin() && ! $doing_ajax; |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * Function to launch frontend objects |
||
300 | * |
||
301 | * @access public |
||
302 | * @return void |
||
303 | */ |
||
304 | public function frontend_actions() { |
||
305 | |||
306 | if( self::is_admin() ) { return; } |
||
307 | |||
308 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' ); |
||
309 | include_once( GRAVITYVIEW_DIR .'includes/class-template.php' ); |
||
310 | include_once( GRAVITYVIEW_DIR .'includes/class-api.php' ); |
||
311 | include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' ); |
||
312 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' ); |
||
313 | |||
314 | |||
315 | /** |
||
316 | * When an entry is created, check if we need to update the custom slug meta |
||
317 | * todo: move this to its own class.. |
||
318 | */ |
||
319 | add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); |
||
320 | |||
321 | /** |
||
322 | * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded |
||
323 | * |
||
324 | * Nice place to insert extensions' frontend stuff |
||
325 | */ |
||
326 | do_action( 'gravityview_include_frontend_actions' ); |
||
327 | } |
||
328 | |||
329 | /** |
||
330 | * helper function to define the default widget areas |
||
331 | * @todo Move somewhere logical |
||
332 | * @return array definition for default widget areas |
||
333 | */ |
||
334 | public static function get_default_widget_areas() { |
||
335 | $default_areas = array( |
||
336 | array( '1-1' => array( array( 'areaid' => 'top', 'title' => __('Top', 'gravityview' ) , 'subtitle' => '' ) ) ), |
||
337 | array( '1-2' => array( array( 'areaid' => 'left', 'title' => __('Left', 'gravityview') , 'subtitle' => '' ) ), '2-2' => array( array( 'areaid' => 'right', 'title' => __('Right', 'gravityview') , 'subtitle' => '' ) ) ), |
||
338 | //array( '1-1' => array( array( 'areaid' => 'bottom', 'title' => __('Full Width Bottom', 'gravityview') , 'subtitle' => '' ) ) ) |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
339 | ); |
||
340 | |||
341 | /** |
||
342 | * @filter `gravityview_widget_active_areas` Array of zones available for widgets to be dropped into |
||
343 | * @param array $default_areas Definition for default widget areas |
||
344 | */ |
||
345 | return apply_filters( 'gravityview_widget_active_areas', $default_areas ); |
||
346 | } |
||
347 | |||
348 | /** DEBUG */ |
||
349 | |||
350 | /** |
||
351 | * Logs messages using Gravity Forms logging add-on |
||
352 | * @param string $message log message |
||
353 | * @param mixed $data Additional data to display |
||
354 | * @return void |
||
355 | */ |
||
356 | public static function log_debug( $message, $data = null ){ |
||
357 | /** |
||
358 | * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
||
359 | * @param string $message Message to display |
||
360 | * @param mixed $data Supporting data to print alongside it |
||
361 | */ |
||
362 | do_action( 'gravityview_log_debug', $message, $data ); |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * Logs messages using Gravity Forms logging add-on |
||
367 | * @param string $message log message |
||
368 | * @return void |
||
369 | */ |
||
370 | public static function log_error( $message, $data = null ){ |
||
371 | /** |
||
372 | * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
||
373 | * @param string $message Error message to display |
||
374 | * @param mixed $data Supporting data to print alongside it |
||
375 | */ |
||
376 | do_action( 'gravityview_log_error', $message, $data ); |
||
377 | } |
||
378 | |||
379 | } // end class GravityView_Plugin |
||
380 | |||
381 | add_action('plugins_loaded', array('GravityView_Plugin', 'getInstance'), 1); |
||
382 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.