Completed
Push — master ( 267f6d...aac082 )
by Stephanie
03:09
created

FrmAddonsController::shorten_edd_filename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
class FrmAddonsController {
4
5
	public static function menu() {
6
		if ( ! current_user_can( 'activate_plugins' ) ) {
7
			return;
8
		}
9
10
		add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), __( 'Add-Ons', 'formidable' ), 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
11
12
		if ( ! FrmAppHelper::pro_is_installed() ) {
13
			add_submenu_page( 'formidable', 'Formidable | ' . __( 'Upgrade to Pro', 'formidable' ), __( 'Upgrade to Pro', 'formidable' ), 'frm_view_forms', 'formidable-pro-upgrade', 'FrmAddonsController::upgrade_to_pro' );
14
		}
15
	}
16
17
	public static function list_addons() {
18
		$installed_addons = apply_filters( 'frm_installed_addons', array() );
19
20
		$addons = self::get_api_addons();
21
		$errors = self::get_error_from_response( $addons );
22
		if ( isset( $addons['error'] ) ) {
23
			unset( $addons['error'] );
24
		}
25
		self::prepare_addons( $addons );
26
27
		$pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
28
29
		include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
30
	}
31
32
	public static function license_settings() {
33
		$plugins = apply_filters( 'frm_installed_addons', array() );
34
		if ( empty( $plugins ) ) {
35
			esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
36
			return;
37
		}
38
39
		ksort( $plugins );
40
41
		include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
42
	}
43
44
	private static function get_api_addons() {
45
		$license = '';
46
		$edd_update = self::get_pro_updater();
47
		if ( ! empty( $edd_update ) ) {
48
			$license = $edd_update->license;
49
		}
50
51
		$addons = self::get_addon_info( $license );
52
53
		if ( empty( $addons ) ) {
54
			$addons = self::fallback_plugin_list();
55
		} else {
56
			foreach ( $addons as $k => $addon ) {
57
				if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
58
					unset( $addons[ $k ] );
59
				}
60
			}
61
		}
62
63
		return $addons;
64
	}
65
66
	/**
67
	 * @since 3.04.03
68
	 */
69
	public static function get_pro_updater() {
70
		if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) ) {
71
			return FrmProAppHelper::get_updater();
72
		}
73
74
		return false;
75
	}
76
77
	/**
78
	 * If the API is unable to connect, show something on the addons page
79
	 *
80
	 * @since 3.04.03
81
	 * @return array
82
	 */
83
	private static function fallback_plugin_list() {
84
		return array(
85
			'formidable-pro' => array(
86
				'title'   => 'Formidable Pro',
87
				'link'    => 'pricing/',
88
				'docs'    => '',
89
				'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
90
			),
91
			'mailchimp' => array(
92
				'title'   => 'MailChimp Forms',
93
				'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a MailChimp mailing list when they submit forms and update their information along with the entry.',
94
			),
95
			'registration' => array(
96
				'title'   => 'User Registration Forms',
97
				'link'    => 'downloads/user-registration/',
98
				'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.',
99
			),
100
			'paypal' => array(
101
				'title'   => 'PayPal Standard Forms',
102
				'link'    => 'downloads/paypal-standard/',
103
				'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.',
104
			),
105
			'stripe' => array(
106
				'title'   => 'Stripe Forms',
107
				'docs'    => 'knowledgebase/stripe/',
108
				'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
109
			),
110
			'authorize-net' => array(
111
				'title'   => 'Authorize.net AIM Forms',
112
				'link'    => 'downloads/authorize-net-aim/',
113
				'docs'    => 'knowledgebase/authorize-net-aim/',
114
				'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
115
			),
116
			'woocommerce' => array(
117
				'title'   => 'WooCommerce Forms',
118
				'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
119
			),
120
			'autoresponder' => array(
121
				'title'   => 'Form Action Automation',
122
				'docs'    => 'knowledgebase/schedule-autoresponder/',
123
				'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
124
			),
125
			'modal' => array(
126
				'title'   => 'Bootstrap Modal Forms',
127
				'link'    => 'downloads/bootstrap-modal/',
128
				'docs'    => 'knowledgebase/bootstrap-modal/',
129
				'excerpt' => 'Open a view or form in a Bootstrap popup.',
130
			),
131
			'bootstrap' => array(
132
				'title'   => 'Bootstrap Style Forms',
133
				'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
134
			),
135
			'zapier' => array(
136
				'title'   => 'Zapier Forms',
137
				'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.',
138
			),
139
			'signature' => array(
140
				'title'   => 'Digital Signature Forms',
141
				'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
142
			),
143
			'api' => array(
144
				'title'   => 'Formidable Forms API',
145
				'link'    => 'downloads/formidable-api/',
146
				'excerpt' => 'Send entry results to any other site that has a Rest API. This includes the option of sending entries from one Formidable site to another.',
147
			),
148
			'twilio' => array(
149
				'title'   => 'Twilio SMS Forms',
150
				'docs'    => 'knowledgebase/twilio-add-on/',
151
				'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
152
			),
153
		);
154
	}
155
156
	/**
157
	 * If Pro is missing but has been authenticated, include a download URL
158
	 *
159
	 * @since 3.04.03
160
	 * @return string
161
	 */
162
	public static function get_pro_download_url() {
163
		$pro_cred_store  = 'frmpro-credentials';
164
		$pro_wpmu_store  = 'frmpro-wpmu-sitewide';
165
		if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
166
			$creds = get_site_option( $pro_cred_store );
167
		} else {
168
			$creds = get_option( $pro_cred_store );
169
		}
170
171
		if ( empty( $creds ) || ! is_array( $creds ) || ! isset( $creds['license'] ) ) {
172
			return '';
173
		}
174
175
		$license = $creds['license'];
176
		if ( empty( $license ) ) {
177
			return '';
178
		}
179
180
		if ( strpos( $license, '-' ) ) {
181
			// this is a fix for licenses saved in the past
182
			$license = strtoupper( $license );
183
		}
184
185
		$downloads = self::get_addon_info( $license );
186
		$pro = isset( $downloads['93790'] ) ? $downloads['93790'] : array();
187
188
		return isset( $pro['url'] ) ? $pro['url'] : '';
189
	}
190
191
	/**
192
	 * @since 3.04.03
193
	 * @return array
194
	 */
195
	public static function get_addon_info( $license = '' ) {
196
		$addons = array();
0 ignored issues
show
Unused Code introduced by
$addons is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
197
		$url = 'https://formidableforms.com/wp-json/s11edd/v1/updates/';
198
		if ( ! empty( $license ) ) {
199
			$url .= '?l=' . urlencode( base64_encode( $license ) );
200
		}
201
202
		$addons = self::get_cached_addons( $license );
203
		if ( ! empty( $addons ) ) {
204
			return $addons;
205
		}
206
207
		$response = wp_remote_get( $url );
208
		if ( is_array( $response ) && ! is_wp_error( $response ) ) {
209
		    $addons = $response['body'];
210
			if ( ! empty( $addons ) ) {
211
				$addons = json_decode( $addons, true );
212
213
				$skip_categories = array( 'WordPress Form Templates', 'WordPress Form Style Templates' );
214
				foreach ( $addons as $k => $addon ) {
215
					if ( ! isset( $addon['categories'] ) ) {
216
						continue;
217
					}
218
					$cats = array_intersect( $skip_categories, $addon['categories'] );
219
					if ( ! empty( $cats ) ) {
220
						unset( $addons[ $k ] );
221
					}
222
				}
223
224
				self::set_cached_addons( $addons, $license );
225
			}
226
		}
227
228
		return $addons;
229
	}
230
231
	/**
232
	 * @since 3.04.03
233
	 * @return array
234
	 */
235
	private static function get_cached_addons( $license = '' ) {
236
		$cache_key = self::get_cache_key( $license );
237
		$cache     = get_option( $cache_key );
238
239 View Code Duplication
		if ( empty( $cache ) || empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
240
			return false; // Cache is expired
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by FrmAddonsController::get_cached_addons of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
241
		}
242
243
		return json_decode( $cache['value'], true );
244
	}
245
246
	/**
247
	 * @since 3.04.03
248
	 */
249 View Code Duplication
	private static function set_cached_addons( $addons, $license = '' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
		$cache_key = self::get_cache_key( $license );
251
		$data = array(
252
			'timeout' => strtotime( '+6 hours', current_time( 'timestamp' ) ),
253
			'value'   => json_encode( $addons ),
254
		);
255
256
		update_option( $cache_key, $data, 'no' );
257
	}
258
259
	/**
260
	 * @since 3.04.03
261
	 */
262
	public static function reset_cached_addons( $license = '' ) {
263
		delete_option( self::get_cache_key( $license ) );
264
	}
265
266
	/**
267
	 * @since 3.04.03
268
	 * @return string
269
	 */
270
	public static function get_cache_key( $license ) {
271
		return 'frm_addons_l' . ( empty( $license ) ? '' : md5( $license ) );
272
	}
273
274
	/**
275
	 * @since 3.04.03
276
	 * @return array
277
	 */
278
	public static function error_for_license( $license ) {
279
		$errors = array();
280
		if ( ! empty( $license ) ) {
281
			$addons = self::get_addon_info( $license );
282
			$errors = self::get_error_from_response( $addons );
283
		}
284
		return $errors;
285
	}
286
287
	/**
288
	 * @since 3.04.03
289
	 * @return array
290
	 */
291
	private static function get_error_from_response( $addons ) {
292
		$errors = array();
293
		if ( isset( $addons['error'] ) ) {
294
			$errors[] = $addons['error']['message'];
295
			do_action( 'frm_license_error', $addons['error'] );
296
		}
297
		return $errors;
298
	}
299
300
	/**
301
	 * @since 3.04.03
302
	 */
303
	public static function check_update( $transient ) {
304
		if ( ! is_object( $transient ) ) {
305
			$transient = new stdClass();
306
		}
307
308
		$installed_addons = apply_filters( 'frm_installed_addons', array() );
309
		if ( empty( $installed_addons ) ) {
310
			return $transient;
311
		}
312
313
		$version_info = self::fill_update_addon_info( $installed_addons );
314
315
		$transient->last_checked = time();
316
317
		$wp_plugins = get_plugins();
318
319
		foreach ( $version_info as $id => $plugin ) {
320
			$plugin = (object) $plugin;
321
322
			if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
323
				continue;
324
			}
325
326
			$folder = $plugin->plugin;
327
			if ( empty( $folder ) ) {
328
				continue;
329
			}
330
331
			if ( ! self::is_installed( $folder ) ) {
332
				// don't show an update if the plugin isn't installed
333
				continue;
334
			}
335
336
			$wp_plugin  = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
337
			$wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
338
339
			if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
340
				$slug = explode( '/', $folder );
341
				$plugin->slug = $slug[0];
342
				$transient->response[ $folder ] = $plugin;
343
			}
344
345
			$transient->checked[ $folder ] = $wp_version;
346
347
		}
348
349
		return $transient;
350
	}
351
352
	/**
353
	 * Check if a plugin is installed before showing an update for it
354
	 *
355
	 * @since 3.05
356
	 * @param string $plugin - the folder/filename.php for a plugin
357
	 * @return bool - True if installed
358
	 */
359
	private static function is_installed( $plugin ) {
360
		if ( ! function_exists( 'get_plugins' ) ) {
361
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
362
		}
363
364
		$all_plugins = get_plugins();
365
		return isset( $all_plugins[ $plugin ] );
366
	}
367
368
	/**
369
	 * @since 3.04.03
370
	 *
371
	 * @param array $installed_addons
372
	 *
373
	 * @return array
374
	 */
375
	private static function fill_update_addon_info( $installed_addons ) {
376
		$checked_licenses = array();
377
		$version_info     = array();
378
379
		foreach ( $installed_addons as $addon ) {
380
			if ( $addon->store_url !== 'https://formidableforms.com' ) {
381
				// check if this is a third-party addon
382
				continue;
383
			}
384
385
			$new_license = $addon->license;
386
			if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
387
				continue;
388
			}
389
390
			$checked_licenses[] = $new_license;
391
392
			if ( empty( $version_info ) ) {
393
				$version_info = self::get_addon_info( $new_license );
394
				continue;
395
			}
396
397
			$plugin = self::get_addon_for_license( $version_info, $addon );
398
			if ( empty( $plugin ) ) {
399
				continue;
400
			}
401
402
			$download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0;
403
			if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) {
404
				// if this addon is using its own license, get the update url
405
				$addon_info = self::get_addon_info( $new_license );
406
407
				$version_info[ $download_id ] = $addon_info[ $download_id ];
408
				if ( isset( $addon_info['error'] ) ) {
409
					$version_info[ $download_id ]['error'] = array(
410
						'message' => $addon_info['error']['message'],
411
						'code'    => $addon_info['error']['code'],
412
					);
413
				}
414
			}
415
		}
416
417
		return $version_info;
418
	}
419
420
	/**
421
	 * @since 3.04.03
422
	 * @param array $addons
423
	 * @param object $license The FrmAddon object
424
	 * @return array
425
	 */
426
	public static function get_addon_for_license( $addons, $license ) {
427
		$download_id = $license->download_id;
428
		$plugin = array();
429
		if ( empty( $download_id ) && ! empty( $addons ) ) {
430
			foreach ( $addons as $addon ) {
431
				if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
432
					return $addon;
433
				}
434
			}
435
		} elseif ( isset( $addons[ $download_id ] ) ) {
436
			$plugin = $addons[ $download_id ];
437
		}
438
439
		return $plugin;
440
	}
441
442
	private static function prepare_addons( &$addons ) {
443
		$activate_url = '';
444
		if ( current_user_can( 'activate_plugins' ) ) {
445
			$activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
446
		}
447
448
		$loop_addons = $addons;
449
		foreach ( $loop_addons as $id => $addon ) {
450
			if ( is_numeric( $id ) ) {
451
				$slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
452
				$file_name = $addon['plugin'];
453
			} else {
454
				$slug = $id;
455
				if ( isset( $addon['file'] ) ) {
456
					$base_file = $addon['file'];
457
				} else {
458
					$base_file = 'formidable-' . $slug;
459
				}
460
				$file_name = $base_file . '/' . $base_file . '.php';
461
			}
462
463
			$addon['installed']    = self::is_installed( $file_name );
464
			$addon['activate_url'] = '';
465
466
			if ( $addon['installed'] && ! empty( $activate_url ) && ! is_plugin_active( $file_name ) ) {
467
				$addon['activate_url'] = add_query_arg(
468
					array(
469
						'_wpnonce'    => wp_create_nonce( 'activate-plugin_' . $file_name ),
470
						'plugin'      => $file_name,
471
					),
472
					$activate_url
473
				);
474
			}
475
476
			if ( ! isset( $addon['docs'] ) ) {
477
				$addon['docs'] = 'knowledgebase/formidable-' . $slug . '/';
478
			}
479
			self::prepare_addon_link( $addon['docs'] );
480
481
			if ( ! isset( $addon['link'] ) ) {
482
				$addon['link'] = 'downloads/' . $slug . '/';
483
			}
484
			self::prepare_addon_link( $addon['link'] );
485
486
			self::set_addon_status( $addon );
487
			$addons[ $id ] = $addon;
488
		}
489
	}
490
491
	/**
492
	 * @since 3.04.02
493
	 */
494
	private static function prepare_addon_link( &$link ) {
495
		$site_url = 'https://formidableforms.com/';
496
		if ( strpos( $link, 'http' ) !== 0 ) {
497
			$link = $site_url . $link;
498
		}
499
		$link = FrmAppHelper::make_affiliate_url( $link );
500
		$query_args = array(
501
			'utm_source'   => 'WordPress',
502
			'utm_medium'   => 'addons',
503
			'utm_campaign' => 'liteplugin',
504
		);
505
		$link = add_query_arg( $query_args, $link );
506
	}
507
508
	/**
509
	 * Add the status to the addon array. Status options are:
510
	 * installed, active, not installed
511
	 *
512
	 * @since 3.04.02
513
	 */
514
	private static function set_addon_status( &$addon ) {
515
		if ( ! empty( $addon['activate_url'] ) ) {
516
			$addon['status'] = array(
517
				'type'  => 'installed',
518
				'label' => __( 'Installed', 'formidable' ),
519
			);
520
		} elseif ( $addon['installed'] ) {
521
			$addon['status'] = array(
522
				'type'  => 'active',
523
				'label' => __( 'Active', 'formidable' ),
524
			);
525
		} else {
526
			$addon['status'] = array(
527
				'type'  => 'not-installed',
528
				'label' => __( 'Not Installed', 'formidable' ),
529
			);
530
		}
531
	}
532
533
	public static function upgrade_to_pro() {
534
		$pro_pricing = self::prepare_pro_info();
535
536
		include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' );
537
	}
538
539
	private static function prepare_pro_info() {
540
		return array(
541
			'personal'     => array(
542
				'id'       => 2,
543
				'download' => 19367654,
544
				'price'    => '49.00',
545
				'name'     => 'Personal',
546
			),
547
			'professional' => array(
548
				'id'       => 0,
549
				'download' => 19367001,
550
				'price'    => '99.00',
551
				'name'     => 'Creator',
552
			),
553
			'smallbusiness' => array(
554
				'id'       => 0,
555
				'download' => 19366995,
556
				'price'    => '199.00',
557
				'name'     => 'Business',
558
			),
559
			'enterprise'   => array(
560
				'id'       => 0,
561
				'download' => 19366992,
562
				'price'    => '399.00',
563
				'name'     => 'Enterprise',
564
			),
565
		);
566
	}
567
568
	/**
569
	 * @since 3.04.02
570
	 */
571
	public static function ajax_install_addon() {
572
573
		self::install_addon_permissions();
574
575
		// Set the current screen to avoid undefined notices.
576
		global $hook_suffix;
577
		set_current_screen();
578
579
		self::maybe_show_cred_form();
580
581
		$installed = self::install_addon();
582
		self::maybe_activate_addon( $installed );
583
584
		// Send back a response.
585
		echo json_encode( true );
586
		wp_die();
587
	}
588
589
	/**
590
	 * @since 3.04.02
591
	 */
592
	private static function maybe_show_cred_form() {
593
		// Start output bufferring to catch the filesystem form if credentials are needed.
594
		ob_start();
595
596
		$show_form = false;
597
		$method = '';
598
		$url    = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) );
599
		$url    = esc_url_raw( $url );
600
		$creds  = request_filesystem_credentials( $url, $method, false, false, null );
601
602
		if ( false === $creds ) {
603
			$show_form = true;
604
		} elseif ( ! WP_Filesystem( $creds ) ) {
605
			request_filesystem_credentials( $url, $method, true, false, null );
606
			$show_form = true;
607
		}
608
609
		if ( $show_form ) {
610
			$form = ob_get_clean();
0 ignored issues
show
Unused Code introduced by
$form is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
611
			//TODO: test this: echo json_encode( array( 'form' => $form ) );
612
			echo json_encode( array( 'form' => __( 'Sorry, you\'re site requires FTP authentication. Please install plugins manaully.', 'formidable' ) ) );
613
			wp_die();
614
		}
615
616
		ob_end_clean();
617
	}
618
619
	/**
620
	 * We do not need any extra credentials if we have gotten this far,
621
	 * so let's install the plugin.
622
	 *
623
	 * @since 3.04.02
624
	 */
625
	private static function install_addon() {
626
		require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
627
628
		$download_url = esc_url_raw( $_POST['plugin'] );
629
630
		// Create the plugin upgrader with our custom skin.
631
		$installer = new Plugin_Upgrader( new FrmInstallerSkin() );
632
		$installer->install( $download_url );
633
634
		// Flush the cache and return the newly installed plugin basename.
635
		wp_cache_flush();
636
		return $installer->plugin_info();
637
	}
638
639
	/**
640
	 * @since 3.04.02
641
	 */
642
	private static function maybe_activate_addon( $installed ) {
643
		if ( ! $installed ) {
644
			return;
645
		}
646
647
		$activate = activate_plugin( $installed );
648
		if ( is_wp_error( $activate ) ) {
649
			echo json_encode( array( 'error' => $activate->get_error_message() ) );
650
			wp_die();
651
		}
652
	}
653
654
	/**
655
	 * Run security checks before installing
656
	 *
657
	 * @since 3.04.02
658
	 */
659
	private static function install_addon_permissions() {
660
		check_ajax_referer( 'frm_ajax', 'nonce' );
661
662
		if ( ! current_user_can( 'activate_plugins' ) || ! isset( $_POST['plugin'] ) ) {
663
			echo json_encode( true );
664
			wp_die();
665
		}
666
	}
667
668
	/**
669
	 * @since 2.03.08
670
	 * @deprecated 3.04.03
671
	 * @codeCoverageIgnore
672
	 *
673
	 * @param boolean $return
674
	 * @param string $package
675
	 *
676
	 * @return boolean
677
	 */
678
	public static function add_shorten_edd_filename_filter( $return, $package ) {
679
		return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::add_shorten_edd_filename_filter() has been deprecated with message: 3.04.03

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
680
	}
681
682
	/**
683
	 * @since 2.03.08
684
	 * @deprecated 3.04.03
685
	 * @codeCoverageIgnore
686
	 *
687
	 * @param string $filename
688
	 * @param string $ext
689
	 *
690
	 * @return string
691
	 */
692
	public static function shorten_edd_filename( $filename, $ext ) {
693
		return FrmDeprecated::shorten_edd_filename( $filename, $ext );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::shorten_edd_filename() has been deprecated with message: 3.04.03

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
694
	}
695
696
	/**
697
	 * @deprecated 3.04.03
698
	 * @codeCoverageIgnore
699
	 */
700
	public static function get_licenses() {
701
		FrmDeprecated::get_licenses();
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::get_licenses() has been deprecated with message: 3.04.03

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
702
	}
703
}
704